Module: Baltix::Spec

Defined in:
lib/baltix/spec.rb

Defined Under Namespace

Classes: InvalidSpaceError, InvalidSpecKindError, Rpm, UndetectedSpecSourceError

Constant Summary collapse

AUTOMAP =
%w(Rpm).reduce({}) do |types, name|
   autoload(:"#{name}", File.dirname(__FILE__) + "/spec/#{name.downcase}")
   types.merge(name.to_sym => "Baltix/Spec/#{name}".downcase)
end

Class Method Summary collapse

Class Method Details

.find(spec_kind) ⇒ Object



24
25
26
# File 'lib/baltix/spec.rb', line 24

def find spec_kind
   specs[spec_kind.to_s] || raise(InvalidSpecKindError.new(spec_kind: spec_kind))
end

.kindsObject



13
14
15
# File 'lib/baltix/spec.rb', line 13

def kinds
   specs.keys
end

.load_from(source: raise, options: {}, space: raise(InvalidSpaceError.new)) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/baltix/spec.rb', line 28

def load_from source: raise, options: {}, space: raise(InvalidSpaceError.new)
   source_pre = 
      case source
      when IO, StringIO
         source.readlines.join("")
      when String
         source
      else
         source.to_s
      end

   spec = specs.values.find { |spec| spec.match?(source_pre) }

   if spec
      spec.parse(source_pre, options, space)
   else
      raise(UndetectedSpecSourceError.new(source: source))
   end
end

.specsObject



17
18
19
20
21
22
# File 'lib/baltix/spec.rb', line 17

def specs
   @specs ||= AUTOMAP.keys.map do |const|
      require(AUTOMAP[const])
      [ const.to_s.downcase, const_get(const) ]
   end.to_h
end