Module: Main::Base::DSL

Included in:
Main::Base
Defined in:
lib/main/base.rb

Instance Method Summary collapse

Instance Method Details

#argument(*a, &b) ⇒ Object Also known as: arg



192
193
194
# File 'lib/main/base.rb', line 192

def argument *a, &b
  (parameters << Parameter.create(:argument, *a, &b)).last
end

#can_has(ptype, *a, &b) ⇒ Object



222
223
224
225
226
# File 'lib/main/base.rb', line 222

def can_has ptype, *a, &b
  key = a.map{|s| s.to_s}.sort_by{|s| -s.size }.first
  can_has_hash.update key => [ptype, a, b]
  key
end

#chunknameObject

TODO - for some reason these hork the usage!



253
254
255
256
257
258
259
260
# File 'lib/main/base.rb', line 253

%w[ examples samples api ].each do |chunkname|
  module_eval <<-code
    def #{ chunkname } *a, &b 
      txt = b ? b.call : a.join("\\n")
      usage['#{ chunkname }'] = txt
    end
  code
end

#default_options!Object



188
189
190
# File 'lib/main/base.rb', line 188

def default_options!
  option 'help', 'h' unless parameters.has_option?('help', 'h')
end

#environment(*a, &b) ⇒ Object Also known as: env



202
203
204
# File 'lib/main/base.rb', line 202

def environment *a, &b
  (parameters << Parameter.create(:environment, *a, &b)).last
end

#has(key, *keys) ⇒ Object



228
229
230
231
232
233
234
235
236
# File 'lib/main/base.rb', line 228

def has key, *keys 
  keys = [key, *keys].flatten.compact.map{|k| k.to_s}
  keys.map do |key|
    ptype, a, b = can_has_hash[key]
    abort "yo - can *not* has #{ key.inspect }!?" unless(ptype and a and b)
    send ptype, *a, &b
    key
  end
end

#keyword(*a, &b) ⇒ Object Also known as: kw



197
198
199
# File 'lib/main/base.rb', line 197

def keyword *a, &b
  (parameters << Parameter.create(:keyword, *a, &b)).last
end

#mixin(name, *names, &block) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/main/base.rb', line 238

def mixin name, *names, &block
  names = [name, *names].flatten.compact.map{|name| name.to_s}
  if block
    names.each do |name|
      mixin_table[name] = block
    end
  else
    names.each do |name|
      module_eval &mixin_table[name]
    end
  end
end

#mode(name, &b) ⇒ Object

def mode name, &b

  klass = 
    create context do
      mode_name name.to_s
      module_eval &b if b
    end
  modes.add klass
end


218
219
220
# File 'lib/main/base.rb', line 218

def mode name, &b
  mode_definitions << [name, b]
end

#option(*a, &b) ⇒ Object Also known as: opt, switch



182
183
184
# File 'lib/main/base.rb', line 182

def option *a, &b
  (parameters << Parameter.create(:option, *a, &b)).last
end

#parameter(*a, &b) ⇒ Object



178
179
180
# File 'lib/main/base.rb', line 178

def parameter *a, &b
  (parameters << Parameter.create(:parameter, *a, &b)).last
end