Class: DevSystem::GeneratorPanel

Inherits:
Liza::Panel show all
Defined in:
lib/dev_system/sub/generator/generator_panel.rb

Defined Under Namespace

Classes: Error, NotFoundError

Instance Attribute Summary

Attributes inherited from Liza::Panel

#key

Instance Method Summary collapse

Methods inherited from Liza::Panel

box, #box, color, #controller, controller, division, #division, #initialize, #push, #short, #started, subsystem, #subsystem, token

Methods inherited from Liza::Unit

const_missing, division, part, system, #system, test_class

Constructor Details

This class inherits a constructor from Liza::Panel

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/dev_system/sub/generator/generator_panel.rb', line 7

def call env
  log :low, "env.count is #{env.count}"
  parse env
  find env
  forward env
  inform env
  save env
rescue Exception => e
  rescue_from_panel(e, with: env)
end

#find(env) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dev_system/sub/generator/generator_panel.rb', line 38

def find env
  if log_level? :low
    puts
    log "env.count is #{env.count}"
  end
  begin
    k = Liza.const "#{env[:generator_name]}_generator"
    log :lower, k
    env[:generator_class] = k
  rescue Liza::ConstNotFound
    raise NotFoundError, "generator #{env[:generator_name].inspect} not found"
  end
end

#forward(env) ⇒ Object



54
55
56
57
58
59
# File 'lib/dev_system/sub/generator/generator_panel.rb', line 54

def forward env
  generator_class = env[:generator_class]

  return forward_base_generator env if generator_class < BaseGenerator
  return forward_generator env if generator_class < Generator
end

#forward_base_generator(env) ⇒ Object



61
62
63
64
65
# File 'lib/dev_system/sub/generator/generator_panel.rb', line 61

def forward_base_generator env
  log :lower,  "forwarding"
  env[:args].shift
  env[:generator_class].call env
end

#forward_generator(env) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/dev_system/sub/generator/generator_panel.rb', line 67

def forward_generator env
  method_name = env[:generator_coil]
  method_name = :call if method_name == :default

  args = env[:args][1..-1]
  log :lower,  "#{env[:generator_class]}.#{method_name}(#{args})"
  env[:generator_class].public_send method_name, args
end

#inform(env) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/dev_system/sub/generator/generator_panel.rb', line 78

def inform env
  if log_level? :low
    puts
    log "env.count is #{env.count}"
  end
  env[:generator] or return log :lower, "not implemented"
  env[:generator].inform
end

#parse(env) ⇒ Object

Raises:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dev_system/sub/generator/generator_panel.rb', line 20

def parse env
  if log_level? :low
    puts
    log "env.count is #{env.count}"
  end
  raise NotFoundError, "generator not found" if env[:args].none?

  generator_name, generator_coil = env[:args].first.split(":").map(&:to_sym)

  env[:generator_name_original] = generator_name
  env[:generator_name] = short(generator_name).to_sym
  env[:generator_coil_original] = generator_coil
  env[:generator_coil] = generator_coil
  log :higher, "generator:coil is #{env[:generator_name]}:#{env[:generator_coil]}"
end

#save(env) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/dev_system/sub/generator/generator_panel.rb', line 89

def save env
  if log_level? :low
    puts
    log "env.count is #{env.count}"
  end
  env[:generator] or return log :lower, "not implemented"
  env[:generator].save
end