Class: Sirportly::DataObject

Inherits:
Object
  • Object
show all
Defined in:
lib/sirportly/data_object.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, attributes = {}) ⇒ DataObject

Returns a new instance of DataObject.



26
27
28
29
# File 'lib/sirportly/data_object.rb', line 26

def initialize(client, attributes = {})
  @client = client
  set_attributes(attributes)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/sirportly/data_object.rb', line 35

def method_missing(name)
  if attributes.keys.include?(name.to_s)
    attributes[name.to_s]
  else
    super
  end
end

Class Attribute Details

.collection_pathObject

Returns the value of attribute collection_path.



5
6
7
# File 'lib/sirportly/data_object.rb', line 5

def collection_path
  @collection_path
end

.mapsObject

Returns the value of attribute maps.



7
8
9
# File 'lib/sirportly/data_object.rb', line 7

def maps
  @maps
end

.memberObject

Returns the value of attribute member.



6
7
8
# File 'lib/sirportly/data_object.rb', line 6

def member
  @member
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



23
24
25
# File 'lib/sirportly/data_object.rb', line 23

def attributes
  @attributes
end

#clientObject (readonly)

Returns the value of attribute client.



24
25
26
# File 'lib/sirportly/data_object.rb', line 24

def client
  @client
end

Class Method Details

.all(client, options = {}) ⇒ Object

Raises:



9
10
11
12
13
# File 'lib/sirportly/data_object.rb', line 9

def all(client, options = {})
  raise Sirportly::Error, "This object does not support a full list" if collection_path.nil?
  result = client.request(collection_path, options)
  DataSet.new(client, result, self)
end

.find(client, query) ⇒ Object

Raises:



15
16
17
18
19
# File 'lib/sirportly/data_object.rb', line 15

def find(client, query)
  raise Sirportly::Error, "This object does not support finding objects" unless member.is_a?(Hash)
  result = client.request(member[:path], {member[:param] => query})
  self.new(client, result)
end

Instance Method Details

#inspectObject



31
32
33
# File 'lib/sirportly/data_object.rb', line 31

def inspect
  "#<#{self.class.to_s} #{attributes.inspect}>"
end