Class: Streak::StreakObject

Inherits:
Object
  • Object
show all
Defined in:
lib/streak/streak_object.rb

Direct Known Subclasses

Box, Field, FieldValue, File, Pipeline, Search, Stage, User

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ StreakObject

Returns a new instance of StreakObject.



28
29
30
31
32
33
34
# File 'lib/streak/streak_object.rb', line 28

def initialize(values)
  @values = {}
  (self.class.attributes + values.keys).each do |k|
    attr = Util.symbolize_attribute(k)
    @values[attr] = StreakObject.convert_to_streak_object(values[k], self.class, attr)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/streak/streak_object.rb', line 36

def method_missing(name, *args)
  if @values.has_key?(name)
    @values[name]
  else
    super
  end
end

Class Method Details

.attributesObject



16
17
18
# File 'lib/streak/streak_object.rb', line 16

def self.attributes
  []
end

.construct_from(values) ⇒ Object



24
25
26
# File 'lib/streak/streak_object.rb', line 24

def self.construct_from(values)
  object = self.new(values)
end

.convert_to_streak_object(resp, type = nil, relation = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/streak/streak_object.rb', line 4

def self.convert_to_streak_object(resp, type = nil, relation = nil)
  case resp
  when Array
    resp.map { |r| convert_to_streak_object(r, type, relation) }
  when Hash
    object_class = (relation.nil? ? type : type.relations[relation]) || StreakObject
    object_class.construct_from(resp)
  else
    resp
  end
end

.relationsObject



20
21
22
# File 'lib/streak/streak_object.rb', line 20

def self.relations
  {}
end