Module: CouchPotato::Persistence::Properties::ClassMethods
- Defined in:
- lib/couch_potato/persistence/properties.rb
Instance Method Summary (collapse)
-
- (Object) property(name, options = {})
Declare a property on a model class.
-
- (Object) property_names
returns all the property names of a model class that have been defined using the #property method.
- - (Object) remove_attribute_accessors_from_activesupport_module
Instance Method Details
- (Object) property(name, options = {})
Declare a property on a model class. Properties are not typed by default. You can store anything in a property that can be serialized into JSON. If you want a property to be of a custom class you have to define it using the :type option.
example:
class Book
property :title
property :year
property :publisher, :type => Publisher
end
72 73 74 75 76 77 |
# File 'lib/couch_potato/persistence/properties.rb', line 72 def property(name, = {}) undefine_attribute_methods define_attribute_methods property_names + [name] properties << SimpleProperty.new(self, name, ) remove_attribute_accessors_from_activesupport_module end |
- (Object) property_names
returns all the property names of a model class that have been defined using the #property method
example:
class Book
property :title
property :year
end
Book.property_names # => [:title, :year]
58 59 60 |
# File 'lib/couch_potato/persistence/properties.rb', line 58 def property_names properties.map(&:name) end |
- (Object) remove_attribute_accessors_from_activesupport_module
79 80 81 82 83 84 85 86 |
# File 'lib/couch_potato/persistence/properties.rb', line 79 def remove_attribute_accessors_from_activesupport_module active_support_module = ancestors[1..-1].find{|m| m.name.nil? && (property_names - m.instance_methods).empty?} if active_support_module property_names.each do |name| active_support_module.send :remove_method, name if active_support_module.instance_methods.include?(name) end end end |