Class: BestInPlaceMongoid::DisplayMethods::Renderer

Inherits:
Struct
  • Object
show all
Defined in:
lib/best_in_place_mongoid/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_mongoid/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
# File 'lib/best_in_place_mongoid/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]
              BestInPlaceMongoid::ViewHelpers.send(opts[:method], object.send(opts[:attr]), opts[:helper_options])
            else
              BestInPlaceMongoid::ViewHelpers.send(opts[:method], object.send(opts[:attr]))
            end
    {:display_as => value}.to_json
  else
    {}.to_json
  end
end