Class: Artdeco::Decorator
- Inherits:
-
Object
- Object
- Artdeco::Decorator
- Includes:
- DecoratorMethods
- Defined in:
- lib/artdeco.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#view_context ⇒ Object
(also: #h)
readonly
Returns the value of attribute view_context.
Instance Method Summary collapse
-
#eval(data, model = nil) ⇒ Object
evaluate data (string or proc) if model is provided it will accessible in evaluated data.
-
#initialize(*args) ⇒ Decorator
constructor
Args may be either the params hash of the request or an object which responds to :params and optionally to :view_context, e.g.
Methods included from DecoratorMethods
Constructor Details
#initialize(*args) ⇒ Decorator
Args may be either the params hash of the request or an object which responds to :params and optionally to :view_context, e.g. a controller instance If a view_context is given it will be accessible in various blocks by calling :h
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/artdeco.rb', line 54 def initialize *args opts = args. @decorator_classes = ([opts.delete(:decorators)] + [opts.delete(:decorator)]).flatten.compact @decorator_classes = nil if @decorator_classes.empty? # required for #decorate case args.size when 0 @view_context = opts.delete :view_context @params = opts.delete(:params){opts} when 1 arg = args.first @view_context = arg.respond_to?(:view_context) ? arg.view_context : nil if arg.respond_to? :params @params = arg.params.symbolize_keys.merge(opts) else raise ArgumentError, 'argument must respond_to :params' end else raise ArgumentError, 'too many arguments' if args.size > 1 end end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
48 49 50 |
# File 'lib/artdeco.rb', line 48 def params @params end |
#view_context ⇒ Object (readonly) Also known as: h
Returns the value of attribute view_context.
48 49 50 |
# File 'lib/artdeco.rb', line 48 def view_context @view_context end |
Instance Method Details
#eval(data, model = nil) ⇒ Object
evaluate data (string or proc) if model is provided it will accessible in evaluated data
80 81 82 83 84 85 86 87 |
# File 'lib/artdeco.rb', line 80 def eval data, model = nil case data when Proc (model ? model : self).instance_exec(&data) else data end end |