Class: Ice::BaseCube

Inherits:
Object show all
Extended by:
CubeAssociation
Defined in:
lib/ice/base_cube.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CubeAssociation

belongs_to, has_many

Constructor Details

#initialize(source) ⇒ BaseCube

Returns a new instance of BaseCube.



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ice/base_cube.rb', line 40

def initialize(source)
  @source = source
  unless @attribute_names
    to_hash.each_key do |key|
      unless self.respond_to? key.to_sym
        self.class.send :define_method, key.to_sym do
          @source.send(key.to_sym)
        end
      end
    end
  end
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



18
19
20
# File 'lib/ice/base_cube.rb', line 18

def source
  @source
end

Class Method Details

.revealing(*attributes) ⇒ Object



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

def self.revealing(* attributes) 
  unless @attribute_names
    @attribute_names = []
  end
  @attribute_names.concat(attributes)

  attributes.each do |attr|
    define_method attr.to_sym do
      @source.send(attr).to_ice
    end
  end
end

Instance Method Details

#idObject



36
37
38
# File 'lib/ice/base_cube.rb', line 36

def id
  @source.id
end

#to_hashObject



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

def to_hash
  if @attribute_names
    hash = {:id => @source.id}
    @attribute_names && @attribute_names.each do |name|
      hash[name] = @source.send(name)
    end
    hash
  else
    @hash = @source.serializable_hash
  end
end

#to_iceObject



20
21
22
# File 'lib/ice/base_cube.rb', line 20

def to_ice
  self
end