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.



11
12
13
14
# File 'lib/configurate/setting_path.rb', line 11

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

Instance Method Details

#==(other) ⇒ Object



67
68
69
# File 'lib/configurate/setting_path.rb', line 67

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

#action?Boolean

Whether the current path looks like an action method

Returns:

  • (Boolean)


34
35
36
# File 'lib/configurate/setting_path.rb', line 34

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

#eachObject



43
44
45
46
47
48
49
# File 'lib/configurate/setting_path.rb', line 43

def each
  return to_enum(:each) unless block_given?

  @path.each do |component|
    yield clean_special_characters(component)
  end
end

#initialize_copy(original) ⇒ Object



16
17
18
19
# File 'lib/configurate/setting_path.rb', line 16

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

#inspectObject



71
72
73
74
75
76
77
# File 'lib/configurate/setting_path.rb', line 71

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)


29
30
31
# File 'lib/configurate/setting_path.rb', line 29

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)


24
25
26
# File 'lib/configurate/setting_path.rb', line 24

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

#setter?Boolean

Whether the current path looks like a setter method

Returns:

  • (Boolean)


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

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

#to_sObject



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

def to_s
  join(".")
end