wvanbergen / scoped_search

Easily search you ActiveRecord models with a simple query language using a named scope.

This URL has Read+Write access

scoped_search / Rakefile
100644 70 lines (54 sloc) 2.27 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'rubygems'
 
load 'test/tasks.rake'
 
desc 'Default: run unit tests.'
task :default => :test
 
namespace :gem do
 
  desc "Sets the version and date of the scoped_search gem. Requires the VERSION environment variable."
  task :version => [:manifest] do
    
    require 'date'
    
    new_version = ENV['VERSION']
    raise "VERSION is required" unless /\d+(\.\d+)*/ =~ new_version
    
    spec_file = Dir['*.gemspec'].first
    
    spec = File.read(spec_file)
    spec.gsub!(/^(\s*s\.version\s*=\s*)('|")(.+)('|")(\s*)$/) { "#{$1}'#{new_version}'#{$5}" }
    spec.gsub!(/^(\s*s\.date\s*=\s*)('|")(.+)('|")(\s*)$/) { "#{$1}'#{Date.today.strftime('%Y-%m-%d')}'#{$5}" }
    File.open(spec_file, 'w') { |f| f << spec }
  end
  
  task :tag => [:version] do
    
    new_version = ENV['VERSION']
    raise "VERSION is required" unless /\d+(\.\d+)*/ =~ new_version
        
    sh "git add scoped_search.gemspec .manifest"
    sh "git commit -m \"Set gem version to #{new_version}\""
    sh "git push origin"
    sh "git tag -a \"scoped_search-#{new_version}\" -m \"Tagged version #{new_version}\""
    sh "git push --tags"
  end
 
  desc "Builds a ruby gem for scoped_search"
  task :build => [:manifest] do
    system %[gem build scoped_search.gemspec]
  end
 
  desc %{Update ".manifest" with the latest list of project filenames. Respect\
.gitignore by excluding everything that git ignores. Update `files` and\
`test_files` arrays in "*.gemspec" file if it's present.}
  task :manifest do
    list = Dir['**/*'].sort
    spec_file = Dir['*.gemspec'].first
    list -= [spec_file] if spec_file
  
    File.read('.gitignore').each_line do |glob|
      glob = glob.chomp.sub(/^\//, '')
      list -= Dir[glob]
      list -= Dir["#{glob}/**/*"] if File.directory?(glob) and !File.symlink?(glob)
      puts "excluding #{glob}"
    end
 
    if spec_file
      spec = File.read spec_file
      spec.gsub! /^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx do
        assignment = $1
        bunch = $2 ? list.grep(/^test.*_test\.rb$/) : list
        '%s%%w(%s)' % [assignment, bunch.join(' ')]
      end
      
      File.open(spec_file, 'w') {|f| f << spec }
    end
    File.open('.manifest', 'w') {|f| f << list.join("\n") }
  end
end