Module: WashoutBuilderSharedHelper

Instance Method Summary collapse

Instance Method Details

#find_class_from_string(complex_class) ⇒ Class?

Tries to constantize a string or a class to return the class

Parameters:

  • complex_class (String)

    A string that contains the name of a class

Returns:

  • (Class, nil)

    returns the class if it is classes_defined otherwise nil



24
25
26
27
28
# File 'app/helpers/washout_builder_shared_helper.rb', line 24

def find_class_from_string(complex_class)
  complex_class.is_a?(Class) ? complex_class : complex_class.constantize
rescue
  nil
end

#find_correct_complex_type(complex_class) ⇒ Class, String

When displaying a complex type that inherits from WashOut::Type we must use its descendant name to properly show the correct Type that can we used to make the actual request to the action

Parameters:

  • complex_class (Class, String)

    the name of the complex type either as a string or a class

Returns:

  • (Class, String)


9
10
11
12
13
14
15
16
17
# File 'app/helpers/washout_builder_shared_helper.rb', line 9

def find_correct_complex_type(complex_class)
  real_class = find_class_from_string(complex_class)
  if real_class.present? && real_class.ancestors.include?( WashoutBuilder::Type.base_type_class)
    descendant = WashoutBuilder::Type.base_param_class.parse_def(config, real_class.wash_out_param_map)[0]
    descendant.find_complex_class_name
  else
    complex_class
  end
end