Module: SmoothOperator::AttributeMethods

Included in:
OpenStruct::Base
Defined in:
lib/smooth_operator/attribute_methods.rb

Instance Method Summary collapse

Instance Method Details

#get_attribute_type(attribute) ⇒ Object



20
21
22
# File 'lib/smooth_operator/attribute_methods.rb', line 20

def get_attribute_type(attribute)
  self.class.internal_structure[attribute.to_s]
end

#get_internal_data(field, method = :value) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/smooth_operator/attribute_methods.rb', line 8

def get_internal_data(field, method = :value)
  result = internal_data[field]

  if result.nil?
    nil
  elsif method == :value
    result.is_a?(Attributes::Dirty) ? internal_data[field].send(method) : internal_data[field]
  else
    internal_data[field].send(method)
  end
end

#internal_dataObject



4
5
6
# File 'lib/smooth_operator/attribute_methods.rb', line 4

def internal_data
  @internal_data ||= {}
end

#push_to_internal_data(attribute_name, attribute_value) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/smooth_operator/attribute_methods.rb', line 24

def push_to_internal_data(attribute_name, attribute_value)
  attribute_name = attribute_name.to_s

  return nil unless allowed_attribute(attribute_name)

  known_attributes.add attribute_name

  attribute_name, attribute_value = extract_nested_attributes(attribute_name, attribute_value)

  initiate_or_update_internal_data(attribute_name, attribute_value)

  new_record_or_mark_for_destruction?(attribute_name, attribute_value)
end