Module: Rails::Generators::ResourceHelpers
Do not use. This module is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | railties/lib/rails/generators/resource_helpers.rb |
Overview
Deal with controller names on scaffold and add some helpers to deal with ActiveModel
.
Class Method Summary
Instance Attribute Summary
- #controller_file_name readonly private
- #controller_name readonly private
Instance Method Summary
-
#initialize(*args)
Set controller variables on initialization.
- #assign_controller_names!(name) private
- #controller_class_name private
- #controller_class_path private
- #controller_file_path private
- #controller_i18n_scope private
-
#orm_class
private
Loads the
ORM::Generators::ActiveModel
class. -
#orm_instance(name = singular_table_name)
private
Initialize
ORM::Generators::ActiveModel
to access instance methods.
Class Method Details
.included(base)
[ GitHub ]# File 'railties/lib/rails/generators/resource_helpers.rb', line 11
def self.included(base) # :nodoc: base.include(Rails::Generators::ModelHelpers) base.class_option :model_name, type: :string, desc: "ModelName to be used" end
Instance Attribute Details
#controller_file_name (readonly, private)
[ GitHub ]# File 'railties/lib/rails/generators/resource_helpers.rb', line 29
attr_reader :controller_name, :controller_file_name
#controller_name (readonly, private)
[ GitHub ]# File 'railties/lib/rails/generators/resource_helpers.rb', line 29
attr_reader :controller_name, :controller_file_name
Instance Method Details
#assign_controller_names!(name) (private)
[ GitHub ]# File 'railties/lib/rails/generators/resource_helpers.rb', line 39
def assign_controller_names!(name) @controller_name = name @controller_class_path = name.include?("/") ? name.split("/") : name.split("::") @controller_class_path.map!(&:underscore) @controller_file_name = @controller_class_path.pop end
#controller_class_name (private)
[ GitHub ]# File 'railties/lib/rails/generators/resource_helpers.rb', line 50
def controller_class_name (controller_class_path + [controller_file_name]).map!(&:camelize).join("::") end
#controller_class_path (private)
[ GitHub ]# File 'railties/lib/rails/generators/resource_helpers.rb', line 31
def controller_class_path if [:model_name] @controller_class_path else class_path end end
#controller_file_path (private)
[ GitHub ]# File 'railties/lib/rails/generators/resource_helpers.rb', line 46
def controller_file_path @controller_file_path ||= (controller_class_path + [controller_file_name]).join("/") end
#controller_i18n_scope (private)
[ GitHub ]# File 'railties/lib/rails/generators/resource_helpers.rb', line 54
def controller_i18n_scope @controller_i18n_scope ||= controller_file_path.tr("/", ".") end
#initialize(*args)
Set controller variables on initialization.
# File 'railties/lib/rails/generators/resource_helpers.rb', line 17
def initialize(*args) # :nodoc: super controller_name = name if [:model_name] self.name = [:model_name] assign_names!(name) end assign_controller_names!(controller_name.pluralize) end
#orm_class (private)
Loads the ORM::Generators::ActiveModel
class. This class is responsible to tell scaffold entities how to generate a specific method for the ORM. Check ActiveModel
for more information.
# File 'railties/lib/rails/generators/resource_helpers.rb', line 61
def orm_class @orm_class ||= begin # Raise an error if the class_option :orm was not defined. unless self.class. [:orm] raise "You need to have :orm as class option to invoke orm_class and orm_instance" end begin "#{ [:orm].to_s.camelize}::Generators::ActiveModel".constantize rescue NameError Rails::Generators::ActiveModel end end end
#orm_instance(name = singular_table_name) (private)
Initialize ORM::Generators::ActiveModel
to access instance methods.
# File 'railties/lib/rails/generators/resource_helpers.rb', line 77
def orm_instance(name = singular_table_name) @orm_instance ||= orm_class.new(name) end