Class: RDF::SAK::Transform::Harness
- Inherits:
-
Object
- Object
- RDF::SAK::Transform::Harness
- Defined in:
- lib/rdf/sak/transform.rb
Overview
This class is the main harness for holding all the transforms and operating over them. This is the primary interface through which we manipulate transforms.
Instance Attribute Summary collapse
-
#partials ⇒ Object
readonly
Returns the value of attribute partials.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
-
.load(repo, root) ⇒ RDF::SAK::Transform::Harness
Bootstrap all the transforms.
Instance Method Summary collapse
-
#application_matches?(subject, transform: nil, params: {}, partial: nil) ⇒ true, false
Returns true if the Application with the given subject URI matches either the transform-params pair, or a partial.
-
#initialize(repo, root) ⇒ Harness
constructor
Create a new harness instance.
-
#load ⇒ Array
Load transforms into an existing instance.
-
#resolve(subject) ⇒ RDF::SAK::Transform
Resolve a Transform based on its URI.
-
#resolve_application(subject: nil, transform: nil, params: {}, partial: nil, input: nil, output: nil) ⇒ RDF::SAK::Transform::Application
Resolve a total function application record based on either its subject URI, a transform-params pair, or a Partial.
-
#resolve_partial(subject: nil, transform: nil, params: nil) ⇒ RDF::SAK::Transform::Partial
Resolve a Partial based on either its subject URI or the transform-params pair.
-
#transforms ⇒ Array
Return all cached Transform identities.
Constructor Details
#initialize(repo, root) ⇒ Harness
Create a new harness instance.
510 511 512 513 514 515 516 517 518 519 520 |
# File 'lib/rdf/sak/transform.rb', line 510 def initialize repo, root raise ArgumentError, "repo is #{repo.class}, not an RDF::Repository" unless repo.is_a? RDF::Repository @repo = repo @root = Pathname(root). raise ArgumentError, "Root #{@root} does not exist" unless @root.directory? and @root.readable? @cache = {} @partials = RDF::SAK::Transform::PartialCache.new self end |
Instance Attribute Details
#partials ⇒ Object (readonly)
Returns the value of attribute partials.
503 504 505 |
# File 'lib/rdf/sak/transform.rb', line 503 def partials @partials end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
503 504 505 |
# File 'lib/rdf/sak/transform.rb', line 503 def repo @repo end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
503 504 505 |
# File 'lib/rdf/sak/transform.rb', line 503 def root @root end |
Class Method Details
.load(repo, root) ⇒ RDF::SAK::Transform::Harness
Bootstrap all the transforms.
527 528 529 |
# File 'lib/rdf/sak/transform.rb', line 527 def self.load repo, root self.new(repo, root).load end |
Instance Method Details
#application_matches?(subject, transform: nil, params: {}, partial: nil) ⇒ true, false
Returns true if the Application with the given subject URI matches either the transform-params pair, or a partial.
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
# File 'lib/rdf/sak/transform.rb', line 602 def application_matches? subject, transform: nil, params: {}, partial: nil # unbundle the params; partial overrides transform+params if partial partial = resolve_partial partial unless partial.is_a? RDF::SAK::Transform::Partial transform = partial.transform params = partial.params else transform = resolve transform unless transform.is_a? RDF::SAK::Transform params = transform.validate params end if subject.is_a? RDF::SAK::Transform::Application return true if partial and subject.completes? partial return true if subject.transform == transform and subject.matches? params else # this should say, try matching the partial if there is one # to match, otherwise attempt to directly match the transform return true if partial and repo.has_statement?( RDF::Statement(subject, RDF::SAK::TFO.completes, partial.subject)) if repo.has_statement?( RDF::Statement(subject, RDF::SAK::TFO.transform, transform.subject)) testp = transform.keys.map do |p| o = repo.query([subject, p, nil]).objects.uniq.sort o.empty? ? nil : [p, o] end.compact.to_h # this will clear any explicit declarations of defaults testp = transform.validate testp, defaults: false, silent: true # true means it matches return testp == params end end false end |
#load ⇒ Array
Load transforms into an existing instance
533 534 535 536 537 538 539 540 541 |
# File 'lib/rdf/sak/transform.rb', line 533 def load RDF::SAK::Util.subjects_for(@repo, RDF.type, RDF::SAK::TFO.Transform, only: :resource).each do |subject| resolve subject end # return self so we can daisy-chain self end |
#resolve(subject) ⇒ RDF::SAK::Transform
Resolve a Transform based on its URI.
556 557 558 559 560 561 562 |
# File 'lib/rdf/sak/transform.rb', line 556 def resolve subject return @cache[subject] if @cache[subject] # XXX raise??? transform = RDF::SAK::Transform.resolve(self, subject) or return @cache[subject] = transform end |
#resolve_application(subject: nil, transform: nil, params: {}, partial: nil, input: nil, output: nil) ⇒ RDF::SAK::Transform::Application
Resolve a total function application record based on either its subject URI, a transform-params pair, or a Partial.
585 586 587 588 589 590 |
# File 'lib/rdf/sak/transform.rb', line 585 def resolve_application subject: nil, transform: nil, params: {}, partial: nil, input: nil, output: nil RDF::SAK::Transform::Application.resolve self, subject: subject, transform: transform, params: params, partial: partial, input: input, output: output end |
#resolve_partial(subject: nil, transform: nil, params: nil) ⇒ RDF::SAK::Transform::Partial
Resolve a Partial based on either its subject URI or the transform-params pair.
572 573 574 |
# File 'lib/rdf/sak/transform.rb', line 572 def resolve_partial subject: nil, transform: nil, params: nil partials.resolve subject: subject, transform: transform, params: params end |
#transforms ⇒ Array
Return all cached Transform identities.
547 548 549 |
# File 'lib/rdf/sak/transform.rb', line 547 def transforms @cache.keys.sort end |