Class: Rubuild::Env::Requirer

Inherits:
Object
  • Object
show all
Defined in:
lib/rubuild/env/requirer.rb

Overview

Rubuild::Env::Requirer Look up a set of provided entries in the environment at once.

Instance Method Summary collapse

Constructor Details

#initialize(env, req_desc) ⇒ Requirer

Returns a new instance of Requirer.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rubuild/env/requirer.rb', line 11

def initialize(env, req_desc)
  self.rubuild_env_requirer__location = 
    Rubuild::Env::Location.new(req_desc.inspect, env.build_factory)

  found_all = env.build_factory.create_dep(
    self.method(:_found_all), self.rubuild_env_requirer__location.name)

  self.location.found_dep.add_parent(found_all)

  case req_desc
  when String
    finding = Rubuild::Env::Location.new(req_desc, env.build_factory)
    env.require(req_desc, finding)
    fill_dep = env.build_factory.create_dep(
      self.method(:_found_only), "fill:#{finding.name}", finding)
    fill_dep.add_parent(finding.found_dep)
    found_all.add_parent(fill_dep)
  when Array
    self.rubuild_env_requirer__found = Array.new(req_desc.size)
    req_desc.each_with_index do |path, index|
      finding = Rubuild::Env::Location.new("#{index}:#{path}", env.build_factory)
      env.require(path, finding)
      fill_dep = env.build_factory.create_dep(
        self.method(:_found_one), "fill:#{finding.name}", index, finding)
      fill_dep.add_parent(finding.found_dep)
      found_all.add_parent(fill_dep)
    end
  when Hash
    self.rubuild_env_requirer__found = Hash.new
    req_desc.each_pair do |key, path|
      finding = Rubuild::Env::Location.new("#{key}:#{path}", env.build_factory)
      env.require(path, finding)
      fill_dep = env.build_factory.create_dep(
        self.method(:_found_one), "fill:#{finding.name}", key, finding)
      fill_dep.add_parent(finding.found_dep)
      found_all.add_parent(fill_dep)
    end
  else
    raise(ArgumentError, "Invalid key type for Rubuild::Env::Requirer.")
  end
end

Instance Method Details

#_found_all(dep) ⇒ Object



59
60
61
62
63
# File 'lib/rubuild/env/requirer.rb', line 59

def _found_all(dep)
  self.location.set_data(self.rubuild_env_requirer__found)
  self.rubuild_env_requirer__env = nil
  self.rubuild_env_requirer__found = nil
end

#_found_one(dep, key, found) ⇒ Object

Rubuild::Env::Requirer#initialize



53
54
55
# File 'lib/rubuild/env/requirer.rb', line 53

def _found_one(dep, key, found)
  self.rubuild_env_requirer__found[key] = found.data
end

#_found_only(dep, found) ⇒ Object



56
57
58
# File 'lib/rubuild/env/requirer.rb', line 56

def _found_only(dep, found)
  self.rubuild_env_requirer__found = found.data
end