Class: Partializer::Collection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PathHelper

#build_path, #partial_path

Constructor Details

#initialize(name, *items) ⇒ Collection

Returns a new instance of Collection.



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

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)



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

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

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



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

def action
  @action
end

#hashieObject (readonly)

Returns the value of attribute hashie.



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

def hashie
  @hashie
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#nsObject (readonly)

Returns the value of attribute ns.



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

def ns
  @ns
end

Instance Method Details

#each(&block) ⇒ Object



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

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

#partialsObject



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

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

#pathObject Also known as: to_partial_path



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

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

#set_context(ns, action) ⇒ Object



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

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