Class: Egi::Env
- Inherits:
-
Object
- Object
- Egi::Env
- Defined in:
- lib/egi/env.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #group(name = nil, &block) ⇒ Object
-
#initialize(name) ⇒ Env
constructor
A new instance of Env.
- #item(name, hash = {}) ⇒ Object
- #items ⇒ Object
- #merge!(other) ⇒ Object
- #set(default = {}) ⇒ Object
- #tagged(name) ⇒ Object
- #tags ⇒ Object
Constructor Details
#initialize(name) ⇒ Env
Returns a new instance of Env.
3 4 5 6 |
# File 'lib/egi/env.rb', line 3 def initialize(name) @name = name @default = {} end |
Instance Method Details
#[](name) ⇒ Object
30 31 32 |
# File 'lib/egi/env.rb', line 30 def [](name) items[name.to_sym] end |
#group(name = nil, &block) ⇒ Object
18 19 20 |
# File 'lib/egi/env.rb', line 18 def group(name = nil, &block) items.merge!(Class.new(Group).new(name).instance_eval(&block).items) end |
#item(name, hash = {}) ⇒ Object
26 27 28 |
# File 'lib/egi/env.rb', line 26 def item(name, hash = {}) items[name.to_sym].update(hash) end |
#items ⇒ Object
22 23 24 |
# File 'lib/egi/env.rb', line 22 def items @items ||= Hash.new {|hash, key| hash[key] = Item[{ :name => key }.merge(@default)] } end |
#merge!(other) ⇒ Object
12 13 14 15 16 |
# File 'lib/egi/env.rb', line 12 def merge!(other) other = (other.is_a?(Env) ? other.items : other) # because items has default proc and cannnot dump items.merge!(Marshal.load(Marshal.dump(Hash[other]))) end |
#set(default = {}) ⇒ Object
8 9 10 |
# File 'lib/egi/env.rb', line 8 def set(default = {}) @default = default end |
#tagged(name) ⇒ Object
38 39 40 41 |
# File 'lib/egi/env.rb', line 38 def tagged(name) name = name.to_sym .include?(name) ? items.select {|k, v| v[:tags].include?(name) } : nil end |
#tags ⇒ Object
34 35 36 |
# File 'lib/egi/env.rb', line 34 def @tags ||= items.values.map {|item| item[:tags] || [] }.flatten.uniq end |