Class: Results::Bad

Inherits:
Struct
  • Object
show all
Defined in:
lib/results.rb

Defined Under Namespace

Classes: And

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Bad

Returns a new instance of Bad.



149
150
151
152
# File 'lib/results.rb', line 149

def initialize(*args)
  flat_args = args.flatten
  super( flat_args.all? { |a| a.is_a? Because } ? flat_args : [Because.new(*flat_args)] )
end

Instance Attribute Details

#whyObject

Returns the value of attribute why

Returns:

  • (Object)

    the current value of why



148
149
150
# File 'lib/results.rb', line 148

def why
  @why
end

Instance Method Details

#andObject



172
173
174
# File 'lib/results.rb', line 172

def and
  And.new(self)
end

#flat_mapObject Also known as: validate



158
159
160
# File 'lib/results.rb', line 158

def flat_map
  self
end

#mapObject



154
155
156
# File 'lib/results.rb', line 154

def map
  self
end

#validate_all(*validations) ⇒ Object



212
213
214
# File 'lib/results.rb', line 212

def validate_all(*validations)
  validations.flatten.inject(self) { |prev_result, validation| prev_result.and.validate(&validation) }
end

#when(msg_or_proc) ⇒ Object



164
165
166
# File 'lib/results.rb', line 164

def when(msg_or_proc)
  self
end

#when_all(*filters) ⇒ Object



204
205
206
# File 'lib/results.rb', line 204

def when_all(*filters)
  filters.flatten.inject(self) { |prev_result, filter| prev_result.and.when(filter) }
end

#when_all_not(*filters) ⇒ Object



208
209
210
# File 'lib/results.rb', line 208

def when_all_not(*filters)
  filters.flatten.inject(self) { |prev_result, filter| prev_result.and.when_not(filter) }
end

#when_not(msg_or_proc) ⇒ Object



168
169
170
# File 'lib/results.rb', line 168

def when_not(msg_or_proc)
  self
end

#zip(other) ⇒ Object



216
217
218
219
220
221
# File 'lib/results.rb', line 216

def zip(other)
  case other
  when Good then self
  when Bad  then Bad.new(why + other.why)
  end
end