Class: CaRuby::Database::Reader::TemplateBuilder
- Inherits:
-
Object
- Object
- CaRuby::Database::Reader::TemplateBuilder
- Defined in:
- lib/caruby/database/reader_template_builder.rb
Overview
TemplateBuilder builds a template suitable for a caCORE saarch database operation.
Instance Method Summary collapse
-
#build_template(obj, hash = nil) ⇒ Object
Returns a template for matching the domain object obj and the optional hash values.
Instance Method Details
#build_template(obj, hash = nil) ⇒ Object
Returns a template for matching the domain object obj and the optional hash values. The default hash attributes are the Propertied#searchable_attributes. The template includes only the non-domain attributes of the hash references.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/caruby/database/reader_template_builder.rb', line 22 def build_template(obj, hash=nil) # split the attributes into reference and non-reference attributes. # the new search template object is built from the non-reference attributes. # the reference attributes values are copied and added. logger.debug { "Building search template for #{obj.qp}..." } hash ||= obj.value_hash(obj.class.searchable_attributes) # the searchable attribute => value hash rh, nrh = hash.split { |pa, value| Jinx::Resource === value } # make the search template from the non-reference attributes tmpl = obj.class.new.merge_attributes(nrh) # get references for the search template unless rh.empty? then logger.debug { "Collecting search reference parameters for #{obj.qp} from attributes #{rh.keys.to_series}..." } end rh.each { |pa, ref| add_search_template_reference(tmpl, ref, pa) } tmpl end |