Module: SmoothOperator::AttributeAssignment
- Included in:
- OpenStruct::Base
- Defined in:
- lib/smooth_operator/attribute_assignment.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#_meta_data ⇒ Object
readonly
Returns the value of attribute _meta_data.
-
#_options ⇒ Object
readonly
Returns the value of attribute _options.
Class Method Summary collapse
Instance Method Summary collapse
- #assign_attributes(_attributes = {}, options = {}) ⇒ Object
- #get_internal_data(field, method = :value) ⇒ Object
- #has_data_from_server ⇒ Object (also: #from_server)
- #initialize(attributes = {}, options = {}) ⇒ Object
- #internal_data ⇒ Object
- #parent_object ⇒ Object
- #push_to_internal_data(attribute_name, attribute_value) ⇒ Object
Instance Attribute Details
#_meta_data ⇒ Object (readonly)
Returns the value of attribute _meta_data.
58 59 60 |
# File 'lib/smooth_operator/attribute_assignment.rb', line 58 def @_meta_data end |
#_options ⇒ Object (readonly)
Returns the value of attribute _options.
58 59 60 |
# File 'lib/smooth_operator/attribute_assignment.rb', line 58 def @_options end |
Class Method Details
.included(base) ⇒ Object
9 10 11 |
# File 'lib/smooth_operator/attribute_assignment.rb', line 9 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#assign_attributes(_attributes = {}, options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/smooth_operator/attribute_assignment.rb', line 61 def assign_attributes(_attributes = {}, = {}) return nil unless _attributes.is_a?(Hash) attributes = _attributes = Helpers.stringify_keys(_attributes) if _attributes.include?(resource_name) attributes = _attributes.delete(resource_name) @_meta_data = _attributes end .each { |key, value| @_options[key] = value } if .is_a?(Hash) attributes.each { |name, value| push_to_internal_data(name, value) } end |
#get_internal_data(field, method = :value) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/smooth_operator/attribute_assignment.rb', line 90 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 |
#has_data_from_server ⇒ Object Also known as: from_server
80 81 82 |
# File 'lib/smooth_operator/attribute_assignment.rb', line 80 def has_data_from_server [:from_server] == true end |
#initialize(attributes = {}, options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/smooth_operator/attribute_assignment.rb', line 48 def initialize(attributes = {}, = {}) @_options = {} before_initialize(attributes, ) assign_attributes attributes, after_initialize(attributes, ) end |
#internal_data ⇒ Object
86 87 88 |
# File 'lib/smooth_operator/attribute_assignment.rb', line 86 def internal_data @internal_data ||= {} end |
#parent_object ⇒ Object
76 77 78 |
# File 'lib/smooth_operator/attribute_assignment.rb', line 76 def parent_object [:parent_object] end |
#push_to_internal_data(attribute_name, attribute_value) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/smooth_operator/attribute_assignment.rb', line 102 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 if internal_data[attribute_name].nil? initiate_internal_data(attribute_name, attribute_value) else update_internal_data(attribute_name, attribute_value) end end |