Class: Oauned::Generators::InstallGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- Oauned::Generators::InstallGenerator
- Includes:
- Helpers
- Defined in:
- lib/generators/oauned/install_generator.rb
Instance Method Summary collapse
- #add_oauned_routes ⇒ Object
- #copy_migration ⇒ Object
- #create_models ⇒ Object
- #inject_application_content ⇒ Object
- #inject_authorization_content ⇒ Object
- #inject_connection_content ⇒ Object
Instance Method Details
#add_oauned_routes ⇒ Object
18 19 20 |
# File 'lib/generators/oauned/install_generator.rb', line 18 def add_oauned_routes route "scope '/scoped' { oauned_routing }" end |
#copy_migration ⇒ Object
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_models ⇒ Object
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_content ⇒ Object
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_content ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/generators/oauned/install_generator.rb', line 62 def if model_exists?() inject_into_class model_path(), .capitalize.constantize, <<EOS include Oauned::Models::Authorization belongs_to :user belongs_to :application EOS end end |
#inject_connection_content ⇒ Object
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 |