Skip to content
Browse files

Updated docs. Fixed Ruby 1.9 compatibility issues

  • Loading branch information...
1 parent e554be6 commit 2dc2870cd4fa11ab1e661db37ad23f2e5ba33d86 @dim dim committed Jul 1, 2011
View
2 Gemfile
@@ -9,5 +9,5 @@ group :test do
gem "rspec"
gem "rspec-rails", :require => false
gem "sqlite3-ruby"
- gem "shoulda", "~> 3.0.0.beta"
+ gem "shoulda-matchers"
end
View
70 Gemfile.lock
@@ -2,66 +2,64 @@ GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
- actionpack (3.0.4)
- activemodel (= 3.0.4)
- activesupport (= 3.0.4)
+ actionpack (3.0.9)
+ activemodel (= 3.0.9)
+ activesupport (= 3.0.9)
builder (~> 2.1.2)
erubis (~> 2.6.6)
- i18n (~> 0.4)
+ i18n (~> 0.5.0)
rack (~> 1.2.1)
- rack-mount (~> 0.6.13)
+ rack-mount (~> 0.6.14)
rack-test (~> 0.5.7)
tzinfo (~> 0.3.23)
- activemodel (3.0.4)
- activesupport (= 3.0.4)
+ activemodel (3.0.9)
+ activesupport (= 3.0.9)
builder (~> 2.1.2)
- i18n (~> 0.4)
- activerecord (3.0.4)
- activemodel (= 3.0.4)
- activesupport (= 3.0.4)
- arel (~> 2.0.2)
+ i18n (~> 0.5.0)
+ activerecord (3.0.9)
+ activemodel (= 3.0.9)
+ activesupport (= 3.0.9)
+ arel (~> 2.0.10)
tzinfo (~> 0.3.23)
- activesupport (3.0.4)
- arel (2.0.8)
+ activesupport (3.0.9)
+ arel (2.0.10)
builder (2.1.2)
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
i18n (0.5.0)
- rack (1.2.1)
- rack-mount (0.6.13)
+ rack (1.2.3)
+ rack-mount (0.6.14)
rack (>= 1.0.0)
rack-test (0.5.7)
rack (>= 1.0)
- railties (3.0.4)
- actionpack (= 3.0.4)
- activesupport (= 3.0.4)
+ railties (3.0.9)
+ actionpack (= 3.0.9)
+ activesupport (= 3.0.9)
rake (>= 0.8.7)
+ rdoc (~> 3.4)
thor (~> 0.14.4)
- rake (0.8.7)
- rspec (2.5.0)
- rspec-core (~> 2.5.0)
- rspec-expectations (~> 2.5.0)
- rspec-mocks (~> 2.5.0)
- rspec-core (2.5.1)
- rspec-expectations (2.5.0)
+ rake (0.9.2)
+ rdoc (3.8)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
diff-lcs (~> 1.1.2)
- rspec-mocks (2.5.0)
- rspec-rails (2.5.0)
+ rspec-mocks (2.6.0)
+ rspec-rails (2.6.1)
actionpack (~> 3.0)
activesupport (~> 3.0)
railties (~> 3.0)
- rspec (~> 2.5.0)
- shoulda (3.0.0.beta2)
- shoulda-context (~> 1.0.0.beta1)
- shoulda-matchers (~> 1.0.0.beta1)
- shoulda-context (1.0.0.beta1)
- shoulda-matchers (1.0.0.beta1)
+ rspec (~> 2.6.0)
+ shoulda-matchers (1.0.0.beta2)
sqlite3 (1.3.3)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
thor (0.14.6)
- tzinfo (0.3.24)
+ tzinfo (0.3.29)
PLATFORMS
ruby
@@ -73,5 +71,5 @@ DEPENDENCIES
activesupport
rspec
rspec-rails
- shoulda (~> 3.0.0.beta)
+ shoulda-matchers
sqlite3-ruby
View
9 README.markdown
@@ -10,9 +10,11 @@ Let's asume we have a model called Post, defined as:
In the simplest possible case you can define a few attributes and start filtering:
class Post < ActiveRecord::Base
+
constrainable do
fields :id, :author_id
end
+
end
# Examle request:
@@ -26,10 +28,12 @@ In the simplest possible case you can define a few attributes and start filterin
By default, only *eq* and *not_eq* operations are enabled, but there are plenty more:
class Post < ActiveRecord::Base
+
constrainable do
fields :id, :author_id, :with => [:in, :not_in, :gt, :gteq, :lt, :lteq]
fields :created_at, :with => [:between]
end
+
end
# Example request (various notations are accepted):
@@ -42,9 +46,11 @@ By default, only *eq* and *not_eq* operations are enabled, but there are plenty
Want to *alias* a column? Try this:
class Post < ActiveRecord::Base
+
constrainable do
timestamp :created, :using => :created_at, :with => [:lt, :lte, :between]
end
+
end
# Example request:
# GET /posts?where[created][lt]=2011-01-01
@@ -53,8 +59,9 @@ What about associations?
class Post < ActiveRecord::Base
belongs_to :author
+
constrainable do
- string :author_name, :using => lambda { Author.scoped.table[:name] }, :with => [:matches], :scope => lambda { includes(:author) }
+ string :author_name, :using => lambda { Author.arel_table[:name] }, :with => [:matches], :scope => lambda { includes(:author) }
end
end
# Example request:
View
4 lib/bsm/constrainable/field/base.rb
@@ -22,9 +22,9 @@ def self.kind
#
# Field::Integer.new :id
# Field::Integer.new :uid, :using => :id
- # Field::Integer.new :uid, :using => lambda { Model.scoped.table[:col_name] }
+ # Field::Integer.new :uid, :using => proc { Model.scoped.table[:col_name] }
# Field::String.new :name, :with => [:matches]
- # Field::String.new :author, :with => [:matches], :using => lambda { Author.scoped.table[:name] }, :scope => labmda { includes(:author) }
+ # Field::String.new :author, :with => [:matches], :using => proc { Author.scoped.table[:name] }, :scope => proc { includes(:author) }
#
def initialize(name, options = {})
@name = name.to_s
View
2 lib/bsm/constrainable/schema.rb
@@ -39,7 +39,7 @@ def fields(*names)
# match :created, :using => :created_at, :as => :timestamp, :with => [:lt, :between]
#
# # Complex example, using an attribute from another table, and ensure it's included (LEFT OUTER JOIN)
- # match :author, :using => lambda { Author.scope.table[:name] }, :scope => { includes(:author) }, :as => :string, :with => [:eq, :matches]
+ # match :author, :using => proc { Author.scope.table[:name] }, :scope => { includes(:author) }, :as => :string, :with => [:eq, :matches]
#
# There are also several short-cutrs available. Examples:
#
View
2 spec/bsm/constrainable/field/base_spec.rb
@@ -33,7 +33,7 @@ def merge(name, params = {})
it 'should allow using special attributes & clauses' do
integer(:using => :other).attribute.should == :other
- integer(:using => lambda { }).attribute.should be_a(Proc)
+ integer(:using => proc { }).attribute.should be_a(Proc)
end
it 'should convert inputs' do
View
4 spec/spec_helper.rb
@@ -60,10 +60,10 @@ class Post < ActiveRecord::Base
constrainable do
integer :id, :author_id, :with => [:in, :not_in]
timestamp :created, :using => :created_at, :with => [:gt, :lt, :between]
- match :author_name, :as => :string, :using => lambda { Author.scoped.table[:name] }, :scope => lambda { includes(:author) }
+ match :author_name, :as => :string, :using => proc { Author.scoped.table[:name] }, :scope => proc { includes(:author) }
string :category
end
- scope :articles, lambda { where(:category => "article") }
+ scope :articles, proc { where(:category => "article") }
end

0 comments on commit 2dc2870

Please sign in to comment.
Something went wrong with that request. Please try again.