Class: AuthorizedRailsScaffolds::RailsHelperHelper

Inherits:
Helper
  • Object
show all
Defined in:
lib/authorized_rails_scaffolds/rails_helper_helper.rb

Instance Method Summary collapse

Methods inherited from Helper

#plural_var_name, #shallow_routes?, #var_name

Methods included from Macros::ResourceMacros

#resource_array_key, #resource_array_name, #resource_array_sym, #resource_array_var, #resource_class, #resource_directory, #resource_human_name, #resource_key, #resource_name, #resource_symbol, #resource_var

Methods included from Macros::PathMacros

#controller_edit_route, #controller_index_path, #controller_index_route, #controller_new_route, #controller_show_route, #references_show_route

Methods included from Macros::ParentMacros

#model_parent_name, #parent_model_names, #parent_models, #parent_module_groups, #parent_modules, #parent_sym, #parent_variable, #parent_variables

Constructor Details

#initialize(options = {}) ⇒ RailsHelperHelper

Returns a new instance of RailsHelperHelper.



3
4
5
6
7
# File 'lib/authorized_rails_scaffolds/rails_helper_helper.rb', line 3

def initialize(options = {})
  super options

  @modular_class_name = options[:class_name] || options[:local_class_name]
end

Instance Method Details

#modular_class_nameObject

Class name with parent modules included (i.e. Example::FooBar) Name of class assumed by default generators, used as a base for determining modules and class



11
12
13
# File 'lib/authorized_rails_scaffolds/rails_helper_helper.rb', line 11

def modular_class_name
  @modular_class_name.singularize
end

#scoped_values_for_form(variable, use_shallow_route = false) ⇒ Object

returns values that should be parsed by a form in order for post and put actions to work



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/authorized_rails_scaffolds/rails_helper_helper.rb', line 16

def scoped_values_for_form(variable, use_shallow_route=false)
  variable ||= resource_var

  form_argument_values = []

  # Add the modules
  parent_module_groups.each do |parent_module|
    form_argument_values << ":#{parent_module}"
  end

  # Add the models
  parent_models = use_shallow_route ? parent_model_names[0..-2] : parent_model_names
  parent_models.each do |parent_model|
    form_argument_values << parent_variable(parent_model)
  end

  form_argument_values << variable

  if form_argument_values.count == 1
    return variable
  else
    "[#{form_argument_values.join(', ')}]"
  end
end