liquid_stream 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 030832c0751d60e0b1ba8a20b10dd2c6c5da59bc
4
- data.tar.gz: ccaf5b71f6f6d8cada5f15ec8fe675aca28f3d9a
3
+ metadata.gz: 6273d042d67ee818d165028563c77f2d97ff9a96
4
+ data.tar.gz: b33895f8647855e6529257646a6b7a7c3f88583c
5
5
  SHA512:
6
- metadata.gz: 1ba6ae8462051277b9ef97d7837f6ae92e68334b619f67301aa50fcd3fdf4dbc6a0313ef72ca398592a2b6e40168f3b5239e2335da14af712d0f82d278422b59
7
- data.tar.gz: 92f0d41dd6b43e0158a711bc619a495c0ba1779c0db771f41b7ac0c83a7b3c77995d24f02541acef582ffbceb80fbf1c95d94c95aed11b4c186505b75b3e7ecf
6
+ metadata.gz: c3da6f7e939f3637d723c1bbf4807fecc6b7ff96ca2bbc151e1b4236a86a3c8b55c03eff0fa6e66b76ce1d4285b82424fcb36ff6d69b10d5108a7cd8e79334b0
7
+ data.tar.gz: 37d6f4de42207e39118ef4e80d316e61a8c8aa350fe7a50855890fa2ab21a2b4641125cad9f07aa41b8989344bb269aee580ad2e5ef33ddff68839f338270c2b
@@ -1,3 +1,8 @@
1
+ # 0.0.3
2
+
3
+ - Allow `LiquidStream::Streams` to have a default source
4
+ - For `LiquidStream::Streams`, if no source nor default source is defined, then source is an empty array
5
+
1
6
  # 0.0.2
2
7
 
3
8
  Fixes issue with Utils being in the wrong place and broke loading
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
- def initialize(source, stream_context={})
7
- @source = source
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
@@ -1,3 +1,3 @@
1
1
  module LiquidStream
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  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.2
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: 2013-07-21 00:00:00.000000000 Z
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.0.3
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