module Neo4j::Rails::Mapping::Property::ClassMethods

Public Instance Methods

columns() click to toggle source

Returns all defined properties

# File lib/neo4j/rails/mapping/property.rb, line 28
def columns
  self._decl_props.keys
end
has_n(*args) click to toggle source

Create two new methods: rel_name and rel_name_rels The first one returns an Neo4j::Rails::Relationships::NodesDSL the second generate method (with the _rels postfix) returns a Neo4j::Rails::Relationships::RelsDSL

See also Neo4j::NodeMixin#has_n which only work with persisted relationships.

# File lib/neo4j/rails/mapping/property.rb, line 16
def has_n(*args)
  options = args.extract_options!
  define_has_n_methods_for(args.first, options)
end
has_one(*args) click to toggle source

See #has_n

# File lib/neo4j/rails/mapping/property.rb, line 22
def has_one(*args)
  options = args.extract_options!
  define_has_one_methods_for(args.first, options)
end
property(*args) click to toggle source

Handles options for the property

Set the property type :type => Time Set a default :default => “default” Property must be there :null => false Property has a length limit :limit => 128

# File lib/neo4j/rails/mapping/property.rb, line 112
def property(*args)
  options = args.extract_options!
  args.each do |property_sym|
    property_setup(property_sym, options)
  end
end

Protected Instance Methods

define_property_before_type_cast_methods_for(property, options) click to toggle source
# File lib/neo4j/rails/mapping/property.rb, line 155
          def define_property_before_type_cast_methods_for(property, options)
            property_before_type_cast = "#{property}_before_type_cast"
            class_eval "              def #{property_before_type_cast}=(value)
                @properties_before_type_cast[:#{property}]=value
              end

              def #{property_before_type_cast}
                @properties_before_type_cast.has_key?(:#{property}) ? @properties_before_type_cast[:#{property}] : self.#{property}
              end
", __FILE__, __LINE__
          end
define_property_methods_for(property, options) click to toggle source
# File lib/neo4j/rails/mapping/property.rb, line 137
          def define_property_methods_for(property, options)
            unless method_defined?(property)
              class_eval "                def #{property}
                  send(:[], "#{property}")
                end
", __FILE__, __LINE__
            end

            unless method_defined?("#{property}=".to_sym)
              class_eval "                def #{property}=(value)
                  send(:[]=, "#{property}", value)
                end
", __FILE__, __LINE__
            end
          end
handle_property_options_for(property, options) click to toggle source
# File lib/neo4j/rails/mapping/property.rb, line 127
def handle_property_options_for(property, options)
  attribute_defaults[property.to_s] = options[:default] if options.has_key?(:default)

  if options.has_key?(:null) && options[:null] === false
    validates(property, :non_nil => true, :on => :create)
    validates(property, :non_nil => true, :on => :update)
  end
  validates(property, :length => { :maximum => options[:limit] }) if options[:limit]
end
property_setup(property, options) click to toggle source
# File lib/neo4j/rails/mapping/property.rb, line 120
def property_setup(property, options)
  _decl_props[property] = options
  handle_property_options_for(property, options)
  define_property_methods_for(property, options)
  define_property_before_type_cast_methods_for(property, options)
end