Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

generators named right

  • Loading branch information...
commit 9e00d732962c762a568b2300c2570abaa4e0d41e 1 parent 3fea18f
Philip (flip) Kromer authored
View
4 generators/email_verification/email_verification_generator.rb
@@ -28,7 +28,7 @@ def initialize(runtime_args, runtime_options = {})
def manifest
record do |m|
# m.directory "lib"
- m.directory File.join('app/views', parent_model_path, 'email_verification')
+ m.directory File.join('app/views/', @parent_plural_name)
m.directory File.join('app', @parent_controller_path)
m.directory File.join('app', @parent_model_path)
m.directory File.join('spec', @parent_controller_path)
@@ -69,7 +69,7 @@ def add_user_model_concerns m
def add_mailer_templates m
%w[email_verified signup_notification].each do |view|
src_file = "#{view}.html.erb"
- src_path = "views/#{src_file}"
+ src_path = "views/#{@parent_plural_name}/#{src_file}"
dest_path = File.join('app/views', parent_plural_name, src_file)
m.template src_path, dest_path
end
View
4 generators/email_verification/templates/migration.rb
@@ -1,7 +1,7 @@
class <%= migration_name %> < ActiveRecord::Migration
def self.up
- #add_column :<%= parent_table_name %>, :email_verification_code, :string, :limit => 40
- #add_column :<%= parent_table_name %>, :email_verified_at, :datetime
+ add_column :<%= parent_table_name %>, :email_verification_code, :string, :limit => 40
+ add_column :<%= parent_table_name %>, :email_verified_at, :datetime
say_with_time "Marking existing users' emails as verified..." do
<%= parent_class_name %>.send(:include, Trustification::EmailVerification)
<%= parent_class_name %>.find(:all).each do |u|
View
42 generators/simple_roles/simple_roles_generator.rb
@@ -1,4 +1,4 @@
-class EmailVerificationGenerator < Rails::Generator::NamedBase
+class SimpleRolesGenerator < Rails::Generator::NamedBase
default_options :skip_migration => false,
:skip_routes => false,
:old_passwords => false,
@@ -13,9 +13,10 @@ class EmailVerificationGenerator < Rails::Generator::NamedBase
:parent_controller_name, # users_controller
:parent_controller_path # controllers/users_controller
+
def initialize(runtime_args, runtime_options = {})
super
- @default_roles_list = [:user, ]
+ options[:default_roles_list] = [:user, ]
@parent_model_name = "user"
@parent_plural_name = @parent_model_name.pluralize
@parent_table_name = @parent_model_name.pluralize
@@ -23,20 +24,20 @@ def initialize(runtime_args, runtime_options = {})
@parent_model_path = "models/#{@parent_model_name}"
@parent_controller_name = "#{@parent_plural_name}_controller"
@parent_controller_path = "controllers/#{@parent_controller_name}"
- @model_path = "#{parent_model_name}/email_verification"
+ @model_path = "#{parent_model_name}/simple_roles"
end
def manifest
record do |m|
# m.directory "lib"
- m.directory File.join('app/views', parent_model_path, 'email_verification')
+ m.directory File.join('app/views', @parent_plural_name)
m.directory File.join('app', @parent_controller_path)
m.directory File.join('app', @parent_model_path)
m.directory File.join('spec', @parent_controller_path)
m.directory File.join('spec', @parent_model_path)
- add_user_model_concerns m
- add_users_controller_concerns m
+ add_users_controller_concerns %w[], m
+ add_user_model_concerns %w[], m
add_migration m unless options[:skip_migration]
post_install_notes
end
@@ -45,7 +46,7 @@ def manifest
protected
# Override with your own usage banner.
def banner
- "Usage: #{$0} email_verification User"
+ "Usage: #{$0} simple_roles User"
end
def add_options!(opt)
opt.separator ''
@@ -70,17 +71,19 @@ def add_options!(opt)
# Installation methods
#
- def add_users_controller_concerns m
- dest_file = "email_verification.rb"
- src_file = "email_verification_controller.rb"
- dest_path = File.join('app', parent_controller_path, dest_file)
- puts "templating #{src_file} to #{dest_path}"
- m.template src_file, dest_path
+ def add_users_controller_concerns concerns, m
+ concerns.each do |concern|
+ src_file = "simple_roles_#{concern}.rb"
+ dest_file = src_file
+ dest_path = File.join('app', parent_controller_path, dest_file)
+ puts "templating #{src_file} to #{dest_path}"
+ m.template src_file, dest_path
+ end
end
- def add_user_model_concerns m
- %w[observer mailer].each do |concern|
- src_file = "email_verification_#{concern}.rb"
+ def add_user_model_concerns concerns, m
+ concerns.each do |concern|
+ src_file = "simple_roles_#{concern}.rb"
dest_file = src_file
dest_path = File.join('app', parent_model_path, dest_file)
puts "templating #{src_file} to #{dest_path}"
@@ -105,13 +108,12 @@ def post_install_notes
action = File.basename($0) # grok the action from './script/generate' or whatever
case action
when "generate"
- puts "- Add an observer to config/environment.rb"
- puts " config.active_record.observers = :#{file_name}_observer"
+ # post-install notes go here
+ # puts ""
end
- puts %{ map.verify '/verify/:activation_code', :controller => '#{parent_controller_name}', :action => 'verify_email', :verification_code => nil }
end
-
end
+
# def manifest
# record do |m|
# modify_or_add_user_fixtures(m)
View
2  generators/simple_roles/templates/migration.rb
@@ -1,6 +1,6 @@
class <%= migration_name %> < ActiveRecord::Migration
def self.up
- add_column :<%= parent_table_name %>, :roles, :text, :default => '<%= default_roles_list.to_json %>'
+ add_column :<%= parent_table_name %>, :roles, :text, :default => '<%= options[:default_roles_list].inspect %>'
say_with_time "Assigning :admin role to a new or existing admin user..." do
Identity::AddOrMakeAdminUser.add_or_make_admin_user
end
View
4 lib/identity.rb
@@ -32,7 +32,7 @@ def has_role? role
[:user, :active].include? role
end
-
+
#
# Validations
#
@@ -52,7 +52,7 @@ def has_role? role
#
# This is purposefully imperfect -- it's just a check for bogus input. See
# http://www.regular-expressions.info/email.html
- MSG_EMAIL_BAD = "should look like an email address (you@somethingsomething.com) and include only letters, numbers and .%+- please."
+ MSG_EMAIL_BAD = "should look like an email address (you@somethingsomething.com) and include only letters, numbers and .&nbsp;+&nbsp;-&nbsp;&#37; please."
RE_EMAIL_NAME = '[\w\.%\+\-]+' # what you actually see in practice
RE_EMAIL_N_RFC2822 = '0-9A-Z!#\$%\&\'\*\+_/=\?^\-`\{|\}~\.' # technically allowed by RFC-2822
RE_DOMAIN_HEAD = '(?:[A-Z0-9\-]+\.)+'
View
2  lib/identity/add_or_make_admin_user.rb
@@ -4,7 +4,7 @@ def self.add_or_make_admin_user
puts "*"*70
admin = self.find_admin || self.make_admin
admin.assign_role! :admin
- admin.reconcile_privileges!
+ admin.send(:reconcile_privileges!)
puts " added 'admin' role"
puts "*"*70
admin
View
2  lib/identity/simple_roles.rb
@@ -24,7 +24,7 @@ def has_role? role
# Adds role. No error if user already has role.
# returns updated user.roles
def assign_role! role, skip_save=false
- self.roles << role
+ (self.roles ||= []) << role.to_s
self.roles.uniq!
self.save(false) unless (skip_save==:skip_save)
self.roles
Please sign in to comment.
Something went wrong with that request. Please try again.