Module: Property::Declaration::ClassMethods
- Defined in:
- lib/property/declaration.rb
Instance Method Summary collapse
-
#define_property_methods(column) ⇒ Object
Define property methods in a class.
-
#has_role?(role) ⇒ Boolean
Return true if the current object has all the roles of the given schema or role.
-
#include_role(role) ⇒ Object
Include a new set of property definitions (Role) into the current class schema.
-
#property(&block) ⇒ Object
Use this class method to declare properties and indices that will be used in your models.
Instance Method Details
#define_property_methods(column) ⇒ Object
Define property methods in a class. This is only triggered when properties are declared directly in the class and not through Role inclusion.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/property/declaration.rb', line 72 def define_property_methods(column) attr_name = column.name class_eval(%Q{ def #{attr_name} # def title prop['#{attr_name}'] # prop['title'] end # end # def #{attr_name}? # def title? prop['#{attr_name}'] # prop['title'] end # end # def #{attr_name}=(new_value) # def title=(new_value) prop['#{attr_name}'] = new_value # prop['title'] = new_value end # end }, __FILE__, __LINE__) end |
#has_role?(role) ⇒ Boolean
Return true if the current object has all the roles of the given schema or role.
49 50 51 |
# File 'lib/property/declaration.rb', line 49 def has_role?(role) schema.has_role? role end |
#include_role(role) ⇒ Object
Include a new set of property definitions (Role) into the current class schema. You can also provide a class to simulate multiple inheritance.
44 45 46 |
# File 'lib/property/declaration.rb', line 44 def include_role(role) schema.include_role role end |
#property(&block) ⇒ Object
Use this class method to declare properties and indices that will be used in your models. Example:
property.string 'phone', :default => '', :indexed => true
You can also use a block:
property do |p|
p.string 'phone', 'name', :default => ''
p.index(:string) do |r|
{
"name_#{r.lang}" => r.name,
}
end
end
66 67 68 |
# File 'lib/property/declaration.rb', line 66 def property(&block) schema.property(&block) end |