Class: Dirwatch::Options

Inherits:
Object show all
Defined in:
lib/dirwatch/options.rb,
lib/dirwatch/options/parser.rb

Defined Under Namespace

Classes: InitParser, Parser, WatchParser

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, options) ⇒ Options

Returns a new instance of Options.



15
16
17
18
# File 'lib/dirwatch/options.rb', line 15

def initialize action, options
  @action = action.to_sym
  @options = send "#{@action}_options", options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



24
25
26
27
# File 'lib/dirwatch/options.rb', line 24

def method_missing m, *args, &block
  return @options[m] if @options && @options.key?(m)
  super
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



13
14
15
# File 'lib/dirwatch/options.rb', line 13

def action
  @action
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/dirwatch/options.rb', line 13

def options
  @options
end

Class Method Details

.from_args(args) ⇒ Object



6
7
8
9
10
11
# File 'lib/dirwatch/options.rb', line 6

def self.from_args args
  parser = Parser.from_args args
  parser.parse! args

  new parser.action, parser.options.to_h
end

Instance Method Details

#respond_to_missing?(m, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/dirwatch/options.rb', line 29

def respond_to_missing? m, include_private = false
  (@options && @options.key?(m)) || super
end

#to_hObject



20
21
22
# File 'lib/dirwatch/options.rb', line 20

def to_h
  @options
end