Class: Partializer::Collection
- Inherits:
-
Object
- Object
- Partializer::Collection
- Includes:
- Enumerable
- 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
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. 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
#action ⇒ Object (readonly)
Returns the value of attribute action.
5 6 7 |
# File 'lib/partializer/collection.rb', line 5 def action @action end |
#hashie ⇒ Object (readonly)
Returns the value of attribute hashie.
5 6 7 |
# File 'lib/partializer/collection.rb', line 5 def hashie @hashie end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/partializer/collection.rb', line 5 def name @name end |
#ns ⇒ Object (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 |
#partials ⇒ Object
19 20 21 |
# File 'lib/partializer/collection.rb', line 19 def partials @partials ||= Partializer::Partials.new end |
#path ⇒ Object 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 |