Module: Workbench::ObjectHelper

Defined in:
app/helpers/workbench/object_helper.rb

Overview

A metamodule- helper methods for object related manipulations in other helpers

Instance Method Summary collapse

Instance Method Details

#collection_base_path(object) ⇒ String

Returns the member path base for the object, object should be metamorphosized before passing.

Returns:

  • (String)

    the member path base for the object, object should be metamorphosized before passing.



22
23
24
# File 'app/helpers/workbench/object_helper.rb', line 22

def collection_base_path(object)
  object.class.name.tableize
end

#helper_module(object) ⇒ Object

Given the object (non metamorphosized), return the helper instance



27
28
29
# File 'app/helpers/workbench/object_helper.rb', line 27

def helper_module(object)
  (object.class.name + 'Helper').constantize
end

#member_base_path(object) ⇒ String

Returns the member path base for the object, object should be metamorphosized before passing.

Returns:

  • (String)

    the member path base for the object, object should be metamorphosized before passing.



16
17
18
# File 'app/helpers/workbench/object_helper.rb', line 16

def member_base_path(object)
  object.class.name.tableize.singularize
end

#metamorphosize_if(object) ⇒ ActiveRecord object

Returns metamorphosize is defined in the concern Shared::IsData, if its available use it on the object.

Returns:

  • (ActiveRecord object)

    metamorphosize is defined in the concern Shared::IsData, if its available use it on the object



6
7
8
9
10
11
12
# File 'app/helpers/workbench/object_helper.rb', line 6

def metamorphosize_if(object)
  if object.respond_to?(:metamorphosize) 
    object.metamorphosize
  else
    object
  end
end