Class: Ice::BaseCube
- Extended by:
- CubeAssociation
- Defined in:
- lib/ice/base_cube.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(source) ⇒ BaseCube
constructor
A new instance of BaseCube.
- #to_hash ⇒ Object
- #to_ice ⇒ Object
- #to_json ⇒ Object
Methods included from CubeAssociation
Constructor Details
#initialize(source) ⇒ BaseCube
Returns a new instance of BaseCube.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ice/base_cube.rb', line 49 def initialize(source) @source = source unless self.class.attribute_names.count > 0 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
#source ⇒ Object (readonly)
Returns the value of attribute source.
4 5 6 |
# File 'lib/ice/base_cube.rb', line 4 def source @source end |
Class Method Details
.attribute_names ⇒ Object
14 15 16 |
# File 'lib/ice/base_cube.rb', line 14 def self.attribute_names @@attribute_names ||= [] end |
.revealing(*attributes) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/ice/base_cube.rb', line 18 def self.revealing(* attributes) 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
#id ⇒ Object
10 11 12 |
# File 'lib/ice/base_cube.rb', line 10 def id @source.id end |
#to_hash ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ice/base_cube.rb', line 29 def to_hash if self.class.attribute_names.count > 0 hash = {} ([:id, :created_at, :updated_at] + self.class.attribute_names).each do |method| if @source.respond_to? method hash[method] = source.send(method) end end hash else @hash ||= @source.serializable_hash.to_ice end end |
#to_ice ⇒ Object
6 7 8 |
# File 'lib/ice/base_cube.rb', line 6 def to_ice self end |
#to_json ⇒ Object
44 45 46 |
# File 'lib/ice/base_cube.rb', line 44 def to_json to_hash.to_json end |