Module: Basecampx::Relations

Included in:
Resource
Defined in:
lib/basecampx/relations.rb

Instance Method Summary collapse

Instance Method Details

#has_many(method, klass) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/basecampx/relations.rb', line 32

def has_many method, klass
  self.class_eval <<-EOB

    def #{method.to_s}
      @#{method.to_s}
    end

    def #{method.to_s}=#{method.to_s}_obj
      @#{method.to_s} ||= #{klass.to_s.titleize}.parse #{method.to_s}_obj
    end

  EOB
end

#has_one(method, klass) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/basecampx/relations.rb', line 18

def has_one method, klass
  self.class_eval <<-EOB

    def #{method.to_s}
      @#{method.to_s}
    end

    def #{method.to_s}=#{method.to_s}_obj
      @#{method.to_s} ||= #{klass.to_s.titleize}.new #{method.to_s}_obj
    end

  EOB
end

#mount(method, klass) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/basecampx/relations.rb', line 4

def mount method, klass
  self.class_eval <<-EOB

    def #{method.to_s}
      @#{method.to_s}
    end

    def #{method.to_s}=#{method.to_s}_obj
      @#{method.to_s} ||= #{klass.to_s.titleize}.new #{method.to_s}_obj
    end

  EOB
end