Module: BestInPlace::DisplayMethods

Defined in:
lib/best_in_place/display_methods.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Renderer

Constant Summary collapse

@@table =
Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }

Class Method Summary collapse

Class Method Details

.add_helper_method(klass, attr, helper_method, helper_options = nil) ⇒ Object



36
37
38
# File 'lib/best_in_place/display_methods.rb', line 36

def add_helper_method(klass, attr, helper_method, helper_options = nil)
  model_attributes(klass)[attr.to_s] = Renderer.new method: helper_method.to_sym, type: :helper, attr: attr, helper_options: helper_options
end

.add_helper_proc(klass, attr, helper_proc) ⇒ Object



40
41
42
# File 'lib/best_in_place/display_methods.rb', line 40

def add_helper_proc(klass, attr, helper_proc)
  model_attributes(klass)[attr.to_s] = Renderer.new type: :proc, attr: attr, proc: helper_proc
end

.add_model_method(klass, attr, display_as) ⇒ Object



32
33
34
# File 'lib/best_in_place/display_methods.rb', line 32

def add_model_method(klass, attr, display_as)
  model_attributes(klass)[attr.to_s] = Renderer.new method: display_as.to_sym, type: :model
end

.lookup(klass, attr) ⇒ Object



27
28
29
30
# File 'lib/best_in_place/display_methods.rb', line 27

def lookup(klass, attr)
  foo = model_attributes(klass)[attr.to_s]
  foo == {} ? nil : foo
end

.model_attributes(klass) ⇒ Object



44
45
46
47
# File 'lib/best_in_place/display_methods.rb', line 44

def model_attributes(klass)
  key = Utils.object_to_key(klass)
  @@table[key]
end