Class: Crisp::Env

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

Overview

The Crisp environment is basically a key/value store. The value for each key is immutable, so you can only store one time for each key

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEnv

create a new internal hash



8
9
10
# File 'lib/crisp/env.rb', line 8

def initialize
  @map = {}
end

Instance Attribute Details

#global_loop_dataObject

Returns the value of attribute global_loop_data.



5
6
7
# File 'lib/crisp/env.rb', line 5

def global_loop_data
  @global_loop_data
end

Instance Method Details

#[](key) ⇒ Object

Returns the value for the given key.



18
19
20
21
22
23
24
25
26
# File 'lib/crisp/env.rb', line 18

def [](key)
  result = @map[key.to_sym]

  if result.class == Hash and result[:alias_to]
    self[result[:alias_to]]
  else
    result
  end
end

#[]=(key, val) ⇒ Object

Store the key/value pair. It is only possible to store a value for a key once, otherwise a error will be raised.

Raises:



30
31
32
33
34
# File 'lib/crisp/env.rb', line 30

def []=(key, val)
  key = key.to_sym
  raise EnvironmentError, "#{key} already binded" if @map.has_key?(key)
  @map[key] = val
end

#alias(to, from) ⇒ Object

Store alias



37
38
39
# File 'lib/crisp/env.rb', line 37

def alias(to, from)
  self[to] = {:alias_to => from}
end

#has_key?(key) ⇒ Boolean

Returns boolean for existence of given key in the environment.

Returns:

  • (Boolean)


13
14
15
# File 'lib/crisp/env.rb', line 13

def has_key?(key)
  @map.has_key?(key.to_sym)
end