lib/active_triples/properties.rb in active-triples-0.3.0 vs lib/active_triples/properties.rb in active-triples-0.3.1

- old
+ new

@@ -15,10 +15,22 @@ included do initialize_generated_modules end + ## + # 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 + def property(name, opts={}, &block) + self.config[name] = NodeConfig.new(name, opts[:predicate], opts.except(:predicate)).tap do |config| + config.with_index(&block) if block_given? + end + register_property(name) + end + module ClassMethods def inherited(child_class) #:nodoc: child_class.initialize_generated_modules super end @@ -51,11 +63,11 @@ # # @param term [#to_sym, RDF::Resource] a property name to predicate # # @return [ActiveTriples::NodeConfig] def config_for_term_or_uri(term) - return config[term.to_sym] unless term.kind_of? RDF::Resource - config.each_value { |v| return v if v.predicate == term.to_uri } + return properties[term.to_s] unless term.kind_of? RDF::Resource + properties.each_value { |v| return v if v.predicate == term.to_uri } end ## # List the property names registered to the class. #