Class: Brainstem::DSL::Conditional
- Inherits:
-
Object
- Object
- Brainstem::DSL::Conditional
- Defined in:
- lib/brainstem/dsl/conditional.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(name, type, action, options = {}) ⇒ Conditional
constructor
A new instance of Conditional.
- #matches?(model, helper_instance = Object.new, conditional_cache = { model: {}, request: {} }) ⇒ Boolean
Constructor Details
#initialize(name, type, action, options = {}) ⇒ Conditional
Returns a new instance of Conditional.
6 7 8 9 10 11 |
# File 'lib/brainstem/dsl/conditional.rb', line 6 def initialize(name, type, action, = {}) @name = name @type = type @action = action @options = end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
4 5 6 |
# File 'lib/brainstem/dsl/conditional.rb', line 4 def action @action end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/brainstem/dsl/conditional.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/brainstem/dsl/conditional.rb', line 4 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/brainstem/dsl/conditional.rb', line 4 def type @type end |
Instance Method Details
#description ⇒ Object
13 14 15 |
# File 'lib/brainstem/dsl/conditional.rb', line 13 def description [:info].presence end |
#matches?(model, helper_instance = Object.new, conditional_cache = { model: {}, request: {} }) ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/brainstem/dsl/conditional.rb', line 17 def matches?(model, helper_instance = Object.new, conditional_cache = { model: {}, request: {} }) case type when :model conditional_cache[:model].fetch(name) { conditional_cache[:model][name] = helper_instance.instance_exec(model, &action) } when :request conditional_cache[:request].fetch(name) { conditional_cache[:request][name] = helper_instance.instance_exec(&action) } else raise "Unknown Brainstem Conditional type #{type}" end end |