Class: Vanagon::Common::Pathname
- Inherits:
-
Object
- Object
- Vanagon::Common::Pathname
- Includes:
- HashableAttributes
- Defined in:
- lib/vanagon/common/pathname.rb,
lib/vanagon/extensions/hashable.rb
Instance Attribute Summary collapse
-
#group ⇒ String, Integer
Returns the numeric group id or string representing the group name of the owner of self.
-
#mode ⇒ String, Integer
Returns an integer representing the permission bits of self.
-
#owner ⇒ String, Integer
Returns the numeric user id or string representing the user name of the owner of self.
-
#path ⇒ String
Returns clean pathname of self with consecutive slashes and useless dots removed.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Equality – Two instances of Pathname are equal if they contain the same number attributes and if each attribute is equal to (according to ‘Object#==`) the corresponding attribute in other_pathname.
-
#configfile? ⇒ Boolean
True if a self is marked as a configuration file.
-
#has_overrides? ⇒ Boolean
Simple test to see if any of the non-required attributes have been set in this object.
-
#hash ⇒ Fixnum
Compute a hash-code for self, derived from its attributes.
-
#initialize(path, mode: nil, owner: nil, group: nil, config: false) ⇒ Vanagon::Common::Pathname
constructor
Each Pathname requires a filesystem path, and has many optional properties that may be set at initialization time.
Methods included from HashableAttributes
Constructor Details
#initialize(path, mode: nil, owner: nil, group: nil, config: false) ⇒ Vanagon::Common::Pathname
Each Vanagon::Common::Pathname requires a filesystem path, and has many optional properties that may be set at initialization time.
32 33 34 35 36 37 38 |
# File 'lib/vanagon/common/pathname.rb', line 32 def initialize(path, mode: nil, owner: nil, group: nil, config: false) @path = ::Pathname.new(path).cleanpath.to_s @mode ||= mode @owner ||= owner @group ||= group @config ||= config end |
Instance Attribute Details
#group ⇒ String, Integer
Returns the numeric group id or string representing the group name of the owner of self.
22 |
# File 'lib/vanagon/common/pathname.rb', line 22 attr_accessor :path, :mode, :owner, :group |
#mode ⇒ String, Integer
Returns an integer representing the permission bits of self. The meaning of the bits is platform dependent; on Unix systems, see stat(2).
22 |
# File 'lib/vanagon/common/pathname.rb', line 22 attr_accessor :path, :mode, :owner, :group |
#owner ⇒ String, Integer
Returns the numeric user id or string representing the user name of the owner of self.
22 |
# File 'lib/vanagon/common/pathname.rb', line 22 attr_accessor :path, :mode, :owner, :group |
#path ⇒ String
Returns clean pathname of self with consecutive slashes and useless dots removed. The filesystem is not accessed.
22 23 24 |
# File 'lib/vanagon/common/pathname.rb', line 22 def path @path end |
Class Method Details
.configfile(path, **args) ⇒ Object
An alias to Vanagon::Common::Pathname‘s constructor method,
which returns a new {Vanagon::Common::Pathname}, explicitly marked as a configuration file
56 57 58 |
# File 'lib/vanagon/common/pathname.rb', line 56 def self.configfile(path, **args) new(path, **args.merge!({ config: true })) end |
.file(path, **args) ⇒ Object
An alias to Vanagon::Common::Pathname‘s constructor method,
which returns a new {Vanagon::Common::Pathname}, explicitly marked as a file
46 47 48 |
# File 'lib/vanagon/common/pathname.rb', line 46 def self.file(path, **args) new(path, **args.merge!({ config: false })) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Equality – Two instances of Vanagon::Common::Pathname are equal if they
contain the same number attributes and if each attribute is equal to
(according to `Object#==`) the corresponding attribute in other_pathname.
77 78 79 |
# File 'lib/vanagon/common/pathname.rb', line 77 def ==(other) other.hash == hash end |
#configfile? ⇒ Boolean
Returns true if a self is marked as a configuration file.
61 62 63 |
# File 'lib/vanagon/common/pathname.rb', line 61 def configfile? !!@config end |
#has_overrides? ⇒ Boolean
Simple test to see if any of the non-required attributes have been set in this object.
68 69 70 |
# File 'lib/vanagon/common/pathname.rb', line 68 def has_overrides? !!(@mode || @owner || @group) end |
#hash ⇒ Fixnum
Compute a hash-code for self, derived from its attributes. Two Vanagon::Common::Pathname objects with the same content will have the same hash code (and will compare as equal using #eql?)
87 88 89 |
# File 'lib/vanagon/common/pathname.rb', line 87 def hash instance_variables.map { |v| instance_variable_get(v) }.hash end |