Class: Yogo::Collection::Property
- Inherits:
-
Object
- Object
- Yogo::Collection::Property
- Includes:
- DataMapper::Resource
- Defined in:
- lib/yogo/collection/property.rb
Direct Known Subclasses
Constant Summary collapse
- COMMON_PROPERTIES =
[:String, :Text, :Integer, :Float, :Boolean, :Date, :Time, :DateTime]
Instance Method Summary collapse
- #add_to_model(model) ⇒ Object
- #as_json(opts = nil) ⇒ Object
-
#field_name ⇒ Object
validates_uniqueness_of :name, :scope => :data_collection_id.
- #model_method ⇒ Object
- #to_s ⇒ Object
- #update_attributes(hash) ⇒ Object
Instance Method Details
#add_to_model(model) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/yogo/collection/property.rb', line 52 def add_to_model(model) prop_name = self.to_s.intern prop_type = self.class = self. || {} model.send(model_method, prop_name, prop_type, ) end |
#as_json(opts = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/yogo/collection/property.rb', line 29 def as_json(opts=nil) { :id => self.id.to_s, :type => self.type.to_s, :field_name => self.to_s, :name => self.name, :options => self., :data_collection => self.data_collection_id.to_s } end |
#field_name ⇒ Object
validates_uniqueness_of :name, :scope => :data_collection_id
21 22 23 |
# File 'lib/yogo/collection/property.rb', line 21 def field_name self.to_s end |
#model_method ⇒ Object
48 49 50 |
# File 'lib/yogo/collection/property.rb', line 48 def model_method :property end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/yogo/collection/property.rb', line 25 def to_s 'field_' + self.id.to_s.gsub('-','_') end |
#update_attributes(hash) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/yogo/collection/property.rb', line 40 def update_attributes(hash) attrs = {} attrs[:name] = hash[:name] || hash['name'] || self.name attrs[:type] = hash[:type] || hash['type'] || self.type || self.class.name attrs[:options] = hash[:options] || hash['options'] || self. self.attributes = attrs end |