Class: MethodInfo::OptionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/method_info/option_handler.rb

Constant Summary collapse

@@custom_default_options =
{}

Class Method Summary collapse

Class Method Details

.default_optionsObject



43
44
45
# File 'lib/method_info/option_handler.rb', line 43

def self.default_options
  @@custom_default_options
end

.default_options=(options = {}) ⇒ Object



39
40
41
# File 'lib/method_info/option_handler.rb', line 39

def self.default_options=(options = {})
  @@custom_default_options = options
end

.default_profileObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/method_info/option_handler.rb', line 22

def self.default_profile
  {
    :ancestors_to_show => [],
    :ancestors_to_exclude => [],
    :format => nil,
    :include_names_of_excluded_ancestors => true,
    :include_names_of_methodless_ancestors => true,
    :private_methods => false,
    :protected_methods => false,
    :singleton_methods => true,
    :public_methods => true,
    :enable_colors => false,
    :suppress_slowness_warning => false,
    :match => nil
  }
end

.handle(object, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/method_info/option_handler.rb', line 7

def self.handle(object, options = {})
  processed_options = process_options(options)
  format = processed_options.delete(:format)
  ancestor_method_structure = AncestorMethodStructure.build(object, processed_options)
  if format == :string
    ancestor_method_structure.to_s
  elsif format == :array
    ancestor_method_structure.to_a
  elsif format
    raise(ArgumentError.new("Unknown value for :format option. Supported values are: nil, :array, :string"))
  else
    puts ancestor_method_structure
  end
end

.process_options(options = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/method_info/option_handler.rb', line 47

def self.process_options(options = {})
  defaults = default_profile.merge(@@custom_default_options)
  unknown_options = options.keys - defaults.keys
  if unknown_options.empty?
    defaults.merge(options)
  else
    raise ArgumentError.new("Unsupported options: " + unknown_options.map { |k| k.to_s }.sort.join(', '))
  end
end