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
-
.included(base) ⇒ Object
a bit of trickiness to change a singleton method…
Instance Method Summary collapse
-
#debug(*msgs) ⇒ Object
Internal debugging.
- #debug? ⇒ Boolean
- #ing_file ⇒ Object
- #namespace ⇒ Object
- #require_ing_file ⇒ Object
-
#require_libs(libs = requires) ⇒ Object
require relative paths relative to the Dir.pwd otherwise, require as given (so gems can be required, etc.).
- #requires ⇒ Object
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
23 24 25 |
# File 'lib/ing/common_options.rb', line 23 def debug? !![:debug] end |
#ing_file ⇒ Object
31 32 33 |
# File 'lib/ing/common_options.rb', line 31 def ing_file [:ing_file] end |
#namespace ⇒ Object
35 36 37 |
# File 'lib/ing/common_options.rb', line 35 def namespace [:namespace] end |
#require_ing_file ⇒ Object
53 54 55 56 |
# File 'lib/ing/common_options.rb', line 53 def require_ing_file f = File.(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.(lib) else lib end require f end end |
#requires ⇒ Object
27 28 29 |
# File 'lib/ing/common_options.rb', line 27 def requires [:require] end |