module AppdirectIntegration::Generators::OrmHelpers

Public Instance Methods

model_contents() click to toggle source
# File lib/generators/appdirect_integration/orm_helpers.rb, line 6
      def model_contents
        buffer = <<-CONTENT
  # Prepared for integration with AppDirect

CONTENT
        if needs_attr_accessible?
          buffer += <<-CONTENT
  # Setup accessible (or protected) attributes for your model

CONTENT
          buffer += "  attr_accessible"
          AppdirectIntegration::FIELDS.each do |field|
            buffer += " :#{field[:name]},"
          end

          # Remove last ','
          buffer = buffer[0..-2]
        end

        buffer
      end
needs_attr_accessible?() click to toggle source
# File lib/generators/appdirect_integration/orm_helpers.rb, line 28
def needs_attr_accessible?
  rails_3? && !strong_parameters_enabled?
end
rails_3?() click to toggle source
# File lib/generators/appdirect_integration/orm_helpers.rb, line 32
def rails_3?
  Rails::VERSION::MAJOR == 3
end
strong_parameters_enabled?() click to toggle source
# File lib/generators/appdirect_integration/orm_helpers.rb, line 36
def strong_parameters_enabled?
  defined?(ActionController::StrongParameters)
end

Private Instance Methods

migration_exists?(table_name) click to toggle source
# File lib/generators/appdirect_integration/orm_helpers.rb, line 46
def migration_exists?(table_name)
  Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_appdirect_integration_to_#{table_name}.rb$/).first
end
migration_path() click to toggle source
# File lib/generators/appdirect_integration/orm_helpers.rb, line 50
def migration_path
  @migration_path ||= File.join("db", "migrate")
end
model_exists?() click to toggle source
# File lib/generators/appdirect_integration/orm_helpers.rb, line 42
def model_exists?
  File.exists?(File.join(destination_root, model_path))
end
model_path() click to toggle source
# File lib/generators/appdirect_integration/orm_helpers.rb, line 54
def model_path
  @model_path ||= File.join("app", "models", "#{file_path}.rb")
end