Class: Guard::Openscad

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/openscad.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(watches = [], options = {}) ⇒ Openscad

Returns a new instance of Openscad.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/guard/openscad.rb', line 14

def initialize(watches=[], options = {})
  super

  net_options = {all_on_start: true,
                 benchmark: false,

                 runner: Scad4r::Runner,
                 result_parser: Scad4r::ResultParser,
                 format: :stl,

                 notifier: Notifier,
                 notification_parser: Scad4r::Notification}.merge(options)

  # Behaviour options
  @all_on_start        = net_options.fetch(:all_on_start)
  @benchmark           = net_options.fetch(:benchmark)

  @runner              = build_runner(net_options)

  @notifier            = net_options.fetch(:notifier)
  @notification_parser = net_options.fetch(:notification_parser)

  @failed              = false
end

Instance Attribute Details

#runnerObject (readonly)

Returns the value of attribute runner.



13
14
15
# File 'lib/guard/openscad.rb', line 13

def runner
  @runner
end

Instance Method Details

#run_allObject



43
44
45
# File 'lib/guard/openscad.rb', line 43

def run_all
  run_on_changes(all_watched_files)
end

#run_on_changes(paths) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/guard/openscad.rb', line 47

def run_on_changes(paths)
  failed = false

  run_list(paths).each do |path|
    result = process(path)

    if result.has_key?(:error) || result.has_key?(:warning)
      failed = true
    end

    notifications = parse_results(result)
    notifications.each { |notification| notify(notification) }
  end

  if failed
    throw :task_has_failed
  end
end

#startObject



39
40
41
# File 'lib/guard/openscad.rb', line 39

def start
  run_all if all_on_start?
end