Class: Steep::Subtyping::Result::All

Inherits:
Base show all
Defined in:
lib/steep/subtyping/result.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#relation

Instance Method Summary collapse

Methods inherited from Base

#else, #then

Constructor Details

#initialize(relation) ⇒ All

Returns a new instance of All.



77
78
79
80
81
# File 'lib/steep/subtyping/result.rb', line 77

def initialize(relation)
  super relation
  @branches = []
  @failure = false
end

Instance Attribute Details

#branchesObject (readonly)

Returns the value of attribute branches.



75
76
77
# File 'lib/steep/subtyping/result.rb', line 75

def branches
  @branches
end

Instance Method Details

#add(*relations, &block) ⇒ Object

Returns ‘false` if no future `#add` changes the result.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/steep/subtyping/result.rb', line 84

def add(*relations, &block)
  relations.each do |relation|
    if success?
      result = yield(relation)
      if result
        branches << result
      end
    else
      # Already failed.
      branches << Skip.new(relation)
    end
  end

  # No need to test more branches if already failed.
  success?
end

#add_result(result) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/steep/subtyping/result.rb', line 101

def add_result(result)
  if result
    add(result.relation) { result }
  else
    success?
  end
end

#failure?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/steep/subtyping/result.rb', line 113

def failure?
  @failure ||= branches.any?(&:failure?)
end

#failure_path(path = []) ⇒ Object



117
118
119
120
121
122
123
# File 'lib/steep/subtyping/result.rb', line 117

def failure_path(path = [])
  if failure?
    r = branches.find(&:failure?) or raise
    path.unshift(self)
    r.failure_path(path)
  end
end

#success?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/steep/subtyping/result.rb', line 109

def success?
  !failure?
end