class Mayday::ScriptGenerator
Attributes
flags[RW]
libs_to_require[RW]
Public Class Methods
new()
click to toggle source
# File lib/mayday/script_generator.rb, line 11 def initialize self.flags = [] self.libs_to_require = [] end
Public Instance Methods
to_ruby(opts={})
click to toggle source
# File lib/mayday/script_generator.rb, line 16 def to_ruby(opts={}) opts[:exit_after] = true if opts[:exit_after] == nil; opts[:output] = true if opts[:output] == nil; require_lines = libs_to_require.map { |lib_to_require| "require '#{lib_to_require}'" }.join("\n") function_defs = flags.map(&:function_def_string).join exit_chunk = if opts[:exit_after] <<-CODE if #{any_errors_variable_name} exit(1) else exit end CODE else "" end call_flag_functions_chunk = call_flag_functions_string("file", opts[:output]) # Return the final code blob <<-CODE Encoding.default_external = "utf-8" #{require_lines} #{function_defs} Dir[ENV["SRCROOT"] + "/**/*.{m,h,swift}"].each do |filename| # Could be a dir with .m, like Underscore.m's dir if (File.file?(filename)) file = File.open(filename, 'r') #{call_flag_functions_chunk} end end #{exit_chunk} CODE end
Private Instance Methods
any_errors_variable_name()
click to toggle source
# File lib/mayday/script_generator.rb, line 72 def any_errors_variable_name "@any_errors" end
call_flag_functions_string(file_var_name, output)
click to toggle source
# File lib/mayday/script_generator.rb, line 58 def call_flag_functions_string(file_var_name, output) "file_contents = file.read\n" + flags.map do |flag| any_errors_line = flag.class == Mayday::Error ? "#{any_errors_variable_name} = true" : "" <<-CODE abstract_flag_output = #{flag.function_name}(#{file_var_name}.path, file_contents) if abstract_flag_output && #{output} puts abstract_flag_output #{any_errors_line} end CODE end.join("\n") end