scope_composer 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDFkNzg5MDA1MTI0Y2ViZTBjMDA3NjBlYTcyMTY5NmI5ZTg3ODYxZA==
4
+ OTJjNjcxMTFlZGY3OTAwMzE2MjRiMjZlNzcwODA5YmZlODU3MTM0ZA==
5
5
  data.tar.gz: !binary |-
6
- Y2YwYTU0YTIxYjZmMjQzYzQwOTA2N2Q1MDIyY2RiNWUzYWQ1NTAxMw==
6
+ ODhiMTAzMTA3ZTQyOWY4M2U3ZjJlYWRiNzZjYjQwODgyOGM2ZjJlMw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OWI0MGZmMTcwNjFiNTBkMWMzZjA3OGU4MTJmYjVjMzNkMzQ2YjU0ODYzYjNj
10
- NTU2OTY1ZTEyZDEwMGM2YTgxMjY3NjUxYzVhMzQ0MTUwOWM1OWIxZGQ5Yjdj
11
- NWJjMzljNGU4NDgzOGMwNmU0YjQ5MjNkYmYyYThkNTNjNzUzMzI=
9
+ MDg5MjQ0OTA5MThkYmNiOTU3NjJkYWMwNjA4ZTcyMDk2NWM3NjcxOTVmZTAy
10
+ YWIwN2Y0Y2E0Yjg5Y2VlNDE1YWU3MzhjYmNhYWFjZjAyMzkyNjM4NWMyYjA0
11
+ MmJjMWQ3ODQ0YmVhY2E0NzcxYmY1OTFmOTBiZGFiZWRlNGFmOGI=
12
12
  data.tar.gz: !binary |-
13
- Mzk0NDBmZDRjODI4OTAzZjk2NzdjNjg0MzA1MWRhZjk5NzVhMzc0ZWEwNzk0
14
- M2EzNmE0ZTdlYmRmOTRmZjIyYzljMGUzNTBlYmUxOTdkMWE3ODVlNjAxMjFm
15
- ZjFlNDRkMGM2NGJlMDY2OGU0MDZhZjBhYjdmN2I1ZDgxNGE1YjI=
13
+ MTk5M2I3MmFjMTFiNDBjNmY0NDY2MTFkMzllN2VjODk5NGRlZGY2NzNiZGI2
14
+ Yzg3ZDVlYjAwNzY1YzdmMTYxMjg4Mzg5MzkxYTkzN2FmZDMxZWNhNjU5YzMy
15
+ MGZmZTEwODkxMGViZDYzNmM0ODk5MWRkNWZkMDhhYThhZjVkNTI=
data/UPGRADE.md CHANGED
@@ -1,8 +1,12 @@
1
+ ## 0.3.0
2
+
3
+ * it stores scope_attributes seperately from attributes
4
+
1
5
  ## 0.2.0
2
6
 
3
- subject#where should return self
7
+ * subject#where should return self
4
8
 
5
9
 
6
10
  ## 0.1.0
7
11
 
8
- Initial
12
+ * Initial
@@ -92,7 +92,7 @@ class Scope
92
92
  # define method
93
93
  define_method(name) do |*args|
94
94
  # if no value is given, act as a getter and retrieve the value
95
- return attributes[name] if args.first.nil?
95
+ return scope_attributes[name] if args.first.nil?
96
96
  # otherwise set the value
97
97
  instance_exec(*args, &proc)
98
98
  # and return self for chaining
@@ -118,9 +118,9 @@ class Scope
118
118
  # init
119
119
  value = args.first
120
120
  # if no value is given, act as a getter
121
- return attributes[name] if value.nil?
121
+ return scope_attributes[name] if value.nil?
122
122
  # otherwise set the value
123
- where( name => value )
123
+ scope_attributes[name] = value
124
124
  # and return self for chaining
125
125
  return self
126
126
  end
@@ -161,5 +161,9 @@ class Scope
161
161
  @attributes = self.attributes.merge(attrs)
162
162
  end
163
163
 
164
+ def scope_attributes
165
+ @scope_attributes ||= {}
166
+ end
167
+
164
168
  end
165
169
  end
@@ -1,3 +1,3 @@
1
1
  module ScopeComposer
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -2,24 +2,24 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe ScopeComposer::Model do
5
- subject do
6
- class TestClass
7
- include ScopeComposer::Model
8
-
9
- has_scope_composer
10
- scope :say_hi, ->(t){ 'hi' }
11
- scope_helper :helper_method, ->(t){ 'hi' }
12
-
13
- scope_composer_for :search
14
-
15
- search_scope :limit
16
- search_scope :offset, prefix: true
17
- search_helper :tester, ->(t){ t.to_i }
18
-
19
- end
20
- TestClass
5
+
6
+ class ScopeComposerModelTest
7
+ include ScopeComposer::Model
8
+
9
+ has_scope_composer
10
+ scope :say_hi, ->(t){ 'hi' }
11
+ scope_helper :helper_method, ->(t){ 'hi' }
12
+
13
+ scope_composer_for :search
14
+ search_scope :limit
15
+ search_scope :offset, prefix: true
16
+ search_helper :tester, ->(t){ t.to_i }
17
+
21
18
  end
22
19
 
20
+ let(:scope){ ScopeComposerModelTest }
21
+ subject{ scope }
22
+
23
23
  it { should respond_to :scope_composer_for }
24
24
  it { should respond_to :scope_scope }
25
25
  it { should respond_to :scope }
@@ -32,12 +32,29 @@ describe ScopeComposer::Model do
32
32
  it { should_not respond_to :tester }
33
33
 
34
34
  it "should define a scope helper" do
35
- TestClass.say_hi('hi').should respond_to :helper_method
35
+ ScopeComposerModelTest.say_hi('hi').should respond_to :helper_method
36
+ end
37
+
38
+ describe ".search_scope" do
39
+ let(:scope){ ScopeComposerModelTest.search_scope.new }
40
+ subject{ scope }
41
+ before(:each){ scope.limit(10) }
42
+
43
+ its(:scope_attributes){ should eq({ limit: 10 }) }
44
+ its(:attributes){ should eq({}) }
45
+
46
+ describe "#where" do
47
+ before(:each){ scope.where( id: 20 ) }
48
+
49
+ its(:scope_attributes){ should eq({ limit: 10 }) }
50
+ its(:attributes){ should eq({ id: 20 }) }
51
+ end
52
+
36
53
  end
37
54
 
38
- describe "#where" do
55
+ describe ".scope" do
39
56
  it "should return self" do
40
- subject.limit(1).where( id: 1 ).class.should eq TestClass::SearchScope
57
+ subject.limit(1).where( id: 1 ).class.should eq ScopeComposerModelTest::SearchScope
41
58
  end
42
59
  end
43
60
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scope_composer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hilscher