Class: ActiveRecord::Generators::MaestranoUserGenerator

Inherits:
Base
  • Object
show all
Includes:
Maestrano::Generators::OrmHelpers
Defined in:
lib/generators/active_record/maestrano_user_generator.rb

Instance Method Summary collapse

Methods included from Maestrano::Generators::OrmHelpers

#model_contents, #model_type, #needs_attr_accessible?, #rails_3?, #strong_parameters_enabled?

Instance Method Details

#copy_maestrano_migrationObject



10
11
12
# File 'lib/generators/active_record/maestrano_user_generator.rb', line 10

def copy_maestrano_migration
  migration_template "migration.rb", "db/migrate/add_maestrano_to_#{table_name}.rb"
end

#inject_maestrano_contentObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/generators/active_record/maestrano_user_generator.rb', line 14

def inject_maestrano_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

#migration_dataObject



29
30
31
32
33
34
35
36
# File 'lib/generators/active_record/maestrano_user_generator.rb', line 29

def migration_data
<<RUBY
## User source identification fields
t.string :provider
t.string :uid
t.string :tenant
RUBY
end