Module: CouchPotato::View::CustomViews::ClassMethods
- Defined in:
- lib/couch_potato/view/custom_views.rb
Instance Method Summary collapse
- #_find_view(view) ⇒ Object
- #execute_view(view_name, view_parameters) ⇒ Object
- #view(view_name, options) ⇒ Object
- #view_spec_class(type) ⇒ Object
-
#views(view_name = nil) ⇒ Object
Declare a CouchDB view, for examples on how to use see the *ViewSpec classes in CouchPotato::View.
Instance Method Details
#_find_view(view) ⇒ Object
46 47 48 49 |
# File 'lib/couch_potato/view/custom_views.rb', line 46 def _find_view(view) return @views[view] if @views && @views[view] superclass._find_view(view) if superclass && superclass.respond_to?(:_find_view) end |
#execute_view(view_name, view_parameters) ⇒ Object
26 27 28 |
# File 'lib/couch_potato/view/custom_views.rb', line 26 def execute_view(view_name, view_parameters) view_spec_class(views(view_name)[:type]).new(self, view_name, views(view_name), view_parameters) end |
#view(view_name, options) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/couch_potato/view/custom_views.rb', line 30 def view(view_name, ) view_name = view_name.to_s views[view_name] = method_str = "def #{view_name}(view_parameters = {}); execute_view(\"#{view_name}\", view_parameters); end" self.instance_eval(method_str) end |
#view_spec_class(type) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/couch_potato/view/custom_views.rb', line 37 def view_spec_class(type) if type && type.is_a?(Class) type else name = type.nil? ? 'Model' : type.to_s.camelize CouchPotato::View.const_get("#{name}ViewSpec") end end |
#views(view_name = nil) ⇒ Object
Declare a CouchDB view, for examples on how to use see the *ViewSpec classes in CouchPotato::View
18 19 20 21 22 23 24 |
# File 'lib/couch_potato/view/custom_views.rb', line 18 def views(view_name = nil) if view_name _find_view(view_name) else @views ||= {} end end |