Class: ViewSlots::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/view_slots/namespace.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, parent = nil) ⇒ Namespace

Returns a new instance of Namespace.



4
5
6
# File 'lib/view_slots/namespace.rb', line 4

def initialize(name, parent=nil)
  @parent, @name = parent, name.to_s
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) {|namespace| ... } ⇒ Object

Yields:

  • (namespace)


16
17
18
19
20
# File 'lib/view_slots/namespace.rb', line 16

def method_missing(m, *args)
  namespace = ::ViewSlots::Namespace.new(m, self)
  yield(namespace) if block_given?
  namespace
end

Instance Method Details

#__path__Object



22
23
24
25
26
27
28
# File 'lib/view_slots/namespace.rb', line 22

def __path__
  if @parent
    "#{@parent.__path__}:#{@name}"
  else
    @name
  end
end

#add(*args) ⇒ Object



8
9
10
# File 'lib/view_slots/namespace.rb', line 8

def add(*args)
  ::ViewSlots.add(__path__, *args)
end

#remove(*args) ⇒ Object



12
13
14
# File 'lib/view_slots/namespace.rb', line 12

def remove(*args)
  ::ViewSlots.remove(__path__, *args)
end