Module: ActsPresentably::InstanceMethods

Defined in:
lib/acts_presentably.rb

Instance Method Summary collapse

Instance Method Details

#as_json(options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/acts_presentably.rb', line 19

def as_json(options={})
  if options && options.has_key?(presenter_key)
    options[presenter_key].new(self).as_json(options)
  else
    klass = Module.const_get(presenter_class)
    return klass.new(self).as_json(options) if klass.is_a?(Class)
    super
  end
end

#presentable?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/acts_presentably.rb', line 10

def presentable?
  true
end

#presenter_classObject



13
14
15
# File 'lib/acts_presentably.rb', line 13

def presenter_class
  self.class.name + 'Presenter'
end

#presenter_keyObject



16
17
18
# File 'lib/acts_presentably.rb', line 16

def presenter_key
  (self.class.name.underscore.downcase + '_presenter').to_sym
end