Class: CleanUp::OptionValues
- Inherits:
-
Object
- Object
- CleanUp::OptionValues
- Defined in:
- lib/clean_up/option_values.rb
Constant Summary collapse
- SUPPORTED_OPTIONS =
%w(dir extension pattern files_amount size).freeze
- SUPPORTED_BLOCK_OPTIONS =
%w(contains).freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(&block) ⇒ OptionValues
constructor
A new instance of OptionValues.
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to_missing?(method) ⇒ Boolean
Constructor Details
#initialize(&block) ⇒ OptionValues
Returns a new instance of OptionValues.
12 13 14 15 |
# File 'lib/clean_up/option_values.rb', line 12 def initialize(&block) @options = {} instance_eval(&block) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/clean_up/option_values.rb', line 21 def method_missing(method, *args, &block) if SUPPORTED_BLOCK_OPTIONS.include?(method.to_s) @options[method.to_s] = block elsif SUPPORTED_OPTIONS.include?(method.to_s) case method when 'dir' @options[method.to_s] = args.first.end_with?('/') ? args.first : "#{args.first}/" else @options[method.to_s] = args end end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/clean_up/option_values.rb', line 6 def @options end |
Class Method Details
.parse(&block) ⇒ Object
8 9 10 |
# File 'lib/clean_up/option_values.rb', line 8 def self.parse(&block) new(&block). end |
Instance Method Details
#respond_to_missing?(method) ⇒ Boolean
17 18 19 |
# File 'lib/clean_up/option_values.rb', line 17 def respond_to_missing?(method, *) SUPPORTED_OPTIONS.include?(method.to_s) || super end |