Class: EventBright::ApiObjectCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/eventbright/api_object_collection.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner = false, hash_array = [], parent = false) ⇒ ApiObjectCollection

Returns a new instance of ApiObjectCollection


4
5
6
7
8
9
10
# File 'lib/eventbright/api_object_collection.rb', line 4

def initialize(owner = false, hash_array = [], parent = false)
  @owner = owner
  hash_array = [] if hash_array.nil?
  arr = hash_array.map{|v| v[self.class.singlet_name]}.reject{|v| v.empty? }
  @array = arr.map{|v| self.class.collection_for.new(owner, v)}
  @array = @array.reject{|v| v.__send__(self.class.collection_for.requires.first).nil? || v.__send__(self.class.collection_for.requires.first) == ""} unless self.class.collection_for.requires.empty?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object


34
35
36
# File 'lib/eventbright/api_object_collection.rb', line 34

def method_missing(meth, *args, &block)
  @array.__send__(meth, *args, &block)
end

Class Method Details

.collection_for(type = false) ⇒ Object


39
40
41
42
# File 'lib/eventbright/api_object_collection.rb', line 39

def self.collection_for(type = false)
  @collection_for = type if type
  @collection_for 
end

.getter(name = false) ⇒ Object


55
56
57
58
# File 'lib/eventbright/api_object_collection.rb', line 55

def self.getter(name = false)
  @getter = name if name
  @getter || "user_list_#{self.plural_name}"
end

.plural_name(name = false) ⇒ Object


49
50
51
52
# File 'lib/eventbright/api_object_collection.rb', line 49

def self.plural_name(name = false)
  @plural_name = name if name
  @plural_name || @collection_for.plural_name || "#{self.singlet_name}s"
end

.singlet_name(name = false) ⇒ Object


44
45
46
47
# File 'lib/eventbright/api_object_collection.rb', line 44

def self.singlet_name(name = false)
  @singlet_name = name if name
  @singlet_name || @collection_for.singlet_name
end

Instance Method Details

#dirty?Boolean

Returns:

  • (Boolean)

26
27
28
29
30
31
32
# File 'lib/eventbright/api_object_collection.rb', line 26

def dirty?
  is_dirty = false
  @array.each do |a|
    is_dirty = true if a.dirty?
  end
  is_dirty
end

#inspectObject


12
13
14
# File 'lib/eventbright/api_object_collection.rb', line 12

def inspect
  "#{@array.inspect}"
end

#saveObject


20
21
22
23
24
# File 'lib/eventbright/api_object_collection.rb', line 20

def save
  @array.each do |a|
    a.save if a.dirty?
  end
end

#to_sObject


16
17
18
# File 'lib/eventbright/api_object_collection.rb', line 16

def to_s
  "#{@array.inspect}"
end