Module: Axel::CascadableAttribute

Included in:
ServiceResource::Base
Defined in:
lib/axel/cascadable_attribute.rb

Instance Method Summary collapse

Instance Method Details

#_cascadable_attributesObject



14
15
16
# File 'lib/axel/cascadable_attribute.rb', line 14

def _cascadable_attributes
  @_cascadable_attributes ||= ["_cascadable_attributes"]
end

#_cascadable_attributes=(arry) ⇒ Object



18
19
20
# File 'lib/axel/cascadable_attribute.rb', line 18

def _cascadable_attributes=(arry)
  @_cascadable_attributes = arry
end

#_instance_var_for(attribute_name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/axel/cascadable_attribute.rb', line 22

def _instance_var_for(attribute_name)
  attribute = instance_variable_get(attribute_name)
  attribute.clone
rescue
  begin
    attribute.dup
  rescue
    attribute
  end
end

#cascade_attribute(*attribute_names) ⇒ Object



10
11
12
# File 'lib/axel/cascadable_attribute.rb', line 10

def cascade_attribute(*attribute_names)
  self._cascadable_attributes += attribute_names.map(&:to_s)
end

#inherited(klass) ⇒ Object



3
4
5
6
7
8
# File 'lib/axel/cascadable_attribute.rb', line 3

def inherited(klass)
  super
  _cascadable_attributes.each do |attribute_name|
    klass.instance_variable_set "@#{attribute_name}", _instance_var_for("@#{attribute_name}")
  end
end