Sha256: c9d725b99bdbd915cb21569860f937a9ca3a4379a9c5fdb1ddb796fa4264e0fc
Contents?: true
Size: 1.68 KB
Versions: 3
Compression:
Stored size: 1.68 KB
Contents
module Neo4j module Rails module Mapping module Property extend ActiveSupport::Concern module ClassMethods # 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 def property(*args) options = args.extract_options! args.each do |property_sym| property_setup(property_sym, options) end end protected def property_setup(property, options) _decl_props[property] = options handle_property_options_for(property, options) define_property_methods_for(property, options) end 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 def define_property_methods_for(property, options) unless method_defined?(property) class_eval <<-RUBY, __FILE__, __LINE__ def #{property} send(:[], "#{property}") end RUBY end unless method_defined?("#{property}=".to_sym) class_eval <<-RUBY, __FILE__, __LINE__ def #{property}=(value) send(:[]=, "#{property}", value) end RUBY end end end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
neo4j-1.0.0-java | lib/neo4j/rails/mapping/property.rb |
neo4j-1.0.0.beta.32-java | lib/neo4j/rails/mapping/property.rb |
neo4j-1.0.0.beta.31-java | lib/neo4j/rails/mapping/property.rb |