Gets the field naming conventions for this resource in the given Repository
@param [String, Symbol] repository_name
the name of the Repository for which the field naming convention will be retrieved
@return [#]
The naming convention for the given Repository
@api public
# File lib/dm-core/model/property.rb, line 159 159: def field_naming_convention(repository_name = default_storage_name) 160: @field_naming_conventions[repository_name] ||= repository(repository_name).adapter.field_naming_convention 161: end
# File lib/dm-core/model/property.rb, line 15 15: def inherited(model) 16: model.instance_variable_set(:@properties, {}) 17: model.instance_variable_set(:@field_naming_conventions, @field_naming_conventions.dup) 18: 19: @properties.each do |repository_name, properties| 20: model_properties = model.properties(repository_name) 21: properties.each { |property| model_properties << property } 22: end 23: 24: super 25: end
Gets the list of key fields for this Model in repository_name
@param [String] repository_name
The name of the Repository for which the key is to be reported
@return [Array]
The list of key fields for this Model in +repository_name+
@api public
# File lib/dm-core/model/property.rb, line 140 140: def key(repository_name = default_repository_name) 141: properties(repository_name).key 142: end
@api private
# File lib/dm-core/model/property.rb, line 177 177: def key_conditions(repository, key) 178: Hash[ self.key(repository.name).zip(key.nil? ? [] : key) ] 179: end
Gets a list of all properties that have been defined on this Model in the requested repository
@param [Symbol, String] repository_name
The name of the repository to use. Uses the default Repository if none is specified.
@return [PropertySet]
A list of Properties defined on this Model in the given Repository
@api public
# File lib/dm-core/model/property.rb, line 116 116: def properties(repository_name = default_repository_name) 117: # TODO: create PropertySet#copy that will copy the properties, but assign the 118: # new Relationship objects to a supplied repository and model. dup does not really 119: # do what is needed 120: repository_name = repository_name.to_sym 121: 122: default_repository_name = self.default_repository_name 123: 124: @properties[repository_name] ||= if repository_name == default_repository_name 125: PropertySet.new 126: else 127: properties(default_repository_name).dup 128: end 129: end
@api private
# File lib/dm-core/model/property.rb, line 164 164: def properties_with_subclasses(repository_name = default_repository_name) 165: properties = properties(repository_name).dup 166: 167: descendants.each do |model| 168: model.properties(repository_name).each do |property| 169: properties << property 170: end 171: end 172: 173: properties 174: end
Defines a Property on the Resource
@param [Symbol] name
the name for which to call this property
@param [Class] type
the ruby type to define this property as
@param [Hash(Symbol => String)] options
a hash of available options
@return [Property]
the created Property
@see Property
@api public
# File lib/dm-core/model/property.rb, line 42 42: def property(name, type, options = {}) 43: if TrueClass == type 44: raise "#{type} is deprecated, use Boolean instead at #{caller[2]}" 45: elsif BigDecimal == type 46: raise "#{type} is deprecated, use Decimal instead at #{caller[2]}" 47: end 48: 49: # if the type can be found within Property then 50: # use that class rather than the primitive 51: unless klass = DataMapper::Property.determine_class(type) 52: raise ArgumentError, "+type+ was #{type.inspect}, which is not a supported type" 53: end 54: 55: property = klass.new(self, name, options) 56: 57: repository_name = self.repository_name 58: properties = properties(repository_name) 59: 60: properties << property 61: 62: # Add property to the other mappings as well if this is for the default 63: # repository. 64: 65: if repository_name == default_repository_name 66: other_repository_properties = DataMapper::Ext::Hash.except(@properties, default_repository_name) 67: 68: other_repository_properties.each do |other_repository_name, properties| 69: next if properties.named?(name) 70: 71: # make sure the property is created within the correct repository scope 72: DataMapper.repository(other_repository_name) do 73: properties << klass.new(self, name, options) 74: end 75: end 76: end 77: 78: # Add the property to the lazy_loads set for this resources repository 79: # only. 80: # TODO Is this right or should we add the lazy contexts to all 81: # repositories? 82: if property.lazy? 83: context = options.fetch(:lazy, :default) 84: context = :default if context == true 85: 86: Array(context).each do |context| 87: properties.lazy_context(context) << property 88: end 89: end 90: 91: # add the property to the child classes only if the property was 92: # added after the child classes' properties have been copied from 93: # the parent 94: descendants.each do |descendant| 95: descendant.properties(repository_name) << property 96: end 97: 98: create_reader_for(property) 99: create_writer_for(property) 100: 101: # FIXME: explicit return needed for YARD to parse this properly 102: return property 103: end
defines the reader method for the property
@api private
# File lib/dm-core/model/property.rb, line 200 200: def create_reader_for(property) 201: name = property.name.to_s 202: reader_visibility = property.reader_visibility 203: instance_variable_name = property.instance_variable_name 204: property_module.module_eval #{reader_visibility} def #{name} return #{instance_variable_name} if defined?(#{instance_variable_name}) property = properties[#{name.inspect}] #{instance_variable_name} = property ? persistence_state.get(property) : nil end, __FILE__, __LINE__ + 1 205: 206: boolean_reader_name = "#{name}?" 207: 208: if property.kind_of?(DataMapper::Property::Boolean) 209: property_module.module_eval #{reader_visibility} def #{boolean_reader_name} #{name} end, __FILE__, __LINE__ + 1 210: end 211: end
defines the setter for the property
@api private
# File lib/dm-core/model/property.rb, line 228 228: def create_writer_for(property) 229: name = property.name 230: writer_visibility = property.writer_visibility 231: 232: writer_name = "#{name}=" 233: property_module.module_eval #{writer_visibility} def #{writer_name}(value) property = properties[#{name.inspect}] self.persistence_state = persistence_state.set(property, value) persistence_state.get(property) end, __FILE__, __LINE__ + 1 234: end
@api public
# File lib/dm-core/model/property.rb, line 244 244: def method_missing(method, *args, &block) 245: if property = properties(repository_name)[method] 246: return property 247: end 248: 249: super 250: end
Defines the anonymous module that is used to add properties. Using a single module here prevents having a very large number of anonymous modules, where each property has their own module. @api private
# File lib/dm-core/model/property.rb, line 187 187: def property_module 188: @property_module ||= begin 189: mod = Module.new 190: class_eval do 191: include mod 192: end 193: mod 194: end 195: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.