Class: Composable::Core::ComposableDSL::Composable
- Inherits:
-
Object
- Object
- Composable::Core::ComposableDSL::Composable
- Defined in:
- lib/composable/core/composable_dsl.rb
Defined Under Namespace
Classes: Condition, Conditions, Sync
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#mapping ⇒ Object
readonly
Returns the value of attribute mapping.
Instance Method Summary collapse
- #evaluate(**options, &block) ⇒ Object
-
#initialize(attribute) ⇒ Composable
constructor
A new instance of Composable.
- #initialize_copy(original_object) ⇒ Object
- #sync_attributes(form, record, reverse: false) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(attribute) ⇒ Composable
Returns a new instance of Composable.
101 102 103 104 105 |
# File 'lib/composable/core/composable_dsl.rb', line 101 def initialize(attribute) @attribute = attribute @mapping = {} @conditions = Conditions.new end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
99 100 101 |
# File 'lib/composable/core/composable_dsl.rb', line 99 def attribute @attribute end |
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
99 100 101 |
# File 'lib/composable/core/composable_dsl.rb', line 99 def conditions @conditions end |
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
99 100 101 |
# File 'lib/composable/core/composable_dsl.rb', line 99 def mapping @mapping end |
Instance Method Details
#evaluate(**options, &block) ⇒ Object
112 113 114 115 116 |
# File 'lib/composable/core/composable_dsl.rb', line 112 def evaluate(**, &block) conditions.merge(**) instance_eval(&block) if block end |
#initialize_copy(original_object) ⇒ Object
107 108 109 110 |
# File 'lib/composable/core/composable_dsl.rb', line 107 def initialize_copy(original_object) @mapping = original_object.mapping.deep_dup @conditions = original_object.conditions.deep_dup end |
#sync_attributes(form, record, reverse: false) ⇒ Object
118 119 120 121 122 |
# File 'lib/composable/core/composable_dsl.rb', line 118 def sync_attributes(form, record, reverse: false) mapping.each_value do |instance| instance.sync(form, record, reverse: reverse) end end |
#valid? ⇒ Boolean
124 125 126 |
# File 'lib/composable/core/composable_dsl.rb', line 124 def valid?(...) conditions.valid?(...) end |