Class: Engine2::Schemes

Inherits:
Object show all
Defined in:
lib/engine2/scheme.rb,
lib/engine2/action/array.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSchemes

Returns a new instance of Schemes.



14
15
16
17
# File 'lib/engine2/scheme.rb', line 14

def initialize
    @builtin = {}
    @user = {}
end

Instance Attribute Details

#builtinObject (readonly)

Returns the value of attribute builtin.



13
14
15
# File 'lib/engine2/scheme.rb', line 13

def builtin
  @builtin
end

#userObject (readonly)

Returns the value of attribute user.



13
14
15
# File 'lib/engine2/scheme.rb', line 13

def user
  @user
end

Instance Method Details

#[](name, raise = true) ⇒ Object

Raises:



25
26
27
28
29
# File 'lib/engine2/scheme.rb', line 25

def [] name, raise = true
    scheme = @builtin[name] || @user[name]
    raise E2Error.new("Scheme #{name} not found") if !scheme && raise
    scheme
end

#define_scheme(name, &blk) ⇒ Object

Raises:



19
20
21
22
23
# File 'lib/engine2/scheme.rb', line 19

def define_scheme name, &blk
    schemes = Engine2::core_loaded ? @user : @builtin
    raise E2Error.new("Scheme '#{name}' already defined") if schemes[name]
    schemes[name] = blk
end