Class: RapidTransit::Action::Base
- Inherits:
-
Object
- Object
- RapidTransit::Action::Base
- Defined in:
- lib/rapid_transit/action/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#action_name ⇒ Object
Returns the value of attribute action_name.
-
#block ⇒ Object
Returns the value of attribute block.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#key ⇒ Object
Returns the value of attribute key.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #apply?(row) ⇒ Boolean
-
#initialize(action_name, *args, &block) ⇒ Base
constructor
A new instance of Base.
- #result(row) ⇒ Object
- #result_saved? ⇒ Boolean
- #valid?(actions) ⇒ Boolean
Constructor Details
#initialize(action_name, *args, &block) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 11 12 13 |
# File 'lib/rapid_transit/action/base.rb', line 5 def initialize(action_name, *args, &block) @action_name = action_name = args. @condition = .delete(:if) @options = @key = args.first @block = block @validations = :action_name, :key end |
Instance Attribute Details
#action_name ⇒ Object
Returns the value of attribute action_name.
3 4 5 |
# File 'lib/rapid_transit/action/base.rb', line 3 def action_name @action_name end |
#block ⇒ Object
Returns the value of attribute block.
3 4 5 |
# File 'lib/rapid_transit/action/base.rb', line 3 def block @block end |
#condition ⇒ Object
Returns the value of attribute condition.
3 4 5 |
# File 'lib/rapid_transit/action/base.rb', line 3 def condition @condition end |
#key ⇒ Object
Returns the value of attribute key.
3 4 5 |
# File 'lib/rapid_transit/action/base.rb', line 3 def key @key end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/rapid_transit/action/base.rb', line 3 def @options end |
Instance Method Details
#apply?(row) ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rapid_transit/action/base.rb', line 28 def apply?(row) if condition.is_a? Hash result = condition.all? { |k, v| row[k] == v } result elsif condition.is_a? Proc condition.call(row) else true end end |
#result(row) ⇒ Object
15 16 17 |
# File 'lib/rapid_transit/action/base.rb', line 15 def result(row) receivers(row).zip(methods, params(row)).map { |r, m, p| r.send m, *p }.last end |
#result_saved? ⇒ Boolean
23 24 25 26 |
# File 'lib/rapid_transit/action/base.rb', line 23 def result_saved? # Override in your subclass if the action returns a saved active record false end |
#valid?(actions) ⇒ Boolean
19 20 21 |
# File 'lib/rapid_transit/action/base.rb', line 19 def valid?(actions) @validations.each { |v| send "validate_#{v}", actions } end |