Class: Jstyler::Beautify::BeautifyRunner
- Inherits:
-
Object
- Object
- Jstyler::Beautify::BeautifyRunner
- Includes:
- Jstyler
- Defined in:
- lib/jstyler/beautify.rb
Constant Summary
Constants included from Jstyler
FORMATTER_LIB, GEM_DIRECTORY, JAVA_LIBS, VERSION
Instance Method Summary collapse
- #flatten_options(options = {}) ⇒ Object
- #flatten_sources(srcs = []) ⇒ Object
-
#initialize ⇒ BeautifyRunner
constructor
A new instance of BeautifyRunner.
-
#run(config_options, *srcs) ⇒ Object
:call-seq: run = config_file, src/ src2 run = hash, src (hash - {:config=>config_file, :verbose=>true }).
Constructor Details
#initialize ⇒ BeautifyRunner
Returns a new instance of BeautifyRunner.
16 17 18 19 |
# File 'lib/jstyler/beautify.rb', line 16 def initialize @conventions = ['java', 'eclipse'] @allowed_options = ['config', 'convention', 'verbose'] end |
Instance Method Details
#flatten_options(options = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/jstyler/beautify.rb', line 57 def ( = {}) = '' .each {|key,val| val = File. val if key.to_s.include? 'config' += " -#{key} #{val}" } end |
#flatten_sources(srcs = []) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/jstyler/beautify.rb', line 67 def flatten_sources(srcs = []) src_string = '' srcs.uniq.flatten.each {|src| src_string += " " + File.(src)} src_string end |
#run(config_options, *srcs) ⇒ Object
:call-seq:
run = config_file, src/ src2
run = hash, src (hash - {:config=>config_file, :verbose=>true })
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/jstyler/beautify.rb', line 24 def run(, *srcs) @options = { :config=> } unless Hash === @options = if @options == nil current_dir = Dir.pwd #validation result = validate_config_path @options result = validate_source_directory srcs if result result = validate_env if result #prepare call execution_string = '' if result execution_string = flatten_sources srcs execution_string = (@options) + execution_string Dir.chdir(JAVA_LIBS) java = File. ENV['JAVA_HOME']+'/bin/java' cmd = "#{java} -jar #{FORMATTER_LIB} #{execution_string} " shell = Session::Shell.new stdout, stderr = shell.execute cmd status = shell.status puts stdout puts stderr if !status #change directory to previous one Dir.chdir(current_dir) result = execution_string end result end |