Class: Partializer::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/partializer/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *items) ⇒ Collection

Returns a new instance of Collection.



7
8
9
10
11
12
13
# File 'lib/partializer/collection.rb', line 7

def initialize name, *items
  hash = items.extract_options!      
  partials << partial_keys(items)
  self.name = name.to_s
  @hashie = Hashie::Mash.new resolve(hash) unless hash.empty?
  set_names unless hashie.nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth_name, *args, &block) ⇒ Object (protected)



92
93
94
# File 'lib/partializer/collection.rb', line 92

def method_missing meth_name, *args, &block
  hashie.send(meth_name)
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



5
6
7
# File 'lib/partializer/collection.rb', line 5

def action
  @action
end

#hashieObject (readonly)

Returns the value of attribute hashie.



5
6
7
# File 'lib/partializer/collection.rb', line 5

def hashie
  @hashie
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/partializer/collection.rb', line 5

def name
  @name
end

#nsObject (readonly)

Returns the value of attribute ns.



5
6
7
# File 'lib/partializer/collection.rb', line 5

def ns
  @ns
end

Instance Method Details

#each(&block) ⇒ Object



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

def each &block
  partials.each {|partial| yield partial }      
end

#partialsObject



19
20
21
# File 'lib/partializer/collection.rb', line 19

def partials
  @partials ||= Partializer::Partials.new
end

#pathObject Also known as: to_partial_path



23
24
25
# File 'lib/partializer/collection.rb', line 23

def path
  [ns, action, name.gsub('.', '/')].compact.join('/')
end

#set_context(ns, action) ⇒ Object



29
30
31
32
# File 'lib/partializer/collection.rb', line 29

def set_context ns, action
  @ns, @action = [ns, action]
  partials.list.each {|p| p.send :set_context, ns, action }
end