ryanb-scope-builder 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +4 -0
- data/Manifest +1 -3
- data/lib/scope_builder/model_additions.rb +8 -0
- data/lib/scope_builder.rb +0 -1
- data/scope-builder.gemspec +13 -20
- data/spec/models/category.rb +15 -0
- data/spec/models/product.rb +2 -0
- data/spec/scope_builder/builder_spec.rb +18 -0
- data/spec/spec_helper.rb +4 -2
- metadata +3 -7
- data/TODO +0 -0
- data/lib/scope_builder/scope_additions.rb +0 -13
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
lib/scope_builder/builder.rb
|
3
3
|
lib/scope_builder/model_additions.rb
|
4
|
-
lib/scope_builder/scope_additions.rb
|
5
4
|
lib/scope_builder.rb
|
6
5
|
LICENSE
|
7
6
|
Manifest
|
8
7
|
README
|
9
8
|
scope-builder.gemspec
|
9
|
+
spec/models/category.rb
|
10
10
|
spec/models/product.rb
|
11
11
|
spec/scope_builder/builder_spec.rb
|
12
12
|
spec/spec_helper.rb
|
13
|
-
spec/test.sqlite3
|
14
13
|
tasks/deployment.rake
|
15
14
|
tasks/spec.rake
|
16
|
-
TODO
|
@@ -11,3 +11,11 @@ end
|
|
11
11
|
class ActiveRecord::Base
|
12
12
|
extend ScopeBuilder::ModelAdditions
|
13
13
|
end
|
14
|
+
|
15
|
+
class ActiveRecord::Associations::AssociationProxy
|
16
|
+
include ScopeBuilder::ModelAdditions
|
17
|
+
end
|
18
|
+
|
19
|
+
class ActiveRecord::NamedScope::Scope
|
20
|
+
include ScopeBuilder::ModelAdditions
|
21
|
+
end
|
data/lib/scope_builder.rb
CHANGED
data/scope-builder.gemspec
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Scope-builder-0.1.
|
2
|
+
# Gem::Specification for Scope-builder-0.1.2
|
3
3
|
# Originally generated by Echoe
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = %q{scope-builder}
|
7
|
-
s.version = "0.1.
|
7
|
+
s.version = "0.1.2"
|
8
8
|
|
9
9
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
10
|
s.authors = ["Ryan Bates"]
|
11
|
-
s.date = %q{2008-
|
11
|
+
s.date = %q{2008-08-28}
|
12
12
|
s.description = %q{Build up named scopes conditionally.}
|
13
13
|
s.email = %q{ryan (at) railscasts (dot) com}
|
14
|
-
s.extra_rdoc_files = ["CHANGELOG", "lib/scope_builder/builder.rb", "lib/scope_builder/model_additions.rb", "lib/scope_builder
|
15
|
-
s.files = ["CHANGELOG", "lib/scope_builder/builder.rb", "lib/scope_builder/model_additions.rb", "lib/scope_builder
|
14
|
+
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"]
|
15
|
+
s.files = ["CHANGELOG", "lib/scope_builder/builder.rb", "lib/scope_builder/model_additions.rb", "lib/scope_builder.rb", "LICENSE", "Manifest", "README", "scope-builder.gemspec", "spec/models/category.rb", "spec/models/product.rb", "spec/scope_builder/builder_spec.rb", "spec/spec_helper.rb", "tasks/deployment.rake", "tasks/spec.rake"]
|
16
16
|
s.has_rdoc = true
|
17
17
|
s.homepage = %q{http://github.com/ryanb/scope-builder}
|
18
18
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Scope-builder", "--main", "README"]
|
@@ -37,22 +37,15 @@ end
|
|
37
37
|
#
|
38
38
|
# require 'rubygems'
|
39
39
|
# require 'rake'
|
40
|
-
#
|
41
|
-
# begin
|
42
|
-
# require 'echoe'
|
40
|
+
# require 'echoe'
|
43
41
|
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
# end
|
52
|
-
#
|
53
|
-
# rescue LoadError => boom
|
54
|
-
# puts "You are missing a dependency required for meta-operations on this gem."
|
55
|
-
# puts "#{boom.to_s.capitalize}."
|
42
|
+
# Echoe.new('scope-builder', '0.1.2') do |p|
|
43
|
+
# p.summary = "Build up named scopes conditionally."
|
44
|
+
# p.description = "Build up named scopes conditionally."
|
45
|
+
# p.url = "http://github.com/ryanb/scope-builder"
|
46
|
+
# p.author = 'Ryan Bates'
|
47
|
+
# p.email = "ryan (at) railscasts (dot) com"
|
48
|
+
# p.ignore_pattern = ["script/*", "**/*.sqlite3"]
|
56
49
|
# end
|
57
50
|
#
|
58
51
|
# Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Category < ActiveRecord::Base
|
2
|
+
has_many :products
|
3
|
+
end
|
4
|
+
|
5
|
+
class CreateCategories < ActiveRecord::Migration
|
6
|
+
def self.up
|
7
|
+
create_table :categories do |t|
|
8
|
+
t.string :name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
drop_table :categories
|
14
|
+
end
|
15
|
+
end
|
data/spec/models/product.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
class Product < ActiveRecord::Base
|
2
2
|
named_scope :released, :conditions => ['released=?', true]
|
3
|
+
belongs_to :category
|
3
4
|
end
|
4
5
|
|
5
6
|
class CreateProducts < ActiveRecord::Migration
|
@@ -7,6 +8,7 @@ class CreateProducts < ActiveRecord::Migration
|
|
7
8
|
create_table :products do |t|
|
8
9
|
t.string :name
|
9
10
|
t.boolean :released
|
11
|
+
t.integer :category_id
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
@@ -52,4 +52,22 @@ describe ScopeBuilder::Builder do
|
|
52
52
|
builder = Product.released.scope_builder
|
53
53
|
builder.all.should == Product.released.all
|
54
54
|
end
|
55
|
+
|
56
|
+
describe "products in category" do
|
57
|
+
before(:each) do
|
58
|
+
Category.delete_all
|
59
|
+
@category = Category.create!(:products => Product.find_all_by_name(['a', 'b']))
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should work on named scope through association" do
|
63
|
+
builder = @category.products.released.scope_builder
|
64
|
+
builder.all.should == @category.products.released.all
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should work directly on assocation" do
|
68
|
+
builder = @category.products.scope_builder
|
69
|
+
builder.released
|
70
|
+
builder.all.should == @category.products.released.all
|
71
|
+
end
|
72
|
+
end
|
55
73
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,13 +6,15 @@ require File.dirname(__FILE__) + '/../lib/scope_builder.rb'
|
|
6
6
|
|
7
7
|
# setup database adapter
|
8
8
|
ActiveRecord::Base.establish_connection({
|
9
|
-
:adapter => "sqlite3",
|
10
|
-
:dbfile => File.dirname(__FILE__) + "/test.sqlite3"
|
9
|
+
:adapter => "sqlite3",
|
10
|
+
:dbfile => File.dirname(__FILE__) + "/test.sqlite3"
|
11
11
|
})
|
12
12
|
|
13
13
|
# load models
|
14
14
|
# there's probably a better way to handle this
|
15
|
+
require File.dirname(__FILE__) + '/models/category.rb'
|
15
16
|
require File.dirname(__FILE__) + '/models/product.rb'
|
17
|
+
CreateCategories.migrate(:up) unless Category.table_exists?
|
16
18
|
CreateProducts.migrate(:up) unless Product.table_exists?
|
17
19
|
|
18
20
|
Spec::Runner.configure do |config|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ryanb-scope-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Bates
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-08-28 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -23,30 +23,26 @@ extra_rdoc_files:
|
|
23
23
|
- CHANGELOG
|
24
24
|
- lib/scope_builder/builder.rb
|
25
25
|
- lib/scope_builder/model_additions.rb
|
26
|
-
- lib/scope_builder/scope_additions.rb
|
27
26
|
- lib/scope_builder.rb
|
28
27
|
- LICENSE
|
29
28
|
- README
|
30
29
|
- tasks/deployment.rake
|
31
30
|
- tasks/spec.rake
|
32
|
-
- TODO
|
33
31
|
files:
|
34
32
|
- CHANGELOG
|
35
33
|
- lib/scope_builder/builder.rb
|
36
34
|
- lib/scope_builder/model_additions.rb
|
37
|
-
- lib/scope_builder/scope_additions.rb
|
38
35
|
- lib/scope_builder.rb
|
39
36
|
- LICENSE
|
40
37
|
- Manifest
|
41
38
|
- README
|
42
39
|
- scope-builder.gemspec
|
40
|
+
- spec/models/category.rb
|
43
41
|
- spec/models/product.rb
|
44
42
|
- spec/scope_builder/builder_spec.rb
|
45
43
|
- spec/spec_helper.rb
|
46
|
-
- spec/test.sqlite3
|
47
44
|
- tasks/deployment.rake
|
48
45
|
- tasks/spec.rake
|
49
|
-
- TODO
|
50
46
|
has_rdoc: true
|
51
47
|
homepage: http://github.com/ryanb/scope-builder
|
52
48
|
post_install_message:
|
data/TODO
DELETED
File without changes
|