Class: ENV
Overview
:nodoc:
Class Method Summary collapse
- .[](name) ⇒ Object
- .[]=(name, value) ⇒ Object
- .delete(name) ⇒ Object
- .empty? ⇒ Boolean
- .fetch(key, default_value = undefined, &block) ⇒ Object
- .key?(name) ⇒ Boolean (also: has_key?, include?, member?)
- .keys ⇒ Object
- .merge(keys) ⇒ Object
-
.pretty_print(q) ⇒ Object
:nodoc:.
- .to_h ⇒ Object (also: to_hash)
- .to_s ⇒ Object (also: inspect)
Class Method Details
.[](name) ⇒ Object
6 7 8 |
# File 'opal/stdlib/nodejs/env.rb', line 6 def [](name) `process.env[#{name}] || nil` end |
.[]=(name, value) ⇒ Object
10 11 12 |
# File 'opal/stdlib/nodejs/env.rb', line 10 def []=(name, value) `process.env[#{name.to_s}] = #{value.to_s}` end |
.delete(name) ⇒ Object
26 27 28 29 30 31 32 |
# File 'opal/stdlib/nodejs/env.rb', line 26 def delete(name) %x{ var value = process.env[#{name}] || nil; delete process.env[#{name}]; return value; } end |
.empty? ⇒ Boolean
18 19 20 |
# File 'opal/stdlib/nodejs/env.rb', line 18 def empty? `Object.keys(process.env).length === 0` end |
.fetch(key, default_value = undefined, &block) ⇒ Object
34 35 36 37 38 39 |
# File 'opal/stdlib/nodejs/env.rb', line 34 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?
14 15 16 |
# File 'opal/stdlib/nodejs/env.rb', line 14 def key?(name) `process.env.hasOwnProperty(#{name})` end |
.keys ⇒ Object
22 23 24 |
# File 'opal/stdlib/nodejs/env.rb', line 22 def keys `Object.keys(process.env)` end |
.merge(keys) ⇒ Object
49 50 51 |
# File 'opal/stdlib/nodejs/env.rb', line 49 def merge(keys) to_h.merge(keys) end |
.pretty_print(q) ⇒ Object
:nodoc:
376 377 378 379 380 381 382 |
# File 'opal/stdlib/pp.rb', line 376 def pretty_print(q) # :nodoc: h = {} ENV.keys.sort.each {|k| h[k] = ENV[k] } q.pp_hash h end |
.to_h ⇒ Object Also known as: to_hash
45 46 47 |
# File 'opal/stdlib/nodejs/env.rb', line 45 def to_h keys.to_h { |k| [k, self[k]] } end |
.to_s ⇒ Object Also known as: inspect
41 42 43 |
# File 'opal/stdlib/nodejs/env.rb', line 41 def to_s 'ENV' end |