Class: PixnetSso::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/pixnet_sso/install_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object

Implement the required interface for Rails::Generators::Migration. taken from github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb



12
13
14
15
16
17
18
# File 'lib/generators/pixnet_sso/install_generator.rb', line 12

def self.next_migration_number(dirname) #:nodoc:
  if ActiveRecord::Base.timestamped_migrations
    Time.now.utc.strftime("%Y%m%d%H%M%S")
  else
    "%.3d" % (current_migration_number(dirname) + 1)
  end
end

Instance Method Details

#create_migration_fileObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/pixnet_sso/install_generator.rb', line 20

def create_migration_file
  template 'user.rb', "app/models/#{user_model.singularize.underscore}.rb"
  migration_template 'migration.rb', "db/migrate/create_#{user_model.tableize}.rb"


  if openid_enabled?
    template 'openid_associate.rb', "app/models/#{openid_model.singularize.underscore}.rb"
    migration_template 'migration_openid.rb', "db/migrate/create_#{openid_model.tableize}.rb"
  end

  template 'config.rb', 'config/initializers/pixnet-sso.rb'
end

#openid_enabledObject



42
43
44
# File 'lib/generators/pixnet_sso/install_generator.rb', line 42

def openid_enabled
  @openid_enabled ||= ask("Would you want to enable OpenID ?(y/N)")
end

#openid_enabled?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/generators/pixnet_sso/install_generator.rb', line 46

def openid_enabled?
  openid_enabled.downcase == 'y'
end

#openid_modelObject



37
38
39
40
# File 'lib/generators/pixnet_sso/install_generator.rb', line 37

def openid_model
  return '' unless openid_enabled?
  @openid_model ||= ask('What is your openid model name?').classify
end

#user_modelObject



33
34
35
# File 'lib/generators/pixnet_sso/install_generator.rb', line 33

def user_model
  @user_model ||= ask('What is your user model name?').classify
end