Class: Appfuel::Repository::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/appfuel/storage/repository/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace, criteria_class) ⇒ Runner

The call relies on the fact that we can build a criteria find the correct repo and call the exists? interface on that repo. The identity of any given repo requires its namespace + its class name.

Parameters:

  • namespace (String)

    fully qualified namespace string fro repos

  • criteria_class (Class)

    class used to represent the criteria



15
16
17
18
# File 'lib/appfuel/storage/repository/runner.rb', line 15

def initialize(namespace, criteria_class)
  @repo_namespace = namespace
  @criteria_class = criteria_class
end

Instance Attribute Details

#criteria_classObject (readonly)

Returns the value of attribute criteria_class.



6
7
8
# File 'lib/appfuel/storage/repository/runner.rb', line 6

def criteria_class
  @criteria_class
end

#repo_namespaceObject (readonly)

Returns the value of attribute repo_namespace.



6
7
8
# File 'lib/appfuel/storage/repository/runner.rb', line 6

def repo_namespace
  @repo_namespace
end

Instance Method Details

#create_criteria(entity_key, opts = {}) ⇒ Object



20
21
22
# File 'lib/appfuel/storage/repository/runner.rb', line 20

def create_criteria(entity_key, opts = {})
  criteria_class.new(entity_key, opts)
end

#exists?(entity_key, opts = {}) ⇒ Bool

Parameters:

  • entity_key (String)

    the type identifier for an entity

  • opts (Hash) (defaults to: {})

    one attr => value pair is required repo => name is optional

Returns:

  • (Bool)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/appfuel/storage/repository/runner.rb', line 33

def exists?(entity_key, opts = {})
  fail "opts must be a hash" unless opts.is_a?(Hash)

  criteria_opts = {}
  if opts.key?(:repo)
    criteria_opts[:repo] = opts.delete(:repo)
  end
  fail "opts hash must have one attr => value pair" if opts.empty?

  property, value = opts.first
  criteria = create_criteria(entity_key, criteria_opts)
  criteria.exists(property, value)

  load_repo(criteria).exists?(criteria)
end

#query(criteria) ⇒ Object



24
25
26
# File 'lib/appfuel/storage/repository/runner.rb', line 24

def query(criteria)
  load_repo(criteria).query(criteria)
end