module ActiveTriples::Properties::ClassMethods

Class methods for classes with ‘Properties`

Public Instance Methods

config_for_term_or_uri(term) click to toggle source

Given a property name or a predicate, return the configuration for the matching property.

@param [#to_sym, RDF::Resource] term property name or predicate

@return [ActiveTriples::NodeConfig] the configuration for the property

# File lib/active_triples/properties.rb, line 155
def config_for_term_or_uri(term)
  return properties[term.to_s] unless
    term.is_a?(RDF::Resource) && !term.is_a?(RDFSource)
  properties.each_value { |v| return v if v.predicate == term.to_uri }
end
fields() click to toggle source

List the property names registered to the class.

@return [Array<Symbol>] list of the symbolized names of registered

properties
# File lib/active_triples/properties.rb, line 166
def fields
  properties.keys.map(&:to_sym)
end
generated_property_methods() click to toggle source

Gives existing generated property methods. If the property methods are not yet present, generates them as a new Module and includes it.

@return [Module] a module self::GeneratedPropertyMethods which is

included in self and defines the property methods

@note use the alias initialize_generated_modules for clarity of intent

where appropriate

@see initialize_generated_modules

# File lib/active_triples/properties.rb, line 111
def generated_property_methods
  @generated_property_methods ||= begin
    mod = const_set(:GeneratedPropertyMethods, Module.new)
    include mod
    mod
  end
end
initialize_generated_modules() click to toggle source

If the property methods are not yet present, generates them.

@return [Module] a module self::GeneratedPropertyMethods which is

included in self and defines the property methods

@note this is an alias to generated_property_methods. Use it when you

intend to initialize, rather than retrieve, the methods for code
readability

@see generated_property_methods

# File lib/active_triples/properties.rb, line 97
def initialize_generated_modules
  generated_property_methods
end
property(name, opts={}, &block) click to toggle source

Registers properties for Resource-like classes

@param [Symbol] name of the property (and its accessor methods) @param [Hash] opts for this property, must include a :predicate @yield [index] index sets solr behaviors for the property

@return [Hash{String=>ActiveTriples::NodeConfig}] the full current

property configuration for the class
# File lib/active_triples/properties.rb, line 128
def property(name, opts={}, &block)
  raise ArgumentError, "#{name} is a keyword and not an acceptable property name." if protected_property_name?(name.to_sym)
  reflection = PropertyBuilder.build(self, name, opts, &block)
  Reflection.add_reflection self, name, reflection
end
protected_property_name?(name) click to toggle source

Checks potential property names for conflicts with existing class instance methods. We avoid setting properties with these names to prevent catastrophic method overwriting.

@param [Symblol] name A potential property name. @return [Boolean] true if the given name matches an existing instance

method which is not an ActiveTriples property.
# File lib/active_triples/properties.rb, line 142
def protected_property_name?(name)
  return false if fields.include?(name)
  return true if instance_methods.include?(name) || instance_methods.include?("#{name}=".to_sym)
  false
end