Class: Pkgr::Env
- Inherits:
-
Object
- Object
- Pkgr::Env
- Defined in:
- lib/pkgr/env.rb
Instance Attribute Summary collapse
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(variables = nil) ⇒ Env
constructor
A new instance of Env.
- #merge(other) ⇒ Object
- #present? ⇒ Boolean
- #to_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(variables = nil) ⇒ Env
Returns a new instance of Env.
11 12 13 14 |
# File 'lib/pkgr/env.rb', line 11 def initialize(variables = nil) @variables = variables || [] @variables.compact! end |
Instance Attribute Details
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
5 6 7 |
# File 'lib/pkgr/env.rb', line 5 def variables @variables end |
Class Method Details
.from_export(file) ⇒ Object
7 8 9 |
# File 'lib/pkgr/env.rb', line 7 def self.from_export(file) new(File.read(file).split("\n").map { |line| line.sub(/^export\s+/, "") }) end |
Instance Method Details
#merge(other) ⇒ Object
28 29 30 |
# File 'lib/pkgr/env.rb', line 28 def merge(other) self.class.new(self.variables + other.variables) end |
#present? ⇒ Boolean
20 21 22 |
# File 'lib/pkgr/env.rb', line 20 def present? create_env_hash_from_string.length > 0 end |
#to_hash ⇒ Object
24 25 26 |
# File 'lib/pkgr/env.rb', line 24 def to_hash create_env_hash_from_string end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/pkgr/env.rb', line 16 def to_s to_hash.map{|k, v| [k, v.quote].join("=")}.join(" ") end |