Module: Jinx::Propertied
- Included in:
- Introspector
- Defined in:
- lib/jinx/metadata/propertied.rb
Overview
Meta-data mix-in for attribute accessors.
Instance Attribute Summary collapse
-
#attributes ⇒ <Symbol>
readonly
This class’s attributes.
-
#defaults ⇒ Hashable
readonly
The default attribute => value associations.
Instance Method Summary collapse
-
#add_alternate_key_attribute(attribute) ⇒ Object
private
Adds the given attribute to this class’s alternate key.
-
#add_attribute(attribute, type, *flags) ⇒ Property
Adds the given attribute to this Class.
-
#add_attribute_aliases(hash) ⇒ Object
private
deprecated
Deprecated.
Use #alias_attribute instead
- #add_attribute_default(attribute, value) ⇒ Object private
- #add_attribute_defaults(hash) ⇒ Object private
- #add_mandatory_attribute(attribute) ⇒ Object private
- #add_mandatory_attributes(*attributes) ⇒ Object private
-
#add_primary_key_attribute(attribute) ⇒ Object
private
Adds the given attribute to this class’s primary key.
- #add_property(property) ⇒ Object private
-
#add_restriction(attribute) ⇒ Object
Adds the given attribute restriction to this Class.
-
#add_secondary_key_attribute(attribute) ⇒ Object
private
Adds the given attribute to this class’s secondary key.
-
#alias_attribute(aliaz, attribute) ⇒ Object
private
Creates the given attribute alias.
-
#alias_standard_attribute_hash ⇒ {Symbol => Symbol}
protected
The attribute alias => standard hash.
-
#all_key_attributes ⇒ <Symbol>
The primary, secondary and alternate key attributes.
-
#alternate_key_attributes ⇒ <Symbol>
Returns this class’s alternate key attribute array.
-
#append_ancestor_enum(enum) ⇒ Enumerable
private
Appends to the given enumerable the result of evaluating the block given to this method on the superclass, if the superclass is in the same parent module as this class.
-
#attribute_filter(attributes = nil) {|prop| ... } ⇒ AttributeEnumerator
Returns an AttributeEnumerator on this Resource class’s attributes which iterates on each of the given attributes.
-
#collect_mandatory_attributes ⇒ Object
private
Merges the secondary key, owner and additional mandatory attributes defined in the attributes.
-
#collection_attribute?(attribute) ⇒ Boolean
Whether attribute is an instance of a Java domain class.
-
#create_nonjava_property(attribute, type, *flags) ⇒ Property
private
The attribute meta-data.
- #default_mandatory_local_attributes ⇒ Object private
-
#dependent_attributes(inc_super = true) ⇒ <Symbol>
The dependent attributes.
-
#detect_attribute_with_type(klass) ⇒ Symbol?
private
Detects the first attribute with the given type.
-
#domain_attribute?(attribute) ⇒ Boolean
Whether attribute return type is a domain object or collection thereof.
-
#domain_attributes ⇒ <Symbol>
The domain attributes.
- #each_property {|prop| ... } ⇒ Object
-
#independent_attributes ⇒ <Symbol>
The Jinx::PropertyCharacteristics#independent? attributes.
-
#init_property_classifiers ⇒ Object
private
Initializes the property meta-data structures.
-
#introspected? ⇒ Boolean
Whether this class’s metadata has been introspected.
-
#java_attributes ⇒ <Symbol>
(also: #printable_attributes)
The domain attributes which wrap a java attribute.
-
#mandatory_attributes ⇒ Object
Returns the subject class’s required attributes, determined as follows: * An attribute marked with the :mandatory flag is mandatory.
-
#mandatory_owner_attribute ⇒ Symbol?
private
The unique non-self-referential owner attribute, if one exists.
-
#most_specific_domain_attribute(klass, attributes = nil) ⇒ Symbol?
private
Returns the most specific attribute which references the given target type, or nil if none.
-
#nondomain_attribute?(attribute) ⇒ Boolean
Whether attribute is not a domain attribute.
-
#nondomain_attributes ⇒ <Symbol>
The non-domain Java attributes.
-
#nondomain_java_attributes ⇒ <Symbol>
(also: #mergeable_attributes)
The non-domain Java attribute wrapper attributes.
- #nonowner_attributes ⇒ Object
-
#offset_attribute(hash, offset = nil) ⇒ Object
private
Makes a new synthetic Class#offset_attr_accessor attribute for each method => original hash entry.
-
#primary_key_attributes ⇒ <Symbol>
The primary key attributes.
-
#property(attribute) ⇒ Property
The corresponding property.
-
#property_defined?(name) ⇒ Boolean
Returns whether this class has an attribute with the given symbol.
-
#property_hash ⇒ {Symbol => Property}
protected
The attribute => metadata hash.
-
#property_path(*attributes) ⇒ <Property>
The corresponding property path.
-
#qualify_attribute(attribute, *flags) ⇒ Object
private
Marks the given attribute with flags supported by Jinx::Property#qualify.
-
#register_property_alias(aliaz, attribute) ⇒ Object
private
Registers an alias to an attribute.
-
#remove_attribute(attribute) ⇒ Object
private
Removes the given attribute from this Resource.
-
#secondary_key_attributes ⇒ <Symbol>
Returns this class’s secondary key attribute array.
-
#secondary_key_non_owner_domain_attributes ⇒ <Symbol>
# the non-owner secondary key domain attributes.
-
#set_alternate_key_attributes(*attributes) ⇒ Object
private
Sets this class’s alternate key attributes to the given attributes.
-
#set_attribute_type(attribute, klass) ⇒ Object
private
Sets the given attribute type to klass.
-
#set_primary_key_attributes(*attributes) ⇒ Object
private
Sets this class’s primary key attributes to the given attributes.
-
#set_secondary_key_attributes(*attributes) ⇒ Object
private
Sets this class’s secondary key attributes to the given attributes.
-
#standard_attribute(name_or_alias) ⇒ Symbol
The standard attribute symbol for the given name or alias.
-
#unidirectional_dependent_attributes ⇒ <Symbol>
The unidirectional dependent attributes.
Instance Attribute Details
#attributes ⇒ <Symbol> (readonly)
Returns this class’s attributes.
11 12 13 |
# File 'lib/jinx/metadata/propertied.rb', line 11 def attributes @attributes end |
#defaults ⇒ Hashable (readonly)
Returns the default attribute => value associations.
14 15 16 |
# File 'lib/jinx/metadata/propertied.rb', line 14 def defaults @defaults end |
Instance Method Details
#add_alternate_key_attribute(attribute) ⇒ Object (private)
Adds the given attribute to this class’s alternate key.
343 344 345 346 |
# File 'lib/jinx/metadata/propertied.rb', line 343 def add_alternate_key_attribute(attribute) @alt_key ||= [] @alt_key << standard_attribute(attribute) end |
#add_attribute(attribute, type, *flags) ⇒ Property
Adds the given attribute to this Class.
30 31 32 33 34 |
# File 'lib/jinx/metadata/propertied.rb', line 30 def add_attribute(attribute, type, *flags) prop = create_nonjava_property(attribute, type, *flags) add_property(prop) prop end |
#add_attribute_aliases(hash) ⇒ Object (private)
Use #alias_attribute instead
Creates the given aliases to attributes.
314 315 316 |
# File 'lib/jinx/metadata/propertied.rb', line 314 def add_attribute_aliases(hash) hash.each { |aliaz, pa| alias_attribute(aliaz, pa) } end |
#add_attribute_default(attribute, value) ⇒ Object (private)
385 386 387 |
# File 'lib/jinx/metadata/propertied.rb', line 385 def add_attribute_default(attribute, value) @local_defaults[standard_attribute(attribute)] = value end |
#add_attribute_defaults(hash) ⇒ Object (private)
379 380 381 |
# File 'lib/jinx/metadata/propertied.rb', line 379 def add_attribute_defaults(hash) hash.each { |da, value| add_attribute_default(da, value) } end |
#add_mandatory_attribute(attribute) ⇒ Object (private)
395 396 397 |
# File 'lib/jinx/metadata/propertied.rb', line 395 def add_mandatory_attribute(attribute) @local_mndty_attrs << standard_attribute(attribute) end |
#add_mandatory_attributes(*attributes) ⇒ Object (private)
390 391 392 |
# File 'lib/jinx/metadata/propertied.rb', line 390 def add_mandatory_attributes(*attributes) attributes.each { |ma| add_mandatory_attribute(ma) } end |
#add_primary_key_attribute(attribute) ⇒ Object (private)
Adds the given attribute to this class’s primary key.
319 320 321 322 |
# File 'lib/jinx/metadata/propertied.rb', line 319 def add_primary_key_attribute(attribute) @prm_key ||= [] @prm_key << standard_attribute(attribute) end |
#add_property(property) ⇒ Object (private)
437 438 439 440 441 442 |
# File 'lib/jinx/metadata/propertied.rb', line 437 def add_property(property) pa = property.attribute @local_prop_hash[pa] = property # map the attribute symbol to itself in the alias map @local_std_prop_hash[pa] = pa end |
#add_restriction(attribute) ⇒ Object
Adds the given attribute restriction to this Class. This method is intended for the exclusive use of Jinx::Property#restrict. Clients restrict an attribute by calling that method.
41 42 43 44 |
# File 'lib/jinx/metadata/propertied.rb', line 41 def add_restriction(attribute) add_property(attribute) logger.debug { "Added restriction #{attribute} to #{qp}." } end |
#add_secondary_key_attribute(attribute) ⇒ Object (private)
Adds the given attribute to this class’s secondary key.
331 332 333 334 |
# File 'lib/jinx/metadata/propertied.rb', line 331 def add_secondary_key_attribute(attribute) @scnd_key ||= [] @scnd_key << standard_attribute(attribute) end |
#alias_attribute(aliaz, attribute) ⇒ Object (private)
Creates the given attribute alias. If the attribute metadata is registered with this class, then this method overrides Class.alias_attribute
to create a new alias reader (writer) method which delegates to the attribute reader (writer, resp.). This aliasing mechanism differs from Class#alias_attribute, which directly aliases the existing reader or writer method. Delegation allows the alias to pick up run-time redefinitions of the aliased reader and writer. If the attribute metadata is not registered with this class, then this method delegates to Class#alias_attribute.
300 301 302 303 304 305 306 307 |
# File 'lib/jinx/metadata/propertied.rb', line 300 def alias_attribute(aliaz, attribute) if property_defined?(attribute) then delegate_to_property(aliaz, property(attribute)) register_property_alias(aliaz, attribute) else super end end |
#alias_standard_attribute_hash ⇒ {Symbol => Symbol} (protected)
Returns the attribute alias => standard hash.
236 237 238 |
# File 'lib/jinx/metadata/propertied.rb', line 236 def alias_standard_attribute_hash @alias_std_prop_map end |
#all_key_attributes ⇒ <Symbol>
Returns the primary, secondary and alternate key attributes.
70 71 72 |
# File 'lib/jinx/metadata/propertied.rb', line 70 def all_key_attributes primary_key_attributes + secondary_key_attributes + alternate_key_attributes end |
#alternate_key_attributes ⇒ <Symbol>
Returns this class’s alternate key attribute array. If this class’s secondary key is not set, then the alternate key is the Metadata superclass alternate key, if any.
65 66 67 |
# File 'lib/jinx/metadata/propertied.rb', line 65 def alternate_key_attributes @alt_key or superclass < Resource ? superclass.alternate_key_attributes : Array::EMPTY_ARRAY end |
#append_ancestor_enum(enum) ⇒ Enumerable (private)
Appends to the given enumerable the result of evaluating the block given to this method on the superclass, if the superclass is in the same parent module as this class.
459 460 461 462 463 464 465 466 |
# File 'lib/jinx/metadata/propertied.rb', line 459 def append_ancestor_enum(enum) return enum unless Class === self and superclass.parent_module == parent_module anc_enum = yield superclass if anc_enum.nil? then raise MetadataError.new("#{qp} superclass #{superclass.qp} does not have required metadata") end enum.union(anc_enum) end |
#attribute_filter(attributes = nil) {|prop| ... } ⇒ AttributeEnumerator
Returns an AttributeEnumerator on this Resource class’s attributes which iterates on each of the given attributes. If a filter block is given, then only those properties which satisfy the filter block are enumerated.
216 217 218 219 220 221 |
# File 'lib/jinx/metadata/propertied.rb', line 216 def attribute_filter(attributes=nil, &filter) # make the attribute filter raise MetadataError.new("#{self} has not been introspected") unless introspected? ph = attributes ? attributes.to_compact_hash { |pa| @prop_hash[pa] } : @prop_hash AttributeEnumerator.new(ph, &filter) end |
#collect_mandatory_attributes ⇒ Object (private)
Merges the secondary key, owner and additional mandatory attributes defined in the attributes.
480 481 482 483 |
# File 'lib/jinx/metadata/propertied.rb', line 480 def collect_mandatory_attributes @local_mndty_attrs.merge!(default_mandatory_local_attributes) append_ancestor_enum(@local_mndty_attrs) { |par| par.mandatory_attributes } end |
#collection_attribute?(attribute) ⇒ Boolean
Returns whether attribute is an instance of a Java domain class.
204 205 206 |
# File 'lib/jinx/metadata/propertied.rb', line 204 def collection_attribute?(attribute) property(attribute).collection? end |
#create_nonjava_property(attribute, type, *flags) ⇒ Property (private)
Returns the attribute meta-data.
256 257 258 |
# File 'lib/jinx/metadata/propertied.rb', line 256 def create_nonjava_property(attribute, type, *flags) Property.new(attribute, self, type, *flags) end |
#default_mandatory_local_attributes ⇒ Object (private)
485 486 487 488 489 490 491 492 493 494 |
# File 'lib/jinx/metadata/propertied.rb', line 485 def default_mandatory_local_attributes mandatory = Set.new # add the secondary key mandatory.merge(secondary_key_attributes) # add the owner attribute, if any oa = mandatory_owner_attribute mandatory << oa if oa # remove optional attributes mandatory.delete_if { |ma| property(ma).flags.include?(:optional) } end |
#dependent_attributes(inc_super = true) ⇒ <Symbol>
Returns the dependent attributes.
159 160 161 162 163 164 165 |
# File 'lib/jinx/metadata/propertied.rb', line 159 def dependent_attributes(inc_super=true) if inc_super then @dep_flt ||= attribute_filter { |prop| prop.dependent? } else @local_dep_flt ||= dependent_attributes.compose { |prop| prop.declarer == self } end end |
#detect_attribute_with_type(klass) ⇒ Symbol? (private)
Detects the first attribute with the given type.
286 287 288 |
# File 'lib/jinx/metadata/propertied.rb', line 286 def detect_attribute_with_type(klass) property_hash.detect_key_with_value { |prop| prop.type == klass } end |
#domain_attribute?(attribute) ⇒ Boolean
Returns whether attribute return type is a domain object or collection thereof.
192 193 194 |
# File 'lib/jinx/metadata/propertied.rb', line 192 def domain_attribute?(attribute) property(attribute).domain? end |
#domain_attributes ⇒ <Symbol>
Returns the domain attributes.
133 134 135 |
# File 'lib/jinx/metadata/propertied.rb', line 133 def domain_attributes @dom_flt ||= attribute_filter { |prop| prop.domain? } end |
#each_property {|prop| ... } ⇒ Object
76 77 78 |
# File 'lib/jinx/metadata/propertied.rb', line 76 def each_property(&block) @prop_hash.each_value(&block) end |
#independent_attributes ⇒ <Symbol>
Returns the Jinx::PropertyCharacteristics#independent? attributes.
153 154 155 |
# File 'lib/jinx/metadata/propertied.rb', line 153 def independent_attributes @ind_flt ||= attribute_filter { |prop| prop.independent? } end |
#init_property_classifiers ⇒ Object (private)
Initializes the property meta-data structures.
243 244 245 246 247 248 249 250 251 252 |
# File 'lib/jinx/metadata/propertied.rb', line 243 def init_property_classifiers @local_std_prop_hash = {} @alias_std_prop_map = append_ancestor_enum(@local_std_prop_hash) { |par| par.alias_standard_attribute_hash } @local_prop_hash = {} @prop_hash = append_ancestor_enum(@local_prop_hash) { |par| par.property_hash } @attributes = Enumerable::Enumerator.new(@prop_hash, :each_key) @local_mndty_attrs = Set.new @local_defaults = {} @defaults = append_ancestor_enum(@local_defaults) { |par| par.defaults } end |
#introspected? ⇒ Boolean
Returns whether this class’s metadata has been introspected.
224 225 226 |
# File 'lib/jinx/metadata/propertied.rb', line 224 def introspected? !!@prop_hash end |
#java_attributes ⇒ <Symbol> Also known as: printable_attributes
Returns the domain attributes which wrap a java attribute.
126 127 128 |
# File 'lib/jinx/metadata/propertied.rb', line 126 def java_attributes @java_flt ||= attribute_filter { |prop| prop.java_property? } end |
#mandatory_attributes ⇒ Object
Returns the subject class’s required attributes, determined as follows:
-
An attribute marked with the :mandatory flag is mandatory.
-
An attribute marked with the :optional or :autogenerated flag is not mandatory.
-
Otherwise, A secondary key or owner attribute is mandatory.
177 178 179 |
# File 'lib/jinx/metadata/propertied.rb', line 177 def mandatory_attributes @mnd_flt ||= collect_mandatory_attributes end |
#mandatory_owner_attribute ⇒ Symbol? (private)
Returns the unique non-self-referential owner attribute, if one exists.
497 498 499 500 501 |
# File 'lib/jinx/metadata/propertied.rb', line 497 def mandatory_owner_attribute oa = owner_attribute || return prop = property(oa) oa if prop.java_property? and prop.type != self end |
#most_specific_domain_attribute(klass, attributes = nil) ⇒ Symbol? (private)
Returns the most specific attribute which references the given target type, or nil if none. If the given class can be returned by more than on of the attributes, then the attribute is chosen whose return type most closely matches the given class.
267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/jinx/metadata/propertied.rb', line 267 def most_specific_domain_attribute(klass, attributes=nil) attributes ||= domain_attributes candidates = attributes.properties best = candidates.inject(nil) do |better, prop| # If the attribute can return the klass then the return type is a candidate. # In that case, the klass replaces the best candidate if it is more specific than # the best candidate so far. klass <= prop.type ? (better && better.type <= prop.type ? better : prop) : better end if best then logger.debug { "Most specific #{qp} -> #{klass.qp} reference from among #{candidates.qp} is #{best.declarer.qp}.#{best}." } best.to_sym end end |
#nondomain_attribute?(attribute) ⇒ Boolean
Returns whether attribute is not a domain attribute.
198 199 200 |
# File 'lib/jinx/metadata/propertied.rb', line 198 def nondomain_attribute?(attribute) not domain_attribute?(attribute) end |
#nondomain_attributes ⇒ <Symbol>
Returns the non-domain Java attributes.
138 139 140 |
# File 'lib/jinx/metadata/propertied.rb', line 138 def nondomain_attributes @ndom_flt ||= attribute_filter { |prop| prop.java_property? and prop.nondomain? } end |
#nondomain_java_attributes ⇒ <Symbol> Also known as: mergeable_attributes
Returns the non-domain Java attribute wrapper attributes.
143 144 145 |
# File 'lib/jinx/metadata/propertied.rb', line 143 def nondomain_java_attributes @ndom_java_flt ||= nondomain_attributes.compose { |prop| prop.java_property? } end |
#nonowner_attributes ⇒ Object
181 182 183 |
# File 'lib/jinx/metadata/propertied.rb', line 181 def nonowner_attributes @nownr_atts ||= attribute_filter { |prop| not prop.owner? } end |
#offset_attribute(hash, offset = nil) ⇒ Object (private)
Makes a new synthetic Class#offset_attr_accessor attribute for each method => original hash entry.
472 473 474 475 |
# File 'lib/jinx/metadata/propertied.rb', line 472 def offset_attribute(hash, offset=nil) offset_attr_accessor(hash, offset) hash.each { |ja, original| add_attribute(ja, property(original).type) } end |
#primary_key_attributes ⇒ <Symbol>
Returns the primary key attributes.
47 48 49 |
# File 'lib/jinx/metadata/propertied.rb', line 47 def primary_key_attributes @prm_key or Class === self && superclass < Resource ? superclass.primary_key_attributes : Array::EMPTY_ARRAY end |
#property(attribute) ⇒ Property
Returns the corresponding property.
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/jinx/metadata/propertied.rb', line 83 def property(attribute) # Simple and predominant case is that the attribute is a standard attribute. # Otherwise, resolve attribute to the standard symbol. prop = @prop_hash[attribute] || @prop_hash[standard_attribute(attribute)] # If not found, then raise a NameError. if prop.nil? then raise NameError.new("#{name.demodulize} attribute not found: #{attribute}") end prop end |
#property_defined?(name) ⇒ Boolean
Returns whether this class has an attribute with the given symbol.
20 21 22 |
# File 'lib/jinx/metadata/propertied.rb', line 20 def property_defined?(name) !!@alias_std_prop_map[name.to_sym] end |
#property_hash ⇒ {Symbol => Property} (protected)
Returns the attribute => metadata hash.
231 232 233 |
# File 'lib/jinx/metadata/propertied.rb', line 231 def property_hash @prop_hash end |
#property_path(*attributes) ⇒ <Property>
Returns the corresponding property path.
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/jinx/metadata/propertied.rb', line 99 def property_path(*attributes) raise ArgumentError.new("#{self} property path attributes is missing") if attributes.empty? # the property of the first attribute prop = property(attributes.shift) return [prop] if attributes.empty? unless prop.type < Resource then raise ArgumentError.new("#{self} property path attribute #{prop} is not a domain type") end # Prepend the first property to the remaining properties. prop.type.property_path(*attributes).unshift(prop) end |
#qualify_attribute(attribute, *flags) ⇒ Object (private)
Marks the given attribute with flags supported by Jinx::Property#qualify.
403 404 405 406 407 408 409 410 411 |
# File 'lib/jinx/metadata/propertied.rb', line 403 def qualify_attribute(attribute, *flags) prop = property(attribute) if prop.declarer == self then prop.qualify(*flags) else logger.debug { "Restricting #{prop.declarer.qp}.#{attribute} to #{qp} with additional flags #{flags.to_series}" } prop.restrict_flags(self, *flags) end end |
#register_property_alias(aliaz, attribute) ⇒ Object (private)
Registers an alias to an attribute.
447 448 449 450 451 |
# File 'lib/jinx/metadata/propertied.rb', line 447 def register_property_alias(aliaz, attribute) std = standard_attribute(attribute) raise ArgumentError.new("#{self} attribute not found: #{attribute}") if std.nil? @local_std_prop_hash[aliaz.to_sym] = std end |
#remove_attribute(attribute) ⇒ Object (private)
Removes the given attribute from this Resource. An attribute declared in a superclass Resource is hidden from this Resource but retained in the declaring Resource.
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'lib/jinx/metadata/propertied.rb', line 416 def remove_attribute(attribute) sa = standard_attribute(attribute) # if the attribute is local, then delete it, otherwise filter out the superclass attribute sp = @local_prop_hash.delete(sa) if sp then # clear the inverse, if any clear_inverse(sp) # remove from the mandatory attributes, if necessary @local_mndty_attrs.delete(sa) # remove from the attribute => metadata hash @local_std_prop_hash.delete_if { |aliaz, pa| pa == sa } else # Filter the superclass hashes. anc_prop_hash = @prop_hash.components[1] @prop_hash.components[1] = anc_prop_hash.filter_on_key { |pa| pa != attribute } anc_alias_hash = @alias_std_prop_map.components[1] @alias_std_prop_map.components[1] = anc_alias_hash.filter_on_key { |pa| pa != attribute } end end |
#secondary_key_attributes ⇒ <Symbol>
Returns this class’s secondary key attribute array. If this class’s secondary key is not set, then the secondary key is the Metadata superclass secondary key, if any.
56 57 58 |
# File 'lib/jinx/metadata/propertied.rb', line 56 def secondary_key_attributes @scnd_key or Class === self && superclass < Resource ? superclass.secondary_key_attributes : Array::EMPTY_ARRAY end |
#secondary_key_non_owner_domain_attributes ⇒ <Symbol>
Returns # the non-owner secondary key domain attributes.
186 187 188 |
# File 'lib/jinx/metadata/propertied.rb', line 186 def secondary_key_non_owner_domain_attributes @scd_key_nown_flt ||= attribute_filter(secondary_key_attributes) { |prop| prop.domain? and not prop.owner? } end |
#set_alternate_key_attributes(*attributes) ⇒ Object (private)
Sets this class’s alternate key attributes to the given attributes. If attributes is set to nil, then the alternate key is cleared.
350 351 352 |
# File 'lib/jinx/metadata/propertied.rb', line 350 def set_alternate_key_attributes(*attributes) attributes.each { |a| add_alternate_key_attribute(a) } end |
#set_attribute_type(attribute, klass) ⇒ Object (private)
Sets the given attribute type to klass. If attribute is defined in a superclass, then klass must be a subclass of the superclass attribute type.
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/jinx/metadata/propertied.rb', line 360 def set_attribute_type(attribute, klass) prop = property(attribute) # degenerate no-op case return if klass == prop.type # If this class is the declarer, then simply set the attribute type. # Otherwise, if the attribute type is unspecified or is a superclass of the given class, # then make a new attribute metadata for this class. if prop.declarer == self then prop.type = klass logger.debug { "Set #{qp}.#{attribute} type to #{klass.qp}." } elsif prop.type.nil? or klass < prop.type then prop.restrict(self, :type => klass) logger.debug { "Restricted #{prop.declarer.qp}.#{attribute}(#{prop.type.qp}) to #{qp} with return type #{klass.qp}." } else raise ArgumentError.new("Cannot reset #{qp}.#{attribute} type #{prop.type.qp} to incompatible #{klass.qp}") end end |
#set_primary_key_attributes(*attributes) ⇒ Object (private)
Sets this class’s primary key attributes to the given attributes. If attributes is set to nil, then the primary key is cleared.
326 327 328 |
# File 'lib/jinx/metadata/propertied.rb', line 326 def set_primary_key_attributes(*attributes) attributes.each { |a| add_primary_key_attribute(a) } end |
#set_secondary_key_attributes(*attributes) ⇒ Object (private)
Sets this class’s secondary key attributes to the given attributes. If attributes is set to nil, then the secondary key is cleared.
338 339 340 |
# File 'lib/jinx/metadata/propertied.rb', line 338 def set_secondary_key_attributes(*attributes) attributes.each { |a| add_secondary_key_attribute(a) } end |
#standard_attribute(name_or_alias) ⇒ Symbol
Returns the standard attribute symbol for the given name or alias.
115 116 117 118 119 120 |
# File 'lib/jinx/metadata/propertied.rb', line 115 def standard_attribute(name_or_alias) if name_or_alias.nil? then raise ArgumentError.new("#{qp} standard attribute call is missing the attribute name/alias parameter") end @alias_std_prop_map[name_or_alias.to_sym] or raise NameError.new("#{self} attribute not found: #{name_or_alias}") end |
#unidirectional_dependent_attributes ⇒ <Symbol>
Returns the unidirectional dependent attributes.
169 170 171 |
# File 'lib/jinx/metadata/propertied.rb', line 169 def unidirectional_dependent_attributes @uni_dep_flt ||= dependent_attributes.compose { |prop| prop.unidirectional? } end |