Class: UseCase::PreConditionFailure
- Inherits:
-
Object
- Object
- UseCase::PreConditionFailure
- Defined in:
- lib/use_case/outcome.rb
Instance Attribute Summary collapse
-
#pre_condition ⇒ Object
readonly
Returns the value of attribute pre_condition.
Instance Method Summary collapse
-
#initialize(pre_condition) ⇒ PreConditionFailure
constructor
A new instance of PreConditionFailure.
- #otherwise {|@pre_condition| ... } ⇒ Object
- #symbol ⇒ Object
- #when(symbol, &block) ⇒ Object
Constructor Details
#initialize(pre_condition) ⇒ PreConditionFailure
Returns a new instance of PreConditionFailure.
75 |
# File 'lib/use_case/outcome.rb', line 75 def initialize(pre_condition); @pre_condition = pre_condition; end |
Instance Attribute Details
#pre_condition ⇒ Object (readonly)
Returns the value of attribute pre_condition.
74 75 76 |
# File 'lib/use_case/outcome.rb', line 74 def pre_condition @pre_condition end |
Instance Method Details
#otherwise {|@pre_condition| ... } ⇒ Object
85 86 87 88 |
# File 'lib/use_case/outcome.rb', line 85 def otherwise(&block) @otherwise = true yield(@pre_condition) if !@called end |
#symbol ⇒ Object
90 91 92 93 94 95 |
# File 'lib/use_case/outcome.rb', line 90 def symbol return @pre_condition.symbol if @pre_condition.respond_to?(:symbol) klass = @pre_condition.class return klass.symbol if klass.respond_to?(:symbol) klass.name.gsub(/([^A-Z])([A-Z])/, '\1_\2').gsub(/[:_]+/, "_").downcase.to_sym end |
#when(symbol, &block) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/use_case/outcome.rb', line 77 def when(symbol, &block) raise Exception.new("Cannot call when after otherwise") if @otherwise if symbol == self.symbol @called = true yield(@pre_condition) end end |