class Lugg::Switch
An object representing a command line swith with certain behaviour. The Runner
applies switches to its own internal `OptionParser` object to build the CLI and provide querying functionality.
@see Runner
Attributes
obj[R]
options[R]
Public Class Methods
apply_all(*args)
click to toggle source
Call {#apply} on each {Switch} in the global collection to register the callback on a given object.
# File lib/lugg/switch.rb, line 18 def self.apply_all(*args) @queries.each do |query| query.apply_to(*args) end end
define(*args, &block)
click to toggle source
Define a new Switch
object and add it to the global collection of switches.
# File lib/lugg/switch.rb, line 12 def self.define(*args, &block) @queries << new(*args).tap { |obj| obj.instance_eval(&block) } end
new(method = :on)
click to toggle source
# File lib/lugg/switch.rb, line 24 def initialize(method = :on) @method = method @flags = nil @cast = nil @desc = nil @action = nil end
Public Instance Methods
apply_to(options, obj)
click to toggle source
# File lib/lugg/switch.rb, line 32 def apply_to(options, obj) @options = options @obj = obj @options.send(@method, *[@flags, @cast, @desc].flatten.compact, &@action) end
Private Instance Methods
action(&block)
click to toggle source
# File lib/lugg/switch.rb, line 52 def action(&block) @action = block end
cast(obj)
click to toggle source
# File lib/lugg/switch.rb, line 44 def cast(obj) @cast = obj end
desc(msg)
click to toggle source
# File lib/lugg/switch.rb, line 48 def desc(msg) @desc = msg end
flags(*flags)
click to toggle source
# File lib/lugg/switch.rb, line 40 def flags(*flags) @flags = flags end