liquid_stream 0.0.2 → 0.0.3
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +15 -0
- data/lib/liquid_stream/streams.rb +15 -2
- data/lib/liquid_stream/version.rb +1 -1
- data/spec/liquid_stream/streams_spec.rb +25 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6273d042d67ee818d165028563c77f2d97ff9a96
|
4
|
+
data.tar.gz: b33895f8647855e6529257646a6b7a7c3f88583c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3da6f7e939f3637d723c1bbf4807fecc6b7ff96ca2bbc151e1b4236a86a3c8b55c03eff0fa6e66b76ce1d4285b82424fcb36ff6d69b10d5108a7cd8e79334b0
|
7
|
+
data.tar.gz: 37d6f4de42207e39118ef4e80d316e61a8c8aa350fe7a50855890fa2ab21a2b4641125cad9f07aa41b8989344bb269aee580ad2e5ef33ddff68839f338270c2b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -113,6 +113,21 @@ You may not want to expose something that will make it easy for a user to break
|
|
113
113
|
posts_stream = PostsStream.new(posts)
|
114
114
|
posts_stream.to_a # boom!
|
115
115
|
|
116
|
+
## Stream/Streams Source
|
117
|
+
|
118
|
+
Singular `Stream` and collection `Streams` both use the term source. This is the object that is wrapped by the stream. For collection `Streams`, source acts a little differently. The reason for this is best shown by the following:
|
119
|
+
|
120
|
+
s = PostsStream.new
|
121
|
+
s.source # nil
|
122
|
+
|
123
|
+
PostsStream.default_source = Post.all
|
124
|
+
s = PostsStream.new
|
125
|
+
s.source # Post.all
|
126
|
+
s = PostsStream.new(Post.popular)
|
127
|
+
s.source # Post.popular
|
128
|
+
|
129
|
+
As you can see, you may want the source of a collection stream to be different things, or default to something if none is given.
|
130
|
+
|
116
131
|
## Contributing
|
117
132
|
|
118
133
|
1. Fork it
|
@@ -3,8 +3,10 @@ module LiquidStream
|
|
3
3
|
|
4
4
|
delegate :count, :size, to: :source
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
class_attribute :default_source
|
7
|
+
|
8
|
+
def initialize(source=nil, stream_context={})
|
9
|
+
@source = source_from(source)
|
8
10
|
@stream_context = stream_context
|
9
11
|
end
|
10
12
|
|
@@ -33,5 +35,16 @@ module LiquidStream
|
|
33
35
|
stream_class_from(@stream_context[:method] || self.class)
|
34
36
|
end
|
35
37
|
|
38
|
+
def source_from(s)
|
39
|
+
src = s
|
40
|
+
src ||= if self.class.default_source.respond_to?(:call)
|
41
|
+
self.class.default_source.call
|
42
|
+
else
|
43
|
+
self.class.default_source
|
44
|
+
end
|
45
|
+
src ||= []
|
46
|
+
src
|
47
|
+
end
|
48
|
+
|
36
49
|
end
|
37
50
|
end
|
@@ -82,4 +82,29 @@ describe LiquidStream::Streams do
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
describe '.default_source' do
|
86
|
+
it 'should set the default source' do
|
87
|
+
described_class.default_source = ['some', 'items']
|
88
|
+
expect(described_class.new.source).to eq(['some', 'items'])
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'when the default source is a lambda' do
|
92
|
+
it 'should resolve to the what the lambda returns' do
|
93
|
+
described_class.default_source = -> { ['some'] }
|
94
|
+
expect(described_class.new.source).to eq(['some'])
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#source' do
|
100
|
+
context 'when there is no source passed nor default source defined' do
|
101
|
+
it 'should be an empty array' do
|
102
|
+
PostsStream.default_source = nil
|
103
|
+
stream = PostsStream.new
|
104
|
+
expect(stream.source).to eq([])
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
85
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liquid_stream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ramon Tayag
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
version: '0'
|
166
166
|
requirements: []
|
167
167
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.
|
168
|
+
rubygems_version: 2.2.2
|
169
169
|
signing_key:
|
170
170
|
specification_version: 4
|
171
171
|
summary: Allow a more Ruby-like interface to Liquid drops with context awareness
|