Module: Baltix::Actor

Defined in:
lib/baltix/actor.rb

Defined Under Namespace

Modules: Copy, Link, Spec, Touch Classes: InvalidActorKindError, InvalidContextKindForActorError

Constant Summary collapse

AUTOMAP =
{
   Spec: "baltix/actor/spec",
   Link: "baltix/actor/link",
   Touch: "baltix/actor/touch",
   Copy: "baltix/actor/copy",
}

Class Method Summary collapse

Class Method Details

.actorsObject



21
22
23
24
25
26
# File 'lib/baltix/actor.rb', line 21

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

.configObject



32
33
34
# File 'lib/baltix/actor.rb', line 32

def config
   @config ||= ObjectSpace.each_object(Baltix::Configuration).first
end

.for(task, context) ⇒ Object



70
71
72
73
# File 'lib/baltix/actor.rb', line 70

def for task, context
   for!(task, context)
rescue InvalidActorKindError
end

.for!(task, context) ⇒ Object



63
64
65
66
67
68
# File 'lib/baltix/actor.rb', line 63

def for! task, context
   actor = actors[task.to_s] || raise(InvalidActorKindError)
   actor.context_kind == context.class || raise(InvalidContextKindForActorError)

   actor
end

.kindsObject



17
18
19
# File 'lib/baltix/actor.rb', line 17

def kinds
   @kinds ||= AUTOMAP.keys.map(&:to_s).map(&:downcase)
end

.objectize(target) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/baltix/actor.rb', line 51

def objectize target
   target.source.trees do |kind, h|
      h.map do |dir, files|
         files.map do |file|
            procline(file) do |actor, context_in|
               YAML.load(context_in.result(binding))
            end
         end
      end
   end.flatten
end

.procline(file) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/baltix/actor.rb', line 36

def procline file
   scheme.map.with_index do |rule, index|
      match = rule['match']

      if !match || /#{match}$/ =~ file
         rule['proc'].map do |data|
            # TODO cache it by match or index
            context_in = ERB.new(data['context'].to_yaml)
            c = yield(data['actor'], context_in)
            c.merge('$' => actors[data['actor']])
         end
      end
   end.compact
end

.schemeObject



28
29
30
# File 'lib/baltix/actor.rb', line 28

def scheme
   @scheme ||= YAML.load(IO.read(File.join(File.dirname(__FILE__), "scheme.erb.yaml")))
end