Module: Hanswurst::ClassMethods
- Included in:
- Hanswurst
- Defined in:
- lib/hanswurst/class_methods.rb
Overview
class methods for Hanswurst
Instance Method Summary collapse
-
#getClass(classname) ⇒ Object
get class obj from a classname.
- #method_missing(meth, *args, &code) ⇒ Object
-
#register_role(hsh) ⇒ Object
hsh is role_alias => klass where role_alias should be a symbol.
-
#role_class(role_alias) ⇒ Object
returns the role klass for the role_alias (role_alias should be a symbol).
-
#role_list(role_alias, listname, val) ⇒ Object
(also: #list_for)
creates a list for documents of the role
role_alias
. -
#role_view(role_alias, viewname, options) ⇒ Object
(also: #view_for)
creates a view to show only documents of the role
role_alias
.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &code) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/hanswurst/class_methods.rb', line 44 def method_missing(meth, *args, &code) case meth when /^view_for_(.+)$/ send(:view_for, $1, *args) when /^list_for_(.+)$/ send(:list_for, $1, *args) else super end end |
Instance Method Details
#getClass(classname) ⇒ Object
get class obj from a classname
9 10 11 |
# File 'lib/hanswurst/class_methods.rb', line 9 def getClass(classname) classname.split('::').inject Kernel do |c,name| c = c.const_get name; end end |
#register_role(hsh) ⇒ Object
hsh is role_alias => klass where role_alias should be a symbol
14 15 16 17 |
# File 'lib/hanswurst/class_methods.rb', line 14 def register_role(hsh) @roles ||= {} @roles.update hsh end |
#role_class(role_alias) ⇒ Object
returns the role klass for the role_alias (role_alias should be a symbol)
20 21 22 23 |
# File 'lib/hanswurst/class_methods.rb', line 20 def role_class(role_alias) @roles ||= {} @roles[role_alias] end |
#role_list(role_alias, listname, val) ⇒ Object Also known as: list_for
creates a list for documents of the role role_alias
37 38 39 |
# File 'lib/hanswurst/class_methods.rb', line 37 def role_list(role_alias, listname, val) self.list :"#{role_alias}_#{listname}", val.to_s end |
#role_view(role_alias, viewname, options) ⇒ Object Also known as: view_for
creates a view to show only documents of the role role_alias
26 27 28 29 30 31 32 |
# File 'lib/hanswurst/class_methods.rb', line 26 def role_view(role_alias, viewname, ) # I keep this commented out to inform the reader that we don't want this in order to easily reuse general lists #options[:list] &&= :"#{role_alias}_#{options[:list]}" [:conditions] &&= " && ( #{[:conditions]} )" [:conditions] = "(doc.hanswurst_roles.#{role_alias} !== undefined)#{[:conditions]}" self.view :"#{role_alias}_#{viewname}", end |