Skip to content
Browse files

adding support for passing block to scope_builder

  • Loading branch information...
1 parent ca93190 commit 5d7c4048eb1babec9b930f9b21250e9b99d0987b @ryanb committed Jun 26, 2008
Showing with 68 additions and 3 deletions.
  1. +3 −2 Manifest
  2. +3 −1 lib/scope_builder/model_additions.rb
  3. +58 −0 scope-builder.gemspec
  4. +4 −0 spec/scope_builder/builder_spec.rb
View
5 Manifest
@@ -3,11 +3,12 @@ lib/scope_builder/builder.rb
lib/scope_builder/model_additions.rb
lib/scope_builder.rb
LICENSE
+Manifest
README
+spec/models/product.rb
spec/scope_builder/builder_spec.rb
-spec/scope_builder/model_additions_spec.rb
spec/spec_helper.rb
+spec/test.sqlite3
tasks/deployment.rake
tasks/spec.rake
TODO
-Manifest
View
4 lib/scope_builder/model_additions.rb
@@ -1,7 +1,9 @@
module ScopeBuilder
module ModelAdditions
def scope_builder
- Builder.new(scoped({}))
+ builder = Builder.new(scoped({}))
+ yield(builder) if block_given?
+ builder
end
end
end
View
58 scope-builder.gemspec
@@ -0,0 +1,58 @@
+
+# Gem::Specification for Scope-builder-0.1.0
+# Originally generated by Echoe
+
+Gem::Specification.new do |s|
+ s.name = %q{scope-builder}
+ s.version = "0.1.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Ryan Bates"]
+ s.date = %q{2008-06-26}
+ s.description = %q{Build up named scopes conditionally.}
+ s.email = %q{ryan (at) railscasts (dot) com}
+ s.extra_rdoc_files = ["CHANGELOG", "lib/scope_builder/builder.rb", "lib/scope_builder/model_additions.rb", "lib/scope_builder.rb", "LICENSE", "README", "tasks/deployment.rake", "tasks/spec.rake", "TODO"]
+ s.files = ["CHANGELOG", "lib/scope_builder/builder.rb", "lib/scope_builder/model_additions.rb", "lib/scope_builder.rb", "LICENSE", "Manifest", "README", "spec/models/product.rb", "spec/scope_builder/builder_spec.rb", "spec/spec_helper.rb", "spec/test.sqlite3", "tasks/deployment.rake", "tasks/spec.rake", "TODO", "scope-builder.gemspec"]
+ s.has_rdoc = true
+ s.homepage = %q{http://github.com/ryanb/scope-builder}
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Scope-builder", "--main", "README"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = %q{scope-builder}
+ s.rubygems_version = %q{1.2.0}
+ s.summary = %q{Build up named scopes conditionally.}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 2
+
+ if current_version >= 3 then
+ else
+ end
+ else
+ end
+end
+
+
+# # Original Rakefile source (requires the Echoe gem):
+#
+# require 'rubygems'
+# require 'rake'
+#
+# begin
+# require 'echoe'
+#
+# Echoe.new('scope-builder', '0.1.0') do |p|
+# p.summary = "Build up named scopes conditionally."
+# p.description = "Build up named scopes conditionally."
+# p.url = "http://github.com/ryanb/scope-builder"
+# p.author = 'Ryan Bates'
+# p.email = "ryan (at) railscasts (dot) com"
+# p.ignore_pattern = ["script/*"]
+# end
+#
+# rescue LoadError => boom
+# puts "You are missing a dependency required for meta-operations on this gem."
+# puts "#{boom.to_s.capitalize}."
+# end
+#
+# Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
View
4 spec/scope_builder/builder_spec.rb
@@ -43,4 +43,8 @@
it "should respond to enumerable methods like each_with_index" do
@builder.should respond_to(:each_with_index)
end
+
+ it "should be able to build up scope in block" do
+ Product.scope_builder { |b| b.released }.all.should == Product.released.all
+ end
end

0 comments on commit 5d7c404

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