Class: BestInPlace::DisplayMethods::Renderer

Inherits:
Struct
  • Object
show all
Defined in:
lib/best_in_place/display_methods.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optsObject

Returns the value of attribute opts

Returns:

  • (Object)

    the current value of opts



5
6
7
# File 'lib/best_in_place/display_methods.rb', line 5

def opts
  @opts
end

Instance Method Details

#render_json(object) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/best_in_place/display_methods.rb', line 6

def render_json(object)
  case opts[:type]
    when :model
      { display_as: object.send(opts[:method]) }.to_json
    when :helper
      value = if opts[:helper_options]
                BestInPlace::ViewHelpers.send(opts[:method], object.send(opts[:attr]), opts[:helper_options])
              else
                BestInPlace::ViewHelpers.send(opts[:method], object.send(opts[:attr]))
              end
      { display_as: value }.to_json
    when :proc
      { display_as: opts[:proc].call(object.send(opts[:attr])) }.to_json
    else
      '{}'
  end
end