Class: Orchid::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/orchid/compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCompiler

Returns a new instance of Compiler.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/orchid/compiler.rb', line 83

def initialize()
  Orchid::INFO[:compiler_opts].each do |opt|
     opt[:name].each do |name|
      name = opt[:multiple] ? name.pluralize.as_iv : name.as_iv
      
      self.instance_variable_set name, nil
      self.instance_variable_set name, false if opt[:bool]
      self.instance_variable_set name, [] if opt[:multiple]
    end
  end
  
  @symbols_file = nil
  @disable_warnings = false
  @save_temps = false
  
  @sources = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &blk) ⇒ Object

Raises:

  • (NoMethodError)


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/orchid/compiler.rb', line 101

def method_missing(method, *args, &blk)
  method = method.to_s.scan(/^(\w+)(=)?/i).flatten    
  option = self.get_option(method.first.as_opt)
  
  if option
    value = *args.first
    value = value.to_a.flatten.uniq if option[:multiple]
    value = value ? true : false if option[:bool]
    
    if method.last
      name = option[:name] - (method.first.as_opt.to_a & option[:name])
      name = name.first
      name = name.pluralize if option[:multiple]
      
      self.instance_variable_set(method.first.as_iv, value)
      self.instance_variable_set(name.as_iv, value) if name
      
      return value
    else
      return self.instance_variable_get(method.first.as_iv)
    end
  end
  
  raise NoMethodError.new("undefined method `#{method * ''}' for #{self}", (method * ''), args)
end

Instance Attribute Details

#disable_warningsObject

Returns the value of attribute disable_warnings.



73
74
75
# File 'lib/orchid/compiler.rb', line 73

def disable_warnings
  @disable_warnings
end

#save_tempsObject

Returns the value of attribute save_temps.



73
74
75
# File 'lib/orchid/compiler.rb', line 73

def save_temps
  @save_temps
end

#sourcesObject

Returns the value of attribute sources.



73
74
75
# File 'lib/orchid/compiler.rb', line 73

def sources
  @sources
end

#symbols_fileObject

Returns the value of attribute symbols_file.



73
74
75
# File 'lib/orchid/compiler.rb', line 73

def symbols_file
  @symbols_file
end

Instance Method Details

#get_option(optname) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/orchid/compiler.rb', line 75

def get_option(optname)
  Orchid::INFO[:compiler_opts].each do |opt|
    return opt if opt[:name].member? optname
  end
  
  return nil
end

#parametersObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/orchid/compiler.rb', line 127

def parameters
  params = []
  
  Orchid::INFO[:compiler_opts].each do |option|
    iv = option[:multiple] ? option[:name].last.pluralize.as_iv : option[:name].last.as_iv
    
    value = [self.instance_variable_get(iv)].flatten
    
    value.each do |val|
      if [true, false].member? val
        params << "#{iv.as_param}" if val
      else
        params << "#{iv.as_param} #{val.as_arg}" if val
      end
    end
  end
  
  params << "--symbols #{File.expand_path(@symbols_file.to_s)}" if (@symbols_file and !@symbols_file.empty?)
  params << "--save-temps" if @save_temps
  params << "--disable-warnings" if @disable_warnings
  
  if @sources
    @sources.each do |source|
      params << "#{File.expand_path(source.to_s).as_arg}"
    end
  end
  
  return params.compact.uniq
end

#runObject



157
158
159
160
161
162
# File 'lib/orchid/compiler.rb', line 157

def run
  cmd = "#{Orchid::VALAC} #{parameters() * ' '}"
  
  puts cmd
  system(cmd)
end