Module: Surrounded

Defined in:
lib/surrounded.rb,
lib/surrounded/context.rb,
lib/surrounded/version.rb,
lib/surrounded/context_errors.rb,
lib/surrounded/context/role_map.rb,
lib/surrounded/context/negotiator.rb

Defined Under Namespace

Modules: Context, Contextual Classes: NullContext

Constant Summary collapse

VERSION =
"0.3.1"

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object (private)



49
50
51
# File 'lib/surrounded.rb', line 49

def method_missing(meth, *args, &block)
  context.role?(meth){} || super
end

Class Method Details

.create_surroundings(obj) ⇒ Object



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

def self.create_surroundings(obj)
  obj.instance_variable_set(:@__surroundings__, [])
end

.extended(object) ⇒ Object



15
16
17
# File 'lib/surrounded.rb', line 15

def self.extended(object)
  Surrounded.create_surroundings(object)
end

.included(klass) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/surrounded.rb', line 4

def self.included(klass)
  klass.class_eval {
    extend Surrounded::Contextual
  }
  unless klass.is_a?(Class)
    def klass.extended(object)
      Surrounded.create_surroundings(object)
    end
  end
end

Instance Method Details

#remove_contextObject



31
32
33
# File 'lib/surrounded.rb', line 31

def remove_context
  surroundings.shift
end

#store_context(ctxt) ⇒ Object



27
28
29
# File 'lib/surrounded.rb', line 27

def store_context(ctxt)
  surroundings.unshift(ctxt)
end