Class: Ace::Support::Config::Models::CascadePath

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/config/models/cascade_path.rb

Overview

Represents a configuration cascade path

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, priority: 100, exists: false, type: :local) ⇒ CascadePath

Initialize cascade path

Parameters:

  • path (String)

    File system path

  • priority (Integer) (defaults to: 100)

    Priority (lower = higher priority)

  • exists (Boolean) (defaults to: false)

    Whether path exists

  • type (Symbol) (defaults to: :local)

    Type of path (:local, :home, :gem)



16
17
18
19
20
21
22
# File 'lib/ace/support/config/models/cascade_path.rb', line 16

def initialize(path:, priority: 100, exists: false, type: :local)
  @path = path.to_s.freeze
  @priority = priority
  @exists = exists
  @type = type
  freeze
end

Instance Attribute Details

#existsObject (readonly)

Returns the value of attribute exists.



9
10
11
# File 'lib/ace/support/config/models/cascade_path.rb', line 9

def exists
  @exists
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/ace/support/config/models/cascade_path.rb', line 9

def path
  @path
end

#priorityObject (readonly)

Returns the value of attribute priority.



9
10
11
# File 'lib/ace/support/config/models/cascade_path.rb', line 9

def priority
  @priority
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/ace/support/config/models/cascade_path.rb', line 9

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ Integer

Compare paths by priority

Parameters:

Returns:

  • (Integer)

    Comparison result



27
28
29
30
31
# File 'lib/ace/support/config/models/cascade_path.rb', line 27

def <=>(other)
  return nil unless other.is_a?(CascadePath)

  priority <=> other.priority
end

#==(other) ⇒ Object Also known as: eql?



67
68
69
70
71
72
# File 'lib/ace/support/config/models/cascade_path.rb', line 67

def ==(other)
  other.is_a?(self.class) &&
    other.path == path &&
    other.priority == priority &&
    other.type == type
end

#absolute?Boolean

Check if path is absolute

Returns:

  • (Boolean)

    true if absolute path



57
58
59
# File 'lib/ace/support/config/models/cascade_path.rb', line 57

def absolute?
  pathname.absolute?
end

#hashObject



74
75
76
# File 'lib/ace/support/config/models/cascade_path.rb', line 74

def hash
  [path, priority, type].hash
end

#inspectObject



80
81
82
83
84
85
86
87
88
89
# File 'lib/ace/support/config/models/cascade_path.rb', line 80

def inspect
  attrs = [
    "path=#{path.inspect}",
    "type=#{type}",
    "priority=#{priority}",
    exists ? "exists" : "missing"
  ].join(" ")

  "#<#{self.class.name} #{attrs}>"
end

#overrides?(other) ⇒ Boolean

Check if this path should override another

Parameters:

Returns:

  • (Boolean)

    true if this path has higher priority



36
37
38
39
40
# File 'lib/ace/support/config/models/cascade_path.rb', line 36

def overrides?(other)
  return false unless other.is_a?(CascadePath)

  priority < other.priority
end

#pathnamePathname

Get path as Pathname

Returns:

  • (Pathname)

    Path object



50
51
52
53
# File 'lib/ace/support/config/models/cascade_path.rb', line 50

def pathname
  require "pathname"
  Pathname.new(path)
end

#relative?Boolean

Check if path is relative

Returns:

  • (Boolean)

    true if relative path



63
64
65
# File 'lib/ace/support/config/models/cascade_path.rb', line 63

def relative?
  !absolute?
end

#to_sString

Convert to string

Returns:

  • (String)

    The file path



44
45
46
# File 'lib/ace/support/config/models/cascade_path.rb', line 44

def to_s
  path
end