Class: Pkgr::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/pkgr/env.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#variablesObject (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

Returns:

  • (Boolean)


20
21
22
# File 'lib/pkgr/env.rb', line 20

def present?
  create_env_hash_from_string.length > 0
end

#to_hashObject



24
25
26
# File 'lib/pkgr/env.rb', line 24

def to_hash
  create_env_hash_from_string
end

#to_sObject



16
17
18
# File 'lib/pkgr/env.rb', line 16

def to_s
  to_hash.map{|k, v| [k, v.quote].join("=")}.join(" ")
end