Class: Partializer::Collection
- Inherits:
-
Object
- Object
- Partializer::Collection
- Includes:
- Enumerable, PathHelper
- Defined in:
- lib/partializer/collection.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#hashie ⇒ Object
readonly
Returns the value of attribute hashie.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ns ⇒ Object
readonly
Returns the value of attribute ns.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(name, *items) ⇒ Collection
constructor
A new instance of Collection.
- #partials ⇒ Object
- #path ⇒ Object (also: #to_partial_path)
- #set_context(ns, action) ⇒ Object
Methods included from PathHelper
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. 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
#action ⇒ Object (readonly)
Returns the value of attribute action.
6 7 8 |
# File 'lib/partializer/collection.rb', line 6 def action @action end |
#hashie ⇒ Object (readonly)
Returns the value of attribute hashie.
6 7 8 |
# File 'lib/partializer/collection.rb', line 6 def hashie @hashie end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/partializer/collection.rb', line 6 def name @name end |
#ns ⇒ Object (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 |
#partials ⇒ Object
20 21 22 |
# File 'lib/partializer/collection.rb', line 20 def partials @partials ||= Partializer::Partials.new end |
#path ⇒ Object 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 |