class Guard::Openscad
Attributes
notification_parser[R]
notifier[R]
runner[R]
Public Class Methods
new(watches=[], options = {})
click to toggle source
Calls superclass method
# 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
Public Instance Methods
run_all()
click to toggle source
# File lib/guard/openscad.rb, line 43 def run_all run_on_changes(all_watched_files) end
run_on_changes(paths)
click to toggle source
# 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
start()
click to toggle source
# File lib/guard/openscad.rb, line 39 def start run_all if all_on_start? end
Private Instance Methods
all_on_start?()
click to toggle source
# File lib/guard/openscad.rb, line 116 def all_on_start? @all_on_start end
all_watched_files()
click to toggle source
# File lib/guard/openscad.rb, line 120 def all_watched_files Watcher.match_files(self,Dir.glob('{,**/}*{,.*}').uniq) end
benchmark(message,&block)
click to toggle source
# File lib/guard/openscad.rb, line 104 def benchmark(message,&block) if @benchmark UI.info(message + " " + Benchmark.measure(&block).to_s) else block.call end end
build_runner(options)
click to toggle source
# File lib/guard/openscad.rb, line 69 def build_runner(options) result_parser = options.fetch(:result_parser).new format = options.fetch(:format) runner_class = options.fetch(:runner) runner_class.new(parser: result_parser, format: format) end
notify(notification)
click to toggle source
# File lib/guard/openscad.rb, line 86 def notify(notification) benchmark("Sending Notification") do notifier.notify(notification.message, title: notification.title, image: notification.image, priority: notification.priority) UI.info([notification.title,notification.message].join(' ')) end end
parse_results(result)
click to toggle source
# File lib/guard/openscad.rb, line 96 def parse_results(result) notification = nil benchmark("Parsing Results") do notification = notification_parser.parse(result) end notification end
process(path)
click to toggle source
# File lib/guard/openscad.rb, line 78 def process(path) result = nil benchmark("Processing #{path}") do result = runner.run(path) end result end
run_list(paths)
click to toggle source
# File lib/guard/openscad.rb, line 112 def run_list(paths) Array(paths) end