class ActiveRecord::Generators::AppdirectIntegrationGenerator

Public Instance Methods

copy_appdirect_integration_migration() click to toggle source
# File lib/generators/active_record/appdirect_integration_generator.rb, line 13
def copy_appdirect_integration_migration
  if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
    migration_template "migration_existing.rb", "db/migrate/add_appdirect_integration_to_#{table_name}.rb"
  else
    migration_template "migration.rb", "db/migrate/appdirect_integration_create_#{table_name}.rb"
  end
end
generate_model() click to toggle source
# File lib/generators/active_record/appdirect_integration_generator.rb, line 21
def generate_model
  invoke "active_record:model", [name], migration: false unless model_exists? && behavior == :invoke
end
inet?() click to toggle source
# File lib/generators/active_record/appdirect_integration_generator.rb, line 54
def inet?
  rails4? && postgresql?
end
inject_appdirect_integration_content() click to toggle source
# File lib/generators/active_record/appdirect_integration_generator.rb, line 25
def inject_appdirect_integration_content
  content = model_contents

  class_path = if namespaced?
    class_name.to_s.split("::")
  else
    [class_name]
  end

  indent_depth = class_path.size - 1
  content = content.split("\n").map { |line| "  " * indent_depth + line } .join("\n") << "\n"

  inject_into_class(model_path, class_path.last, content) if model_exists?
end
ip_column() click to toggle source
# File lib/generators/active_record/appdirect_integration_generator.rb, line 49
def ip_column
  # Padded with spaces so it aligns nicely with the rest of the columns.
  "%-8s" % (inet? ? "inet" : "string")
end
migration_data() click to toggle source
# File lib/generators/active_record/appdirect_integration_generator.rb, line 40
def migration_data
  data = "\n"
  AppdirectIntegration::FIELDS.each do |field|
    data += "      t.#{field[:type]} :#{field[:name]}\n"
  end

  data
end
postgresql?() click to toggle source
# File lib/generators/active_record/appdirect_integration_generator.rb, line 62
def postgresql?
  config = ActiveRecord::Base.configurations[Rails.env]
  config && config['adapter'] == 'postgresql'
end
rails4?() click to toggle source
# File lib/generators/active_record/appdirect_integration_generator.rb, line 58
def rails4?
  Rails.version.start_with? '4'
end