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



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

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

#eachObject



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

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



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

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

#is_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 is_question?
  @path.last.to_s.end_with?("?")
end

#is_question_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 is_question_or_setter?
  is_question? || is_setter?
end

#is_setter?Boolean

Whether the current path looks like a setter method

Returns:

  • (Boolean)


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

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

#to_sObject



55
56
57
# File 'lib/configurate/setting_path.rb', line 55

def to_s
  join(".")
end