Module: Ing::CommonOptions

Included in:
Ing::Commands::Generate, Ing::Commands::Help, Ing::Commands::Implicit, Ing::Commands::List
Defined in:
lib/ing/common_options.rb

Overview

Common options for built-in Ing commands

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

a bit of trickiness to change a singleton method…



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ing/common_options.rb', line 7

def self.included(base)
  meth = base.method(:specify_options) if base.respond_to?(:specify_options)
  base.send(:define_singleton_method, :specify_options) do |expect|
    meth.call(expect) if meth
    expect.text "\nCommon Options:"
    expect.opt :debug, "Display debug messages"        
    expect.opt :namespace, "Top-level namespace",
               :type => :string, :default => base::DEFAULTS[:namespace]
    expect.opt :require, "Require file or library before running (multi)", 
               :multi => true, :type => :string
    expect.opt :ing_file, "Default task file (ruby)", 
               :type => :string, :short => 'f', 
               :default => base::DEFAULTS[:ing_file]
  end
end

Instance Method Details

#debug(*msgs) ⇒ Object

Internal debugging



59
60
61
62
63
# File 'lib/ing/common_options.rb', line 59

def debug(*msgs)
  if debug?
    msgs.each do |msg| $stderr.puts "DEBUG :: #{msg}" end
  end
end

#debug?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ing/common_options.rb', line 23

def debug?
  !!options[:debug]
end

#ing_fileObject



31
32
33
# File 'lib/ing/common_options.rb', line 31

def ing_file
  options[:ing_file]
end

#namespaceObject



35
36
37
# File 'lib/ing/common_options.rb', line 35

def namespace
  options[:namespace]
end

#require_ing_fileObject



53
54
55
56
# File 'lib/ing/common_options.rb', line 53

def require_ing_file
  f = File.expand_path(ing_file)
  require_libs(f) if f && File.exists?(f)
end

#require_libs(libs = requires) ⇒ Object

require relative paths relative to the Dir.pwd otherwise, require as given (so gems can be required, etc.)



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ing/common_options.rb', line 41

def require_libs(libs=requires)
  libs = Array(libs)
  libs.each do |lib| 
    f = if /\A\.{1,2}\// =~ lib
        File.expand_path(lib)
      else
        lib
      end
    require f
  end
end

#requiresObject



27
28
29
# File 'lib/ing/common_options.rb', line 27

def requires
  options[:require]
end