lib/standup/scripts/base.rb in standup-0.6.8 vs lib/standup/scripts/base.rb in standup-0.6.9
- old
+ new
@@ -5,62 +5,62 @@
class Base
def initialize *args
merge_params self.class.default_params
merge_params Settings[name]
end
-
+
class_attribute :name
-
+
class_attribute :default_params
self.default_params = {}
-
+
class_attribute :description
-
+
attr_accessor :params
-
+
def name
self.class.name
end
-
+
def put_title
bright_p name, HighLine::CYAN
end
-
+
def script_file filename
- [Standup.local_scripts_path, Standup.gem_scripts_path].each do |dir|
+ [Standup.local_scripts_path, Standup.conf_scripts_path, Standup.gem_scripts_path].compact.each do |dir|
next unless dir
path = File.expand_path("#{name}/#{filename}", dir)
return path if File.exists? path
end
nil
end
-
+
def with_processed_file filename
Dir.mktmpdir do |dir|
erb = ERB.new File.read(filename)
erb.filename = filename
result = erb.result get_binding
- tmp_filename = File.expand_path File.basename(filename), dir
+ tmp_filename = File.expand_path File.basename(filename), dir
File.open(tmp_filename, 'w') {|f| f.write result}
yield tmp_filename
end
end
-
+
def self.execute
new.run
end
-
+
protected
-
+
def merge_params param_overrides
@params = if param_overrides.is_a? Hash
ActiveSupport::HashWithIndifferentAccess.new((@params || {}).merge(param_overrides))
else
param_overrides || @params
end
end
-
+
def argument arg_pattern, arg_name = arg_pattern, variants = nil
self.class.argument arg_pattern, arg_name, variants
end
def self.argument arg_pattern, arg_name = arg_pattern, variants = nil
@@ -87,17 +87,17 @@
end
Trollop::with_standard_exception_handling opt_parser do
opt_parser.parse ARGV
raise Trollop::HelpNeeded if ARGV.empty?
end
-
+
result = ARGV.shift
if variants && !variants.include?(result)
opt_parser.die "unknown #{arg_name} #{result}", nil
end
result
end
-
+
def get_binding
binding
end
end
end
\ No newline at end of file