module Rails::Generators::ResourceHelpers

def self.included(base) #:nodoc:

:nodoc:
def self.included(base) #:nodoc:
  base.class_option :force_plural, :type => :boolean, :desc => "Forces the use of a plural ModelName"
end

def controller_class_name

def controller_class_name
  @controller_class_name ||= (controller_class_path + [controller_file_name]).map!{ |m| m.camelize }.join('::')
end

def controller_class_path

def controller_class_path
  @class_path
end

def controller_file_name

def controller_file_name
  @controller_file_name ||= file_name.pluralize
end

def controller_file_path

def controller_file_path
  @controller_file_path ||= (controller_class_path + [controller_file_name]).join('/')
end

def controller_i18n_scope

def controller_i18n_scope
  @controller_i18n_scope ||= controller_file_path.gsub('/', '.')
end

def initialize(*args) #:nodoc:

:nodoc:

Set controller variables on initialization.
def initialize(*args) #:nodoc:
  super
  if name == name.pluralize && name.singularize != name.pluralize && !options[:force_plural]
    unless ResourceHelpers.skip_warn
      say "Plural version of the model detected, using singularized version. Override with --force-plural."
      ResourceHelpers.skip_warn = true
    end
    name.replace name.singularize
    assign_names!(name)
  end
  @controller_name = name.pluralize
end

def orm_class

ORM. Check Rails::Generators::ActiveModel for more information.
to tell scaffold entities how to generate an specific method for the
Loads the ORM::Generators::ActiveModel class. This class is responsable
def orm_class
  @orm_class ||= begin
    # Raise an error if the class_option :orm was not defined.
    unless self.class.class_options[:orm]
      raise "You need to have :orm as class option to invoke orm_class and orm_instance"
    end
    begin
      "#{options[:orm].to_s.classify}::Generators::ActiveModel".constantize
    rescue NameError => e
      Rails::Generators::ActiveModel
    end
  end
end

def orm_instance(name=singular_table_name)

Initialize ORM::Generators::ActiveModel to access instance methods.
def orm_instance(name=singular_table_name)
  @orm_instance ||= @orm_class.new(name)
end