Module: Contextualize

Defined in:
lib/contextualize.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



39
40
41
# File 'lib/contextualize.rb', line 39

def self.included base
  base.extend ClassMethods
end

Instance Method Details

#add_context(name) ⇒ Object Also known as: enter_context



59
60
61
62
63
64
# File 'lib/contextualize.rb', line 59

def add_context name
  context(name).each do |const|
    self.send :mixin, const
  end
  self
end

#add_contexts(*names) ⇒ Object Also known as: enter_contexts



47
48
49
50
# File 'lib/contextualize.rb', line 47

def add_contexts *names
  names.each {|name| add_context(name) }
  self
end

#context_mapObject



43
44
45
# File 'lib/contextualize.rb', line 43

def context_map
  self.class.context_map || {}
end

#remove_context(name) ⇒ Object Also known as: exit_context



67
68
69
70
71
72
73
# File 'lib/contextualize.rb', line 67

def remove_context name
  return if !context(name) || context(name).empty? 
  context(name).each do |const|
    self.send :unmix, const
  end
  self
end

#remove_contexts(*names) ⇒ Object Also known as: exit_contexts



53
54
55
56
# File 'lib/contextualize.rb', line 53

def remove_contexts *names
  names.each {|name| remove_context(name) }
  self
end