Module: AppdirectIntegration::Generators::OrmHelpers

Included in:
ActiveRecord::Generators::AppdirectIntegrationGenerator, Mongoid::Generators::AppdirectIntegrationGenerator
Defined in:
lib/generators/appdirect_integration/orm_helpers.rb

Instance Method Summary collapse

Instance Method Details

#model_contentsObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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?Boolean



28
29
30
# File 'lib/generators/appdirect_integration/orm_helpers.rb', line 28

def needs_attr_accessible?
  rails_3? && !strong_parameters_enabled?
end

#rails_3?Boolean



32
33
34
# File 'lib/generators/appdirect_integration/orm_helpers.rb', line 32

def rails_3?
  Rails::VERSION::MAJOR == 3
end

#strong_parameters_enabled?Boolean



36
37
38
# File 'lib/generators/appdirect_integration/orm_helpers.rb', line 36

def strong_parameters_enabled?
  defined?(ActionController::StrongParameters)
end