Class: Configurate::SettingPath

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/configurate/setting_path.rb

Overview

Class encapsulating the concept of a path to a setting

Instance Method Summary collapse

Constructor Details

#initialize(path = []) ⇒ SettingPath

Returns a new instance of SettingPath.



9
10
11
12
# File 'lib/configurate/setting_path.rb', line 9

def initialize path=[]
  path = path.split(".") if path.is_a? String
  @path = path
end

Instance Method Details

#==(other) ⇒ Object



64
65
66
# File 'lib/configurate/setting_path.rb', line 64

def ==(other)
  to_s == other.to_s
end

#action?Boolean

Whether the current path looks like an action method

Returns:

  • (Boolean)


32
33
34
# File 'lib/configurate/setting_path.rb', line 32

def action?
  @path.last.to_s.end_with?("!")
end

#eachObject



41
42
43
44
45
46
# File 'lib/configurate/setting_path.rb', line 41

def each
  return to_enum(:each) unless block_given?
  @path.each do |component|
    yield clean_special_characters(component)
  end
end

#initialize_copy(original) ⇒ Object



14
15
16
17
# File 'lib/configurate/setting_path.rb', line 14

def initialize_copy original
  super
  @path = @path.clone
end

#inspectObject



68
69
70
71
72
73
74
# File 'lib/configurate/setting_path.rb', line 68

def inspect
  "<SettingPath:#{object_id.to_s(16)} "\
  "path=#{self}:#{@path.object_id.to_s(16)} "\
  "question=#{question?} "\
  "action=#{action?} "\
  "setter=#{setter?}>"
end

#question?Boolean

Whether the current path looks like a question method

Returns:

  • (Boolean)


27
28
29
# File 'lib/configurate/setting_path.rb', line 27

def question?
  @path.last.to_s.end_with?("?")
end

#question_action_or_setter?Boolean

Whether the current path looks like a question or setter method

Returns:

  • (Boolean)


22
23
24
# File 'lib/configurate/setting_path.rb', line 22

def question_action_or_setter?
  question? || action? || setter?
end

#setter?Boolean

Whether the current path looks like a setter method

Returns:

  • (Boolean)


37
38
39
# File 'lib/configurate/setting_path.rb', line 37

def setter?
  @path.last.to_s.end_with?("=")
end

#to_sObject



60
61
62
# File 'lib/configurate/setting_path.rb', line 60

def to_s
  join(".")
end