Sha256: e5062f8b67305e8cdfcfea01cfeb5992db60818fd6ad974879b36ca84c097b32

Contents?: true

Size: 996 Bytes

Versions: 1

Compression:

Stored size: 996 Bytes

Contents

module Neo4j
	module Rails
		module Mapping
			module Property
				extend ActiveSupport::Concern
					
				def []=(key, value)
					attribute_will_change!(key.to_s) if self[key.to_s] != value
					super
				end
				
				module ClassMethods
					# Handle some additional options for the property
					#
					# Set a default - 							:default => "default"
					# Prpoerty must be there - 			:null => false
					# Property has a length limit - :limit => 128
					def property(*args)
						super
						handle_property_options_for(args.first)
					end
					
					protected
					def handle_property_options_for(property)
						options = _decl_props[property.to_sym]
		
						write_inheritable_attribute(:attribute_defaults, property => options[:default]) if options[:default]
						validates(property, :non_nil => true) if options.has_key?(:null) && options[:null] == false
						validates(property, :length => { :maximum => options[:limit] }) if options[:limit]
					end
				end
			end
		end
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
neo4j-1.0.0.beta.20 lib/neo4j/rails/mapping/property.rb