Module: Fleakr::Support::Object::InstanceMethods

Defined in:
lib/fleakr/support/object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authentication_optionsObject (readonly)

Returns the value of attribute authentication_options.



98
99
100
# File 'lib/fleakr/support/object.rb', line 98

def authentication_options
  @authentication_options
end

#documentObject (readonly)

Returns the value of attribute document.



98
99
100
# File 'lib/fleakr/support/object.rb', line 98

def document
  @document
end

Instance Method Details

#associationsObject



120
121
122
# File 'lib/fleakr/support/object.rb', line 120

def associations
  @associations ||= {}
end

#initialize(document = nil, options = {}) ⇒ Object



100
101
102
103
# File 'lib/fleakr/support/object.rb', line 100

def initialize(document = nil, options = {})
  self.populate_from(document) unless document.nil?
  @authentication_options = options.extract!(:auth_token)
end

#inspectObject



113
114
115
116
117
118
# File 'lib/fleakr/support/object.rb', line 113

def inspect
  names      = instance_variables.reject {|n| %w(@associations @document).include?(n.to_s) }
  attributes = names.map {|n| "#{n}=#{instance_variable_get(n).inspect}" }

  "#<#{self.class} #{attributes.join(', ')}>"
end

#populate_from(document) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/fleakr/support/object.rb', line 105

def populate_from(document)
  @document = document
  self.class.attributes.each do |attribute|
    value = attribute.value_from(document)
    self.send("#{attribute.name}=".to_sym, value) unless value.nil?
  end
end