Class: Librarian::Dsl

Inherits:
Object
  • Object
show all
Defined in:
lib/librarian/dsl.rb,
lib/librarian/dsl/target.rb,
lib/librarian/dsl/receiver.rb

Direct Known Subclasses

Mock::Dsl

Defined Under Namespace

Classes: Error, Receiver, Target

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment) ⇒ Dsl

Returns a new instance of Dsl


66
67
68
# File 'lib/librarian/dsl.rb', line 66

def initialize(environment)
  self.environment = environment
end

Instance Attribute Details

#environmentObject

Returns the value of attribute environment


11
12
13
# File 'lib/librarian/dsl.rb', line 11

def environment
  @environment
end

Class Method Details

.run(environment, specfile = nil, precache_sources = [], &block) ⇒ Object


16
17
18
# File 'lib/librarian/dsl.rb', line 16

def run(environment, specfile = nil, precache_sources = [], &block)
  new(environment).run(specfile, precache_sources, &block)
end

Instance Method Details

#debug_named_source_cache(name, target) ⇒ Object


85
86
87
88
89
90
91
92
93
# File 'lib/librarian/dsl.rb', line 85

def debug_named_source_cache(name, target)
  source_cache = target.source_cache
  debug { "#{name}:" }
  source_cache.each do |key, value|
    type = key[0]
    attributes = key[1...key.size]
    debug { "  #{key.inspect}" }
  end
end

#run(specfile = nil, sources = []) ⇒ Object


70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/librarian/dsl.rb', line 70

def run(specfile = nil, sources = [])
  specfile, sources = nil, specfile if specfile.kind_of?(Array) && sources.empty?

  Target.new(self).tap do |target|
    target.precache_sources(sources)
    debug_named_source_cache("Pre-Cached Sources", target)

    specfile ||= Proc.new if block_given?
    receiver = Receiver.new(target)
    receiver.run(specfile)

    debug_named_source_cache("Post-Cached Sources", target)
  end.to_spec
end