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

Instance Method Summary collapse

Instance Attribute Details

#attributes<Symbol> (readonly)

Returns this class’s attributes.

Returns:

  • (<Symbol>)

    this class’s attributes



11
12
13
# File 'lib/jinx/metadata/propertied.rb', line 11

def attributes
  @attributes
end

#defaultsHashable (readonly)

Returns the default attribute => value associations.

Returns:

  • (Hashable)

    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.

Parameters:

  • attribute (Symbol)

    the attribute to add

  • type (Class)

    (see Property#initialize)

  • flags (<Symbol>)

    the qualifying #flags

Returns:

  • (Property)

    the attribute meta-data



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)

Deprecated.

Use #alias_attribute instead

Creates the given aliases to attributes.

Parameters:

See Also:

  • #attribute_alias


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)

Parameters:

  • attribute (Symbol)

    the attribute

  • value

    the default value



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)

Parameters:

  • hash (Hash)

    the attribute => value defaults



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)

Parameters:

  • attribute (Symbol)

    the mandatory attribute



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)

Parameters:

  • attributes (<Symbol>)

    the mandatory attributes



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)

Parameters:



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.

Parameters:

  • attribute (Property)

    the restricted attribute



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.

Parameters:

  • aliaz (Symbol)

    the attribute alias

  • attribute (Symbol)

    the attribute to alias



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.

Returns:

  • ({Symbol => Symbol})

    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.

Returns:

  • (<Symbol>)

    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.

Returns:

  • (<Symbol>)

    the alternate key attributes



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.

Parameters:

Returns:



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.

Parameters:

  • attributes (<Symbol>, nil) (defaults to: nil)

    the optional attributes to filter on (default all attributes)

Yields:

  • (prop)

    the optional attribute selector

Yield Parameters:

  • prop (Property)

    the candidate attribute

Returns:

Raises:



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_attributesObject (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.

Parameters:

  • attribute (Symbol)

    the attribute to check

Returns:

  • (Boolean)

    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.

Parameters:

  • attribute (Symbol)

    the attribute to add

  • type (Class)

    (see Property#initialize)

  • flags (<Symbol>)

    the qualifying #flags

Returns:

  • (Property)

    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_attributesObject (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.

Parameters:

  • inc_super (Boolean, nil) (defaults to: true)

    flag indicating whether to include dependents defined in the superclass

Returns:

  • (<Symbol>)

    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.

Parameters:

  • klass (Class)

    the target attribute type

Returns:

  • (Symbol, nil)

    the 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.

Parameters:

  • attribute (Symbol)

    the attribute to check

Returns:

  • (Boolean)

    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.

Returns:

  • (<Symbol>)

    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

Yields:

  • (prop)

    operate on the given property

Yield Parameters:

  • prop (Property)

    the property in this class



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:



153
154
155
# File 'lib/jinx/metadata/propertied.rb', line 153

def independent_attributes
  @ind_flt ||= attribute_filter { |prop| prop.independent? }
end

#init_property_classifiersObject (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.

Returns:

  • (Boolean)

    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.

Returns:

  • (<Symbol>)

    the domain attributes which wrap a java attribute

See Also:



126
127
128
# File 'lib/jinx/metadata/propertied.rb', line 126

def java_attributes
  @java_flt ||= attribute_filter { |prop| prop.java_property? }
end

#mandatory_attributesObject

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_attributeSymbol? (private)

Returns the unique non-self-referential owner attribute, if one exists.

Returns:

  • (Symbol, nil)

    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.

Parameters:

  • klass (Class)

    the target type

  • attributes (AttributeEnumerator, nil) (defaults to: nil)

    the attributes to check (default all domain attributes)

Returns:

  • (Symbol, nil)

    the most specific reference attribute, or nil if none



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.

Parameters:

  • attribute (Symbol)

    the attribute to check

Returns:

  • (Boolean)

    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.

Returns:

  • (<Symbol>)

    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.

Returns:

  • (<Symbol>)

    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_attributesObject



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.

Parameters:

  • hash ({Symbol => Symbol})

    the offset => original method hash

  • offset (Integer, nil) (defaults to: nil)

    the offset amount (default is -1)



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.

Returns:

  • (<Symbol>)

    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.

Parameters:

  • attribute (Symbol)

    the property attribute symbol or alias

Returns:

  • (Property)

    the corresponding property

Raises:

  • (NameError)

    if the attribute is not recognized



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.

Parameters:

Returns:

  • (Boolean)

    whether there is a corresponding attribute



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.

Returns:



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.

Parameters:

  • attributes (<Symbol>)

    an attribute reference path leading from this class

Returns:

  • (<Property>)

    the corresponding property path

Raises:

  • (ArgumentError)

    if there are no attributes or one of the attributes besides the last is not a domain attribute

  • (NameError)

    if the attribute is not recognized



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.

Parameters:

  • attribute (Symbol)

    the attribute to qualify

  • the ({Symbol => Object})

    flags to apply to the restricted attribute



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.

Parameters:

  • aliaz (Symbol)

    the attribute alias

  • attribute (Symbol)

    the attribute to alias

Raises:

  • (ArgumentError)


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.

Returns:

  • (<Symbol>)

    the secondary key attributes



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.

Returns:

  • (<Symbol>)

    # 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.

Parameters:

  • attribute (Symbol)

    the attribute to modify

  • klass (Class)

    the attribute type

Raises:

  • (ArgumentError)

    if the new type is incompatible with the current 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.

Parameters:

  • name_or_alias (Symbol, String)

    the attribute name or alias

Returns:

  • (Symbol)

    the standard attribute symbol for the given name or alias

Raises:

  • (ArgumentError)

    if the attribute name or alias argument is missing

  • (NameError)

    if the attribute is not found



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.

Returns:

  • (<Symbol>)

    the unidirectional dependent attributes

See Also:



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