Module: SmoothOperator::AttributeAssignment

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

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_meta_dataObject (readonly)

Returns the value of attribute _meta_data.



56
57
58
# File 'lib/smooth_operator/attribute_assignment.rb', line 56

def 
  @_meta_data
end

#_optionsObject (readonly)

Returns the value of attribute _options.



56
57
58
# File 'lib/smooth_operator/attribute_assignment.rb', line 56

def _options
  @_options
end

Class Method Details

.included(base) ⇒ Object



8
9
10
# File 'lib/smooth_operator/attribute_assignment.rb', line 8

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#assign_attributes(_attributes = {}, options = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/smooth_operator/attribute_assignment.rb', line 59

def assign_attributes(_attributes = {}, options = {})
  return nil unless _attributes.is_a?(Hash)

  attributes = _attributes = Helpers.stringify_keys(_attributes)

  if _attributes.include?(self.class.resource_name)
    attributes = _attributes.delete(self.class.resource_name)
    @_meta_data = _attributes
  end

  options.each { |key, value| @_options[key] = value } if options.is_a?(Hash)

  attributes.each { |name, value| push_to_internal_data(name, value) }
end

#has_data_from_serverObject Also known as: from_server



78
79
80
# File 'lib/smooth_operator/attribute_assignment.rb', line 78

def has_data_from_server
  _options[:from_server] == true
end

#initialize(attributes = {}, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/smooth_operator/attribute_assignment.rb', line 46

def initialize(attributes = {}, options = {})
  @_options = {}

  before_initialize(attributes, options)

  assign_attributes attributes, options

  after_initialize(attributes, options)
end

#parent_objectObject



74
75
76
# File 'lib/smooth_operator/attribute_assignment.rb', line 74

def parent_object
  _options[:parent_object]
end