lib/herdic/client.rb in herdic-1.0.1 vs lib/herdic/client.rb in herdic-1.0.2
- old
+ new
@@ -1,7 +1,8 @@
require 'active_support/core_ext'
require 'erb'
+require 'fileutils'
require 'json'
require 'net/http'
require 'open-uri'
require 'optparse'
require 'psych'
@@ -14,20 +15,20 @@
attr_reader :registry, :config
def initialize(file, options)
@file, @options = file, options
- @config_file = @options['c'] || Util.find_files_upward(Herdic.config_filename, Herdic.pwd, 1)[0]
@context = binding
- @store = Store.new @config_file
- @registry = @store.data
+ @config_file = @options['c'] || Util.find_files_upward(Herdic.config_filename, Herdic.pwd, 1)[0]
+ load_config @config_file if @config_file
@printer = Printer.new @options
+ @printer.start_message @config_file
- load_config @config_file if @config_file
- load_yaml
+ @store = Store.new @config_file
+ @registry = @store.data
end
def load_config(file)
@config = {}
@@ -36,27 +37,18 @@
end
@config = Psych.load @config
end
- def load_yaml
- @specs = Loader.new(@file).specs
-
+ def run_all
if @options['e']
- File.open(Herdic.edit_request_file, 'w+') do |f|
- f.write Psych.dump(@specs)
- end
-
+ FileUtils.cp @file, Herdic.edit_request_file
system "$EDITOR '%s'" % Herdic.edit_request_file
- File.open(Herdic.edit_request_file, 'r') do |f|
- @specs = Psych.load f.read
- end
+ @specs = Loader.new Herdic.edit_request_file, @file
+ else
+ @specs = Loader.new @file
end
- end
-
- def run_all
- @printer.start_message @specs
@specs.each do |spec|
# FIXME: figure out better way
spec = Psych.dump spec
spec = ERB.new(spec).result @context