Class: Oauned::Generators::InstallGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Includes:
Helpers
Defined in:
lib/generators/oauned/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_oauned_routesObject



18
19
20
# File 'lib/generators/oauned/install_generator.rb', line 18

def add_oauned_routes
  route "scope '/scoped' { oauned_routing }"
end

#copy_migrationObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/oauned/install_generator.rb', line 22

def copy_migration
  [:application, :authorization, :connection].each do |model_sym|
    model_name = send(model_sym)
    @table_name = model_name.pluralize
    if (behavior == :invoke && model_exists?(model_name)) || (behavior == :revoke && migration_exists?(model_name))
      migration_template "migration_existing.rb",
        "db/migrate/add_oauned_to_#{model_name}"
    else
      migration_template "migration.rb",
        "db/migrate/oauned_create_#{model_name}"
    end
  end
end

#create_modelsObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/generators/oauned/install_generator.rb', line 36

def create_models
  [:application, :authorization, :connection].each do |model_sym|
    model_name = send(model_sym)
    if !model_exists?(model_name) && behavior == :invoke
      Rails::Generators.invoke "active_record:model",
        [model_name],
        :migration => false,
        :destination_root => destination_root
      require File.join(destination_root, model_path(model_name))
    end
  end
end

#inject_application_contentObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/generators/oauned/install_generator.rb', line 49

def inject_application_content
  if model_exists?(application)
    inject_into_class model_path(application),
      application.capitalize.constantize,
<<EOS
  include Oauned::Models::Application

  has_many   :authorizations
  has_many   :connections
EOS
  end
end

#inject_authorization_contentObject



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/generators/oauned/install_generator.rb', line 62

def inject_authorization_content
  if model_exists?(authorization)
    inject_into_class model_path(authorization),
      authorization.capitalize.constantize,
<<EOS
  include Oauned::Models::Authorization

  belongs_to       :user
  belongs_to       :application
EOS
  end
end

#inject_connection_contentObject



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/generators/oauned/install_generator.rb', line 75

def inject_connection_content
  if model_exists?(connection)
    inject_into_class model_path(connection),
      connection.capitalize.constantize,
 <<EOS
  include Oauned::Models::Connection

  belongs_to       :user
  belongs_to       :application
EOS
  end
end