Class: ENV

Inherits:
Object show all
Defined in:
opal/stdlib/pp.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object



4
5
6
# File 'opal/stdlib/nodejs/env.rb', line 4

def [](name)
  `process.env[#{name}] || nil`
end

.[]=(name, value) ⇒ Object



8
9
10
# File 'opal/stdlib/nodejs/env.rb', line 8

def []=(name, value)
  `process.env[#{name.to_s}] = #{value.to_s}`
end

.delete(name) ⇒ Object



24
25
26
27
28
29
30
# File 'opal/stdlib/nodejs/env.rb', line 24

def delete(name)
  %x{
    var value = process.env[#{name}] || nil;
    delete process.env[#{name}];
    return value;
  }
end

.empty?Boolean

Returns:



16
17
18
# File 'opal/stdlib/nodejs/env.rb', line 16

def empty?
  `Object.keys(process.env).length === 0`
end

.fetch(key, default_value = undefined, &block) ⇒ Object

Raises:

  • (KeyError)


32
33
34
35
36
37
# File 'opal/stdlib/nodejs/env.rb', line 32

def fetch(key, default_value = undefined, &block)
  return self[key] if key?(key)
  return yield key if block_given?
  return default_value unless `typeof(#{default_value}) === 'undefined'`
  raise KeyError, 'key not found'
end

.key?(name) ⇒ Boolean Also known as: has_key?, include?, member?

Returns:



12
13
14
# File 'opal/stdlib/nodejs/env.rb', line 12

def key?(name)
  `process.env.hasOwnProperty(#{name})`
end

.keysObject



20
21
22
# File 'opal/stdlib/nodejs/env.rb', line 20

def keys
  `Object.keys(process.env)`
end

.merge(keys) ⇒ Object



47
48
49
# File 'opal/stdlib/nodejs/env.rb', line 47

def merge(keys)
  to_h.merge(keys)
end

.pretty_print(q) ⇒ Object

:nodoc:



375
376
377
378
379
380
381
# File 'opal/stdlib/pp.rb', line 375

def pretty_print(q) # :nodoc:
  h = {}
  ENV.keys.sort.each {|k|
    h[k] = ENV[k]
  }
  q.pp_hash h
end

.to_hObject Also known as: to_hash



43
44
45
# File 'opal/stdlib/nodejs/env.rb', line 43

def to_h
  keys.to_h { |k| [k, self[k]] }
end

.to_sObject Also known as: inspect



39
40
41
# File 'opal/stdlib/nodejs/env.rb', line 39

def to_s
  'ENV'
end