Module: ActiveTriples::Properties::ClassMethods
- Defined in:
- lib/active_triples/properties.rb
Overview
Class methods for classes with ‘Properties`
Instance Method Summary collapse
-
#config_for_term_or_uri(term) ⇒ ActiveTriples::NodeConfig
Given a property name or a predicate, return the configuration for the matching property.
-
#fields ⇒ Array<Symbol>
List the property names registered to the class.
-
#generated_property_methods ⇒ Module
Gives existing generated property methods.
-
#inherited(child_class) ⇒ Object
:nodoc:.
-
#initialize_generated_modules ⇒ Module
If the property methods are not yet present, generates them.
-
#property(name, opts = {}) {|index| ... } ⇒ Hash{String=>ActiveTriples::NodeConfig}
Registers properties for Resource-like classes.
-
#protected_property_name?(name) ⇒ Boolean
Checks potential property names for conflicts with existing class instance methods.
Instance Method Details
#config_for_term_or_uri(term) ⇒ ActiveTriples::NodeConfig
Given a property name or a predicate, return the configuration for the matching property.
155 156 157 158 159 |
# 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 ⇒ Array<Symbol>
List the property names registered to the class.
166 167 168 |
# File 'lib/active_triples/properties.rb', line 166 def fields properties.keys.map(&:to_sym) end |
#generated_property_methods ⇒ Module
use the alias #initialize_generated_modules for clarity of intent where appropriate
Gives existing generated property methods. If the property methods are not yet present, generates them as a new Module and includes it.
111 112 113 114 115 116 117 |
# 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 |
#inherited(child_class) ⇒ Object
:nodoc:
82 83 84 85 |
# File 'lib/active_triples/properties.rb', line 82 def inherited(child_class) #:nodoc: child_class.initialize_generated_modules super end |
#initialize_generated_modules ⇒ Module
this is an alias to #generated_property_methods. Use it when you intend to initialize, rather than retrieve, the methods for code readability
If the property methods are not yet present, generates them.
97 98 99 |
# File 'lib/active_triples/properties.rb', line 97 def initialize_generated_modules generated_property_methods end |
#property(name, opts = {}) {|index| ... } ⇒ Hash{String=>ActiveTriples::NodeConfig}
Registers properties for Resource-like classes
128 129 130 131 132 |
# 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 reflection = PropertyBuilder.build(self, name, opts, &block) Reflection.add_reflection self, name, reflection end |
#protected_property_name?(name) ⇒ Boolean
Checks potential property names for conflicts with existing class instance methods. We avoid setting properties with these names to prevent catastrophic method overwriting.
142 143 144 145 146 |
# File 'lib/active_triples/properties.rb', line 142 def protected_property_name?(name) reject = self.instance_methods.map! { |s| s.to_s.gsub(/=$/, '').to_sym } reject -= properties.keys.map { |k| k.to_sym } reject.include? name end |