Organized seeds and added rake config:show and config:put tasks

Esse commit está contido em:
Ronaldo Pontes
2013-08-19 19:46:52 -03:00
commit 7729b1630f
6 arquivos alterados com 251 adições e 9 exclusões
+2
Ver Arquivo
@@ -3,6 +3,8 @@ db/*.sqlite3
log/*.log
tmp/**/*
config/database.yml
db/seeds/my-seeds-local.rb
db/seeds/my-seeds-heroku.rb
db/development_structure.sql
# Vim
*.swp
Arquivo normal → Arquivo executável
+31
Ver Arquivo
@@ -1,5 +1,7 @@
# coding: utf-8
puts 'Seeding the database...'
[
{ pt: 'Arte', en: 'Art' },
{ pt: 'Artes plásticas', en: 'Visual Arts' },
@@ -90,3 +92,32 @@ OauthProvider.find_or_create_by_name!(
secret: 'your_facebook_app_secret',
path: 'facebook'
)
puts
puts '============================================='
puts ' Showing all Authentication Providers'
puts '---------------------------------------------'
OauthProvider.all.each do |conf|
a = conf.attributes
puts " name #{a['name']}"
puts " key: #{a['key']}"
puts " secret: #{a['secret']}"
puts " path: #{a['path']}"
puts
end
puts
puts '============================================='
puts ' Showing all entries in Configuration Table...'
puts '---------------------------------------------'
Configuration.all.each do |conf|
a = conf.attributes
puts " #{a['name']}: #{a['value']}"
end
puts '---------------------------------------------'
puts 'Done!'
+1 -8
Ver Arquivo
@@ -1,11 +1,4 @@
## Optional Seed file
## to be used during development
puts "Adding Uservoice.com settings..."
Configuration.find_or_create_by_name('uservoice_subdomain').update_attribute('value', 'dummy_domain.uservoice.com')
Configuration.find_or_create_by_name('uservoice_sso_key').update_attribute('value', 'dummy_uservoice_sso_key')
## Add sample users
puts "Adding Admin user..."
+85
Ver Arquivo
@@ -0,0 +1,85 @@
## Update this configuration seed and then run
## rake db:seed:my-seeds
puts "Adding OauthProvider settings..."
puts " Facebook..."
## catarse-local-dev Facebook App
facebook = OauthProvider.find_or_initialize_by_name 'facebook'
facebook.update_attributes(
key: '556758001037275',
secret: '5b3a847321b426f9dabd011359a21400',
path: 'facebook'
)
#OauthProvider.create :name => 'Twitter', :key => 'myconsumerkey', :secret => 'myconsumersecret', :strategy => 'Twitter', :path => 'twitter'
#OauthProvider.create :name => 'LinkedIn', :key => 'myconsumerkey', :secret => 'myconsumersecret', :strategy => 'LinkedIn', :path => 'linked_in'
###
## Uservoice.com seetings
## at YOURDOMAIN.uservoice.com/admin/settings#/channels
## Sendgrid Heroku Plugin Settings
puts "Creating Configuration entries..."
{
catarse_fee: '0.13',
company_name: 'Catarse',
host: 'YOUR_HOST',
base_domain: 'YOUR_DOMAIN',
base_url: "YOUR_BASE_URL",
facebook_url: "http://facebook.com/MY-FACEBOOK-PAGE",
facebook_app_id: '556758001037275',
uservoice_subdomain: 'MY-USER-VOICE.uservoice.com',
uservoice_sso_key: 'MY-USER-VOICE-KEY',
uservoice_secret_gadget: 'MY-USER-VOICE-SECRET',
sendgrid_user_name: 'MY-HEROKU-SENDGRID-APP@heroku.com',
sendgrid: 'MY-HEROKU-SENDGRID-KEY',
mailchimp_url: "YOUR_MAIL_CHIMP_URL",
blog_url: "YOUR_BLOG_URL",
twitter_username: "YOUR_TWITTER",
email_contact: 'EMAIL_ACCOUNT',
email_payments: 'EMAIL_ACCOUNT',
email_projects: 'EMAIL_ACCOUNT',
email_system: 'EMAIL_ACCOUNT',
email_no_reply: 'EMAIL_ACCOUNT',
support_forum: 'YOUR_SUPPORT_URL',
}.each do |name, value|
conf = Configuration.find_or_initialize_by_name name
conf.update_attributes({
value: value
})
end
puts
puts '============================================='
puts ' Showing all Authentication Providers'
puts '---------------------------------------------'
OauthProvider.all.each do |conf|
a = conf.attributes
puts " name #{a['name']}"
puts " key: #{a['key']}"
puts " secret: #{a['secret']}"
puts " path: #{a['path']}"
puts
end
puts
puts '============================================='
puts ' Showing all entries in Configuration Table...'
puts '---------------------------------------------'
Configuration.all.each do |conf|
a = conf.attributes
puts " #{a['name']}: #{a['value']}"
end
puts '---------------------------------------------'
puts 'Done!'
Arquivo executável
+57
Ver Arquivo
@@ -0,0 +1,57 @@
####
# Task to manage the application configuration table
##
namespace :config do
###
# Shows all entries in the configuration table
# usage: rake config:show
##
desc "Shows all entries in the configuration table\n usage: rake config:show"
task :show => :environment do
puts
puts '============================================='
puts ' Showing all Authentication Providers'
puts '---------------------------------------------'
OauthProvider.all.each do |conf|
a = conf.attributes
puts " name #{a['name']}"
puts " key: #{a['key']}"
puts " secret: #{a['secret']}"
puts " path: #{a['path']}"
puts
end
puts
puts '============================================='
puts ' Showing all entries in Configuration Table...'
puts '---------------------------------------------'
Configuration.all.each do |conf|
a = conf.attributes
puts " #{a['name']}: #{a['value']}"
end
puts '---------------------------------------------'
puts 'Done!'
end
###
# Adds an entry to the configuration table
# usage: rake config:put[config_name,config_value]
##
desc "Adds an entry to the configuration table\n usage: rake config:put"
task :put, [:name, :value] => :environment do |t, args|
puts
puts "Adding #{args[:name]}=#{args[:value]} to configuration table..."
conf = Configuration.find_or_initialize_by_name args[:name]
conf.update_attributes(
value: args[:value],
)
puts 'Done!'
puts
end
end
Arquivo normal → Arquivo executável
+75 -1
Ver Arquivo
@@ -1,4 +1,12 @@
namespace :user do
####
# Task to manage the application users
##
namespace :users do
###
# Syncs users with newsletter
# usage: rake users:sync_with_mailee
##
desc 'This task will sync the users with newsletter = true with Mailee.'
task :sync_with_mailee => :environment do
print "Synchronizing contacts..."
@@ -7,4 +15,70 @@ namespace :user do
end
puts "OK!"
end
###
# Shows all entries in the configuration table
# usage: rake users:show
##
desc "Shows all entries in the configuration table"
task :show => :environment do
puts
puts '============================================='
puts ' Application Users'
puts '---------------------------------------------'
User.all.each do |conf|
a = conf.attributes
print "\nname: #{a['name']}"
print "\n nickname: #{a['nickname']}"
print "\n email: #{a['email']}"
print "\n admin: #{a['admin']}"
puts
end
puts '---------------------------------------------'
puts 'Done!'
end
###
# Sets user as administrator
# usage: rake users:admin[email]
##
desc "Sets user as administrator"
task :admin, [:email] => :environment do |t, args|
puts
puts "Setting #{args[:email]} as administrator..."
u = User.find_by_email(args[:email])
unless u
puts "ERROR: User doesn't exist!"
next
end
u.update_attribute :admin, true
puts "#{u.name}: #{u.email} is now an administrator!"
puts 'Done!'
puts
end
###
# Sets first user as administrator
# usage: rake users:adminfirst
##
desc "Sets first user as administrator"
task :adminfirst => :environment do
puts
unless User.count > 0
puts "ERROR: User doesn't exist!"
next
end
u = User.first
u.update_attribute :admin, true
puts "#{u.name}: #{u.email} is now an administrator!"
puts 'Done!'
puts
end
end