Class: Mayday::ScriptGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/mayday/script_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScriptGenerator

Returns a new instance of ScriptGenerator.



11
12
13
# File 'lib/mayday/script_generator.rb', line 11

def initialize
  self.flags = []
end

Instance Attribute Details

#flagsObject

Returns the value of attribute flags.



9
10
11
# File 'lib/mayday/script_generator.rb', line 9

def flags
  @flags
end

Instance Method Details

#to_ruby(opts = {}) ⇒ Object



15
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
# File 'lib/mayday/script_generator.rb', line 15

def to_ruby(opts={})
  opts[:exit_after] = true if opts[:exit_after] == nil;
  opts[:output] = true if opts[:output] == nil;

  function_defs = flags.map(&:function_def_string).join
  exit_chunk = if opts[:exit_after]
    "if \#{any_errors_variable_name}\n  exit(1)\nelse\n  exit\nend\n      CODE\n  else\n    \"\"\n  end\n\n  call_flag_functions_chunk = call_flag_functions_string(\"file\", opts[:output])\n\n# Return the final code blob\n\n  <<-CODE\n# encoding: utf-8\nEncoding.default_external = \"utf-8\"\n\n\#{function_defs}\n\nDir[ENV[\"SRCROOT\"] + \"/**/*.{m,h,swift}\"].each do |filename|\n  # Could be a dir with .m, like Underscore.m's dir\n  if (File.file?(filename))\nfile = File.open(filename, 'r')\n\#{call_flag_functions_chunk}\n  end\nend\n\n\#{exit_chunk}\n    CODE\nend\n"