Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 4 commits
  • 10 files changed
  • 0 commit comments
  • 1 contributor
View
13 .travis.yml
@@ -0,0 +1,13 @@
+language: ruby
+bundler_args: --without development --standalone
+rvm:
+ - 1.8.7
+ - 1.9.2
+ - 1.9.3
+gemfile:
+ - ci/Gemfile.ar3.1
+ - ci/Gemfile.ar-edge
+matrix:
+ exclude:
+ - rvm: 1.8.7
+ gemfile: ci/Gemfile.ar-edge
View
2 Gemfile
@@ -1,2 +1,2 @@
-source :rubygems
+source 'https://rubygems.org'
gemspec
View
7 README.md
@@ -6,7 +6,7 @@ SexyScopes
* [Source Code](https://github.com/samleb/sexy_scopes)
* [Rubygem](http://rubygems.org/gems/sexy_scopes)
-SexyScopes is a gem that adds syntactic sugar for creating scopes in Rails 3.
+SexyScopes is a gem that adds syntactic sugar for creating scopes in ActiveRecord >= 3.1.
Usage & Examples
----------------
@@ -61,13 +61,12 @@ Here is a complete list of Arel method aliases:
* For predicates:
- `==`: `eq`
- `=~`: `matches`
- - `!~`: `does_not_match`
+ - `!~`: `does_not_match` (won't work in Ruby 1.8)
- `>=`: `gteq`
- `>` : `gt`
- `<` : `lt`
- `<=`: `lteq`
- - `!=`: `not_eq`
-
+ - `!=`: `not_eq` (won't work in Ruby 1.8)
* For combination
- `&`: `and`
View
8 ci/Gemfile.ar-edge
@@ -0,0 +1,8 @@
+source 'https://rubygems.org'
+
+gem 'activerecord', :github => 'rails/rails', :branch => 'master'
+
+gem 'rake', '~> 0.9'
+gem 'rspec', '~> 2.0'
+gem 'sqlite3', '~> 1.0'
+
View
7 ci/Gemfile.ar3.0
@@ -0,0 +1,7 @@
+source 'https://rubygems.org'
+
+gem 'activerecord', '~> 3.0.0'
+
+gem 'rake', '~> 0.9'
+gem 'rspec', '~> 2.0'
+gem 'sqlite3', '~> 1.0'
View
7 ci/Gemfile.ar3.1
@@ -0,0 +1,7 @@
+source 'https://rubygems.org'
+
+gem 'activerecord', '~> 3.1.0'
+
+gem 'rake', '~> 0.9'
+gem 'rspec', '~> 2.0'
+gem 'sqlite3', '~> 1.0'
View
11 lib/sexy_scopes/arel/predicate_methods.rb
@@ -1,6 +1,13 @@
module SexyScopes
module Arel
module PredicateMethods
+ class << self
+ private
+ def ruby_19_alias(new_name, old_name)
+ class_eval "alias #{new_name} #{old_name}" if RUBY_VERSION >= "1.9"
+ end
+ end
+
def eq(other)
extend_predicate(super)
end
@@ -18,7 +25,7 @@ def matches(other)
def does_not_match(other)
extend_predicate(super)
end
- alias !~ does_not_match
+ ruby_19_alias '!~', 'does_not_match'
def gteq(other)
extend_predicate(super)
@@ -43,7 +50,7 @@ def lteq(other)
def not_eq(other)
extend_predicate(super)
end
- alias != not_eq
+ ruby_19_alias '!=', 'not_eq'
end
end
end
View
4 sexy_scopes.gemspec
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
gem.version = SexyScopes::VERSION
gem.summary = %{Write beautiful and expressive ActiveRecord scopes without SQL.}
- gem.description = %{Small DSL to create ActiveRecord (>= 3) attribute predicates without writing SQL.}
+ gem.description = %{Small DSL to create ActiveRecord (>= 3.1) attribute predicates without writing SQL.}
gem.authors = ['Samuel Lebeau']
gem.email = 'samuel.lebeau@gmail.com'
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
gem.licenses = ['MIT']
- gem.add_dependency 'activerecord', '~> 3.0'
+ gem.add_dependency 'activerecord', '~> 3.1'
gem.add_development_dependency 'bundler', '~> 1.0'
gem.add_development_dependency 'rake', '~> 0.9'
View
10 spec/predicate_methods_spec.rb
@@ -5,6 +5,8 @@
@attribute = User.attribute(:score)
end
+ RUBY_19_METHODS = %w( != !~ )
+
METHODS = {
# Arel method => [ Ruby operator, SQL operator ]
:eq => [ '==', '= %s' ],
@@ -28,9 +30,11 @@
it { should convert_to_sql %{"users"."score" #{sql_operator % 42.0}} }
- it "is aliased as `#{operator}`" do
- @attribute.method(operator).should == @attribute.method(method)
- end if operator
+ if operator && (!RUBY_19_METHODS.include?(operator) || ruby_19?)
+ it "is aliased as `#{operator}`" do
+ @attribute.method(operator).should == @attribute.method(method)
+ end
+ end
end
end
end
View
6 spec/spec_helper.rb
@@ -10,7 +10,11 @@
RSpec.configure do |config|
config.extend Module.new {
def ruby_19
- yield if RUBY_VERSION >= "1.9"
+ yield if ruby_19?
+ end
+
+ def ruby_19?
+ RUBY_VERSION >= "1.9"
end
}
end

No commit comments for this range

Something went wrong with that request. Please try again.