Sha256: c44936a19cb9a8862fa4203a8b299fe38959dba5e19d5f4982d27fe60f881fd7

Contents?: true

Size: 1.75 KB

Versions: 4

Compression:

Stored size: 1.75 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)
						_decl_props[property][:defined] = true  # TODO is this needed ?
					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

4 entries across 4 versions & 1 rubygems

Version Path
neo4j-1.0.0.beta.30-java lib/neo4j/rails/mapping/property.rb
neo4j-1.0.0.beta.29-java lib/neo4j/rails/mapping/property.rb
neo4j-1.0.0.beta.28-java lib/neo4j/rails/mapping/property.rb
neo4j-1.0.0.beta.27-java lib/neo4j/rails/mapping/property.rb