Class: Mayday::ScriptGenerator
- Inherits:
-
Object
- Object
- Mayday::ScriptGenerator
- Defined in:
- lib/mayday/script_generator.rb
Instance Attribute Summary collapse
-
#flags ⇒ Object
Returns the value of attribute flags.
-
#libs_to_require ⇒ Object
Returns the value of attribute libs_to_require.
Instance Method Summary collapse
-
#initialize ⇒ ScriptGenerator
constructor
A new instance of ScriptGenerator.
- #to_ruby(opts = {}) ⇒ Object
Constructor Details
#initialize ⇒ ScriptGenerator
Returns a new instance of ScriptGenerator.
11 12 13 14 |
# File 'lib/mayday/script_generator.rb', line 11 def initialize self.flags = [] self.libs_to_require = [] end |
Instance Attribute Details
#flags ⇒ Object
Returns the value of attribute flags.
9 10 11 |
# File 'lib/mayday/script_generator.rb', line 9 def flags @flags end |
#libs_to_require ⇒ Object
Returns the value of attribute libs_to_require.
9 10 11 |
# File 'lib/mayday/script_generator.rb', line 9 def libs_to_require @libs_to_require end |
Instance Method Details
#to_ruby(opts = {}) ⇒ Object
16 17 18 19 20 21 22 23 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 56 |
# 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: utf-8 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 |