class Quails::Generators::NamedBase
Attributes
file_name[R]
TODO Change this to private once we've dropped Ruby 2.2 support. Workaround for Ruby 2.2 “private attribute?” warning.
Private Class Methods
check_class_collision(options = {})
click to toggle source
Add a class collisions name to be checked on class initialization. You can supply a hash with a :prefix or :suffix to be tested.
Examples¶ ↑
check_class_collision suffix: "Decorator"
If the generator is invoked with class name Admin
, it will check for the presence of “AdminDecorator”.
# File railties/lib/rails/generators/named_base.rb, line 194 def self.check_class_collision(options = {}) # :doc: define_method :check_class_collision do name = if respond_to?(:controller_class_name) # for ScaffoldBase controller_class_name else class_name end class_collisions "#{options[:prefix]}#{name}#{options[:suffix]}" end end
Public Instance Methods
js_template(source, destination)
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 30 def js_template(source, destination) template(source + ".js", destination + ".js") end
template(source, *args, &block)
click to toggle source
Calls superclass method
# File railties/lib/rails/generators/named_base.rb, line 24 def template(source, *args, &block) inside_template do super end end
Private Instance Methods
application_name()
click to toggle source
Tries to retrieve the application name or simply return application.
# File railties/lib/rails/generators/named_base.rb, line 147 def application_name # :doc: if defined?(Quails) && Quails.application Quails.application.class.name.split("::").first.underscore else "application" end end
assign_names!(name)
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 155 def assign_names!(name) @class_path = name.include?("/") ? name.split("/") : name.split("::") @class_path.map!(&:underscore) @file_name = @class_path.pop end
attributes_names()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 168 def attributes_names # :doc: @attributes_names ||= attributes.each_with_object([]) do |a, names| names << a.column_name names << "password_confirmation" if a.password_digest? names << "#{a.name}_type" if a.polymorphic? end end
class_name()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 75 def class_name # :doc: (class_path + [file_name]).map!(&:camelize).join("::") end
class_path()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 63 def class_path # :doc: inside_template? || !namespaced? ? regular_class_path : namespaced_class_path end
edit_helper()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 110 def edit_helper # :doc: "edit_#{show_helper}" end
field_id(attribute_name)
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 118 def field_id(attribute_name) [singular_table_name, attribute_name].join("_") end
file_path()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 59 def file_path # :doc: @file_path ||= (class_path + [file_name]).join("/") end
fixture_file_name()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 134 def fixture_file_name # :doc: @fixture_file_name ||= (pluralize_table_names? ? plural_file_name : file_name) end
human_name()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 79 def human_name # :doc: @human_name ||= singular_name.humanize end
i18n_scope()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 87 def i18n_scope # :doc: @i18n_scope ||= file_path.tr("/", ".") end
index_helper()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 102 def index_helper # :doc: uncountable? ? "#{plural_table_name}_index" : plural_table_name end
inside_template() { || ... }
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 48 def inside_template # :doc: @inside_template = true yield ensure @inside_template = false end
inside_template?()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 55 def inside_template? # :doc: @inside_template end
mountable_engine?()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 180 def mountable_engine? # :doc: defined?(ENGINE_ROOT) && namespaced? end
namespaced_class_path()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 71 def namespaced_class_path # :doc: @namespaced_class_path ||= namespace_dirs + @class_path end
new_helper()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 114 def new_helper # :doc: "new_#{singular_table_name}_url" end
parse_attributes!()
click to toggle source
Convert attributes array into GeneratedAttribute
objects.
# File railties/lib/rails/generators/named_base.rb, line 162 def parse_attributes! self.attributes = (attributes || []).map do |attr| Quails::Generators::GeneratedAttribute.parse(attr) end end
plural_file_name()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 130 def plural_file_name # :doc: @plural_file_name ||= file_name.pluralize end
plural_name()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 83 def plural_name # :doc: @plural_name ||= singular_name.pluralize end
plural_table_name()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 126 def plural_table_name # :doc: @plural_table_name ||= (pluralize_table_names? ? table_name : table_name.pluralize) end
pluralize_table_names?()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 176 def pluralize_table_names? # :doc: !defined?(ActiveRecord::Base) || ActiveRecord::Base.pluralize_table_names end
regular_class_path()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 67 def regular_class_path # :doc: @class_path end
route_url()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 138 def route_url # :doc: @route_url ||= class_path.collect { |dname| "/" + dname }.join + "/" + plural_file_name end
show_helper()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 106 def show_helper # :doc: "#{singular_table_name}_url(@#{singular_table_name})" end
singular_name()
click to toggle source
FIXME: We are avoiding to use alias because a bug on thor that make this method public and add it to the task list.
# File railties/lib/rails/generators/named_base.rb, line 44 def singular_name # :doc: file_name end
singular_table_name()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 122 def singular_table_name # :doc: @singular_table_name ||= (pluralize_table_names? ? table_name.singularize : table_name) end
table_name()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 91 def table_name # :doc: @table_name ||= begin base = pluralize_table_names? ? plural_name : singular_name (class_path + [base]).join("_") end end
uncountable?()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 98 def uncountable? # :doc: singular_name == plural_name end
url_helper_prefix()
click to toggle source
# File railties/lib/rails/generators/named_base.rb, line 142 def url_helper_prefix # :doc: @url_helper_prefix ||= (class_path + [file_name]).join("_") end