Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Rails3: Support auto login without passwod for db:shell and postgresql #4

Closed
wants to merge 3 commits into from

3 participants

@dapi

No description provided.

@mike-burns
Owner

Well, this fork has been deleted. And it's unclear why Matt added his Rails3 commits to your fork instead of to master. Danil, Matt, can you work this out and merge this pull request?

@dapi

Such way? #5

@dapi dapi closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 9, 2010
  1. @mjankowski

    rails 3 updates

    mjankowski authored
Commits on Jun 24, 2011
  1. Postgres database shell support added

    Danil Pismenny authored
This page is out of date. Refresh to see the latest.
View
2  MIT-LICENSE
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
5 README.textile
@@ -3,9 +3,9 @@ Limerick Rake
A collection of useful rake tasks.
-To use in a Rails app:
+To use in a Rails app, in your Gemfile:
- $ ruby script/plugin install -f git://github.com/thoughtbot/limerick_rake.git
+ gem 'limerick_rake'
h2. Database
@@ -15,6 +15,7 @@ Read tasks/database.rake for details for configuration.
* rake db:indexes:missing - Prints a list of unindexed foreign keys so you can index them.
* rake db:shell - Launches the database shell using the values defined in config/database.yml.
* rake db:validate_models - Run model validations on all model records in database.
+* rake db:recreate - Recreate database with seeds (drop, create, migrate and seed)
h2. Git
View
28 lib/find_mass_assignment.rb
@@ -2,22 +2,22 @@
# http://github.com/mhartl/find_mass_assignment
require 'active_support'
-
+
# Find potential mass assignment problems.
# The method is to scan the controllers for likely mass assignment,
# and then find the corresponding models that *don't* have
# attr_accessible defined. Any time that happens, it's a potential problem.
-
+
class String
-
+
@@cache = {}
-
+
# A regex to match likely cases of mass assignment
# Examples of matching strings:
# "Foo.new( { :bar => 'baz' } )"
# "Foo.update_attributes!(params[:foo])"
MASS_ASSIGNMENT = /(\w+)\.(new|create|update_attributes|build)!*\(/
-
+
# Return the strings that represent potential mass assignment problems.
# The MASS_ASSIGNMENT regex returns, e.g., ['Post', 'new'] because of
# the grouping methods; we want the first of the two for each match.
@@ -28,12 +28,12 @@ class String
def mass_assignment_models
scan(MASS_ASSIGNMENT).map { |problem| problem.first.classify }
end
-
+
# Return true if the string has potential mass assignment code.
def mass_assignment?
self =~ MASS_ASSIGNMENT
end
-
+
# Return true if the model defines attr_accessible.
# Note that 'attr_accessible' must be preceded by nothing other than
# whitespace; this catches cases where attr_accessible is commented out.
@@ -48,17 +48,17 @@ def attr_accessible?
true
end
end
-
+
# Returnt true if a model does not define attr_accessible.
def problem?
not attr_accessible?
end
-
+
# Return true if a line has a problem model (no attr_accessible).
def problem_model?
mass_assignment_models.find { |model| model.problem? }
end
-
+
# Return true if a controller string has a (likely) mass assignment problem.
# This is true if at least one of the controller's lines
# (1) Has a likely mass assignment
@@ -67,9 +67,9 @@ def mass_assignment_problem?
File.open(self).find { |l| l.mass_assignment? and l.problem_model? }
end
end
-
+
module MassAssignment
-
+
def self.print_mass_assignment_problems(controller)
lines = File.open(controller)
lines.each_with_index do |line, number|
@@ -78,7 +78,7 @@ def self.print_mass_assignment_problems(controller)
end
end
end
-
+
def self.find
controllers = Dir.glob("#{Rails.root.to_s}/app/controllers/*_controller.rb")
controllers.each do |controller|
@@ -88,4 +88,4 @@ def self.find
end
end
end
-end
+end
View
3  lib/limerick_rake.rb
@@ -0,0 +1,3 @@
+module LimerickRake
+ require 'limerick_rake/engine' if defined?(Rails)
+end
View
6 lib/limerick_rake/engine.rb
@@ -0,0 +1,6 @@
+module LimerickRake
+
+ class Engine < Rails::Engine
+ end
+
+end
View
2  tasks/backup.rake → lib/tasks/backup.rake
@@ -15,7 +15,7 @@ namespace :backup do
raise RuntimeError, "I only work with mysql." unless config['adapter'] == 'mysql'
raise RuntimeError, "Cannot find mysqldump." if mysqldump.blank?
-
+
FileUtils.mkdir_p backupdir
`#{mysqldump} #{options} #{config['database']} > #{filepath}`
puts "#{config['database']} => #{filepath}"
View
0  tasks/coverage.rake → lib/tasks/coverage.rake
File renamed without changes
View
0  tasks/db/bootstrap.rake → lib/tasks/db/bootstrap.rake
File renamed without changes
View
2  tasks/db/indexes.rake → lib/tasks/db/indexes.rake
@@ -19,4 +19,4 @@ namespace :db do
end
end
end
-end
+end
View
4 lib/tasks/db/recreate.rake
@@ -0,0 +1,4 @@
+ namespace :db do
+ desc "Recreate database. Drop, create, migrate and seed it."
+ task :recreate => [:drop, :create, :migrate, :seed]
+ end
View
9 tasks/db/shell.rake → lib/tasks/db/shell.rake
@@ -13,11 +13,14 @@ namespace :db do
command << "--password=#{config['password'] || ''} "
command << config['database']
when 'postgresql'
- puts 'You should consider switching to MySQL or get off your butt and submit a patch'
+ command << "psql "
+ command << "-h #{config['host'] || 'localhost'} "
+ command << "-p #{config['port'] || 5432} "
+ command << "-U #{config['username'] || 'postgres'} "
+ command << "\"dbname=#{config['database']} password=#{config['password']}\""
else
command << "echo Unsupported database adapter: #{config['adapter']}"
end
-
system command
end
-end
+end
View
2  tasks/db/validate_models.rake → lib/tasks/db/validate_models.rake
@@ -8,7 +8,7 @@ namespace :db do
require file
end
end
-
+
Object.subclasses_of(ActiveRecord::Base).select { |c| c.base_class == c}.sort_by(&:name).each do |klass|
next if klass.name == "CGI::Session::ActiveRecordStore::Session"
invalid_count = 0
View
4 tasks/find_mass_assignment_tasks.rake → lib/tasks/find_mass_assignment_tasks.rake
@@ -1,5 +1,5 @@
desc "Find potential mass assignment vulnerabilities"
task :find_mass_assignment do
- require File.join(File.dirname(__FILE__), "../lib/find_mass_assignment.rb")
+ require File.join(File.dirname(__FILE__), '../../lib/find_mass_assignment.rb')
MassAssignment.find
-end
+end
View
36 tasks/git.rake → lib/tasks/git.rake
@@ -1,35 +1,35 @@
module GitCommands
class ShellError < RuntimeError; end
-
+
@logging = ENV['LOGGING'] != "false"
-
+
def self.run cmd, *expected_exitstatuses
puts "+ #{cmd}" if @logging
output = `#{cmd} 2>&1`
puts output.gsub(/^/, "- ") if @logging
expected_exitstatuses << 0 if expected_exitstatuses.empty?
raise ShellError.new("ERROR: '#{cmd}' failed with exit status #{$?.exitstatus}") unless
- [expected_exitstatuses].flatten.include?( $?.exitstatus )
+ [expected_exitstatuses].flatten.include?( $?.exitstatus )
output
end
-
+
def self.current_branch
run("git branch --no-color | grep '*' | cut -d ' ' -f 2").chomp
end
-
+
def self.remote_branch_exists?(branch)
! run("git branch -r --no-color | grep '#{branch}'").blank?
end
-
+
def self.ensure_clean_working_directory!
return if run("git status", 0, 1).match(/working directory clean/)
raise "Must have clean working directory"
end
-
+
def self.diff_staging
puts run("git diff HEAD origin/staging")
end
-
+
def self.diff_production
puts run("git diff origin/staging origin/production")
end
@@ -45,15 +45,15 @@ module GitCommands
raise
end
end
-
+
def self.push_staging
push(current_branch, "staging")
end
-
+
def self.push_production
push("origin/staging", "production")
end
-
+
def self.branch_production(branch)
raise "You must specify a branch name." if branch.blank?
ensure_clean_working_directory!
@@ -61,45 +61,45 @@ module GitCommands
run "git branch -f #{branch} origin/production"
run "git checkout #{branch}"
end
-
+
def self.pull_template
ensure_clean_working_directory!
run "git pull git://github.com/thoughtbot/suspenders.git master"
end
end
-
+
namespace :git do
namespace :push do
desc "Reset origin's staging branch to be the current branch."
task :staging do
GitCommands.push_staging
end
-
+
desc "Reset origin's production branch to origin's staging branch."
task :production do
GitCommands.push_production
end
end
-
+
namespace :diff do
desc "Show the difference between current branch and origin/staging."
task :staging do
GitCommands.diff_staging
end
-
+
desc "Show the difference between origin/staging and origin/production."
task :production do
GitCommands.diff_production
end
end
-
+
namespace :pull do
desc "Pull updates from suspenders, the thoughtbot rails template."
task :suspenders do
GitCommands.pull_template
end
end
-
+
namespace :branch do
desc "Branch origin/production into BRANCH locally."
task :production do
View
5 tasks/haml_sass.rake → lib/tasks/haml_sass.rake
@@ -39,7 +39,7 @@ namespace :sass do
convert_sass_to_css basename
end
end
-
+
desc "Convert all Sass files to CSS."
task :all_sass2css => :environment do
files = Dir.entries(@sass_dir).find_all do |f|
@@ -65,7 +65,7 @@ namespace :haml do
controllers.each do |controller|
files = Dir.entries("#{@views_dir}/#{controller}").find_all do |f|
(File.new("#{@views_dir}/#{controller}/#{f}").path.include?(".html.erb") ||
- File.new("#{@views_dir}/#{controller}/#{f}").path.include?(".rhtml")) &&
+ File.new("#{@views_dir}/#{controller}/#{f}").path.include?(".rhtml")) &&
File.basename("#{@views_dir}/#{controller}/#{f}") !~ /^[.]/
end
files.each do |filename|
@@ -75,4 +75,3 @@ namespace :haml do
end
end
end
-
View
2  tasks/rails_two.rake → lib/tasks/rails_two.rake
@@ -17,4 +17,4 @@ namespace :rails_two do
puts `git mv #{file} #{file.gsub(/\.haml$/, '.html.haml')}`
end
end
-end
+end
View
6 tasks/svn.rake → lib/tasks/svn.rake
@@ -3,17 +3,17 @@
namespace :svn do
desc "Adds all files with an svn status flag of '?'"
task(:add) { system %q(svn status | awk '/\\?/ {print $2}' | xargs svn add) }
-
+
desc "Deletes all files with an svn status flag of '!'"
task(:delete) { system %q(svn status | awk '/\\!/ {print $2}' | xargs svn delete) }
-
+
desc "Writes the log file to doc/svn_log.txt"
task(:log) do
File.delete("#{Rails.root.to_s}/doc/svn_log.txt") if File::exists?("#{Rails.root.to_s}/doc/svn_log.txt")
File.new("#{Rails.root.to_s}/doc/svn_log.txt", "w+")
system("svn log >> doc/svn_log.txt")
end
-
+
desc 'Updates svn:ignore from .svnignore'
task(:update_svn_ignore) do
system %q(svn propset svn:ignore -F .svnignore .)
View
20 limerick_rake.gemspec
@@ -8,13 +8,15 @@ Gem::Specification.new do |s|
s.description = "A collection of useful rake tasks."
s.authors = ["the Ruby community", "thoughtbot, inc."]
s.files = ["README.textile",
+ "MIT-LICENSE",
"limerick_rake.gemspec",
- "tasks/backup.rake",
- "tasks/db/bootstrap.rake",
- "tasks/db/indexes.rake",
- "tasks/db/shell.rake",
- "tasks/db/validate_models.rake",
- "tasks/git.rake",
- "tasks/haml_sass.rake",
- "tasks/svn.rake"]
-end
+ "lib/tasks/backup.rake",
+ "lib/tasks/db/bootstrap.rake",
+ "lib/tasks/db/indexes.rake",
+ "lib/tasks/db/shell.rake",
+ "lib/tasks/db/validate_models.rake",
+ "lib/tasks/git.rake",
+ "lib/tasks/haml_sass.rake",
+ "lib/tasks/svn.rake"
+ ]
+end
Something went wrong with that request. Please try again.