Class: GestartShowcase::Presenter

Inherits:
SimpleDelegator
  • Object
show all
Extended by:
Helpers::ModuleMethodBuilder
Includes:
Helpers::Present
Defined in:
lib/gestart_showcase/presenter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::ModuleMethodBuilder

define_module_method

Methods included from Helpers::Present

#present, #present_collection, #presenter_context

Constructor Details

#initialize(obj, context) ⇒ Presenter

Returns a new instance of Presenter.



19
20
21
22
# File 'lib/gestart_showcase/presenter.rb', line 19

def initialize(obj, context)
  super(obj)
  @view_context = context
end

Instance Attribute Details

#view_contextObject (readonly) Also known as: h

Returns the value of attribute view_context.



12
13
14
# File 'lib/gestart_showcase/presenter.rb', line 12

def view_context
  @view_context
end

Class Method Details

.presents(*args) ⇒ Object



37
38
39
# File 'lib/gestart_showcase/presenter.rb', line 37

def self.presents(*args)
  wrap_methods(args, :present)
end

.presents_collection(*args) ⇒ Object



41
42
43
# File 'lib/gestart_showcase/presenter.rb', line 41

def self.presents_collection(*args)
  wrap_methods(args, :present_collection)
end

.wrap_methods(args, method) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/gestart_showcase/presenter.rb', line 47

def self.wrap_methods(args, method)
  options = args.extract_options!
  options.assert_valid_keys(:with, :nil_presenter)
  presenter_klass = options.fetch(:with, nil)

  args.each do |attr|
    define_module_method attr do
      send(method,
           object.send(attr),
           presenter_klass,
           view_context,
           options.slice(:nil_presenter))
    end
  end
end

Instance Method Details

#__decorator_class__Object



17
# File 'lib/gestart_showcase/presenter.rb', line 17

alias_method :__decorator_class__, :class

#classObject



24
25
26
# File 'lib/gestart_showcase/presenter.rb', line 24

def class
  object.class
end

#instance_of?(klass) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/gestart_showcase/presenter.rb', line 33

def instance_of?(klass)
  object.instance_of?(klass)
end

#kind_of?(klass) ⇒ Boolean Also known as: is_a?

Returns:

  • (Boolean)


28
29
30
# File 'lib/gestart_showcase/presenter.rb', line 28

def kind_of?(klass)
  object.kind_of?(klass)
end