Class: DynamicFinderProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/active_rdf/objectmanager/resource.rb

Overview

proxy to manage find_by_ invocations

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(find_string, where, *args) ⇒ DynamicFinderProxy

construct proxy from find_by text foaf::name



517
518
519
520
# File 'lib/active_rdf/objectmanager/resource.rb', line 517

def initialize(find_string, where, *args)
  @where = where || []
  parse_attributes(find_string, *args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/active_rdf/objectmanager/resource.rb', line 522

def method_missing(method, *args)
  # we store the ns:name for later (we need to wait until we have the 
  # arguments before actually constructing the where clause): now we just 
  # store that a where clause should appear about foaf:name

  # if this method is called name_and_foaf::age we add ourself to the query
  # otherwise, the query is built: we execute it and return the results
  if method.to_s.include?('_and_')
    parse_attributes(method.to_s, *args)
  else
    @where << Namespace.lookup(@ns, method.to_s)
    query(*args)
  end
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



512
513
514
# File 'lib/active_rdf/objectmanager/resource.rb', line 512

def value
  @value
end