module Property::Declaration::ClassMethods

Public Instance Methods

define_property_methods(column) click to toggle source

Define property methods in a class. This is only triggered when properties are declared directly in the class and not through Role inclusion.

# 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) click to toggle source

Return true if the current object has all the roles of the given schema or role.

# File lib/property/declaration.rb, line 49
def has_role?(role)
  schema.has_role? role
end
include_role(role) click to toggle source

Include a new set of property definitions (Role) into the current class schema. You can also provide a class to simulate multiple inheritance.

# File lib/property/declaration.rb, line 44
def include_role(role)
  schema.include_role role
end
property(&block) click to toggle source

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
# File lib/property/declaration.rb, line 66
def property(&block)
  schema.property(&block)
end