Class: EyServicesFake::Model

Inherits:
Cubbyhole::Base
  • Object
show all
Defined in:
lib/ey_services_fake/models.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.current_idObject

Returns the value of attribute current_id.



9
10
11
# File 'lib/ey_services_fake/models.rb', line 9

def current_id
  @current_id
end

Class Method Details

.backendObject



18
19
20
# File 'lib/ey_services_fake/models.rb', line 18

def self.backend
  @backend ||= Hash.new
end

.belongs_to(model, name, key) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ey_services_fake/models.rb', line 24

def self.belongs_to(model, name, key)
  search_context = self.to_s.split("::")
  search_context.pop
  search_context = eval(search_context.join("::").to_s)
  self.class_eval do
    define_method(name) do
      klass = search_context.const_get(model)
      klass.all.find{|s| self.send(key).to_i == s.id.to_i }
    end
  end
end

.decendantsObject



21
22
23
# File 'lib/ey_services_fake/models.rb', line 21

def self.decendants
  @decendants ||= []
end

.has_many(model, name, key) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ey_services_fake/models.rb', line 35

def self.has_many(model, name, key)
  search_context = self.to_s.split("::")
  search_context.pop
  search_context = eval(search_context.join("::").to_s)
  self.class_eval do
    define_method(name) do
      klass = search_context.const_get(model)
      Cubbyhole::Collection.new(klass.all.select{|s| s.send(key).to_s == self.id.to_s })
    end
  end
end

.inherited(klass) ⇒ Object



5
6
7
# File 'lib/ey_services_fake/models.rb', line 5

def self.inherited(klass)
  decendants << klass
end

.next_idObject



12
13
14
# File 'lib/ey_services_fake/models.rb', line 12

def self.next_id
  Model.current_id += 1
end

.nuke_allObject



15
16
17
# File 'lib/ey_services_fake/models.rb', line 15

def self.nuke_all
  decendants.map(&:nuke)
end