Class: Composable::Core::ComposableDSL::Composable

Inherits:
Object
  • Object
show all
Defined in:
lib/composable/core/composable_dsl.rb

Defined Under Namespace

Classes: Condition, Conditions, Sync

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributeObject (readonly)

Returns the value of attribute attribute.



99
100
101
# File 'lib/composable/core/composable_dsl.rb', line 99

def attribute
  @attribute
end

#conditionsObject (readonly)

Returns the value of attribute conditions.



99
100
101
# File 'lib/composable/core/composable_dsl.rb', line 99

def conditions
  @conditions
end

#mappingObject (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(**options, &block)
  conditions.merge(**options)

  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

Returns:

  • (Boolean)


124
125
126
# File 'lib/composable/core/composable_dsl.rb', line 124

def valid?(...)
  conditions.valid?(...)
end