Method: Pakyow::Presenter::View#find
- Defined in:
- lib/pakyow/presenter/view.rb
#find(*names) ⇒ Object
Finds a view binding by name. When passed more than one value, the view will be traversed through each name. Returns a Pakyow::Presenter::VersionedView.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/pakyow/presenter/view.rb', line 122 def find(*names) if names.any? named = names.shift.to_sym found = each_binding(named).map(&:itself) result = if names.empty? && !found.empty? # found everything; wrap it up if found[0].is_a?(StringDoc::MetaNode) VersionedView.new(View.from_object(found[0])) else VersionedView.new(View.from_object(StringDoc::MetaNode.new(found))) end elsif !found.empty? && names.count > 0 # descend further View.from_object(found[0]).find(*names) else nil end if result && block_given? yield result end result else nil end end |