Class: CleanUp::OptionValues

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/clean_up/option_values.rb', line 6

def options
  @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).options
end

Instance Method Details

#respond_to_missing?(method) ⇒ Boolean

Returns:

  • (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