bsflow 2.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 457b3db7aef819c0684ec2ed6b74e6e4f3586f2072da8ca8e855c25dc7e86790
4
+ data.tar.gz: 2fa0aeccb978acc29aac5c7c5b0fc599abd01e3033eb1241600d18afdef58c4e
5
+ SHA512:
6
+ metadata.gz: cb427d952b5e8d27aa30daba5e5c0ddd7ef9e9b5f0c5c72f1d12e7ae5525c01d1cfaccc9ab213a65bc7c152dcde97c973d8b70f4c32b61eedcfac96f23ba5f3a
7
+ data.tar.gz: 70bf14e6fed64895ab7bde2326626d72a436019a7f35472c1976227fe95124c91edbcf42c3f93741fea593c4572b45536c4922e71b3b9d2c0d65e3865cdedca6
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ *.gem
14
+
15
+ vendor/bundle
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in bsielski_control_flow.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bsflow (2.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.1)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.0)
24
+
25
+ PLATFORMS
26
+ x64-mingw32
27
+
28
+ DEPENDENCIES
29
+ bsflow!
30
+ bundler (~> 1.16)
31
+ rake (~> 10.0)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 1.16.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Bartłomiej Sielski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,362 @@
1
+ # bsflow
2
+
3
+ A couple of classes that represent useful control flow patterns (conditional loops, pipelines etc).
4
+
5
+ ## When to use it?
6
+
7
+ In pseudo-funtional programming.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'bsflow'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install bsflow
24
+
25
+ ## Usage
26
+
27
+ Reqiure proper class.
28
+
29
+ ```ruby
30
+ require "bsflow/pipeline"
31
+ ```
32
+
33
+ Use it.
34
+
35
+ ```ruby
36
+ square_number_generator = BSFlow:Pipeline.new(procs: [random_int, square])
37
+
38
+ ```
39
+
40
+ All classes have just one public method: ***#call***.
41
+
42
+ Some classes have dependencies (injected in constructor) called "procs". They are objects that respond to ***#call*** method.
43
+
44
+ ## API
45
+
46
+
47
+ ### Class BSFlow::Pipeline
48
+
49
+ It passes a value through every proc and returns a final value. Output of the previous proc is input of the next proc.
50
+
51
+ Source code:
52
+
53
+ ```ruby
54
+ module BSFlow
55
+ class Pipeline
56
+ def initialize(procs:)
57
+ @procs = procs
58
+ end
59
+
60
+ def call(*args)
61
+ output = @procs[0].call(*args)
62
+ if @procs.length == 1
63
+ return output
64
+ else
65
+ @procs[1..-1].each do |proc|
66
+ output = proc.call(output)
67
+ end
68
+ output
69
+ end
70
+ end
71
+ end
72
+ ```
73
+
74
+ #### Require
75
+
76
+ ```ruby
77
+ require "bsflow/pipeline"
78
+ ```
79
+
80
+ #### Constructor
81
+
82
+ ```ruby
83
+ BSFlow:Pipeline.new(procs: procs) # => new_pipeline
84
+ ```
85
+
86
+ Paramaters:
87
+
88
+ - **_procs_** - an array of procs or objects responding on `.call` message. The first **_proc_** takes the "main" input of the class (any number of arguments). The result is passed to the next **_proc_** as input. The output of the last **_proc_** is the output of `.call` method of **Pipeline** class.
89
+
90
+
91
+ ### Class BSFlow::FirstArg
92
+
93
+ It just returns first pased argument and ignores the rest. Used to reduce number of arguments.
94
+
95
+ Source code:
96
+
97
+ ```ruby
98
+ module BSFlow
99
+ class FirstArg
100
+ def call(*args)
101
+ args.first
102
+ end
103
+ end
104
+ end
105
+ ```
106
+
107
+ #### Require
108
+
109
+ ```ruby
110
+ require "bsflow/first_arg"
111
+ ```
112
+
113
+ #### Constructor
114
+
115
+ ```ruby
116
+ BSFlow:FirstArg.new # => new_first_arg
117
+ ```
118
+
119
+
120
+ ### Class BSFlow::LastArg
121
+
122
+ It just returns last pased argument and ignores the rest. Used to reduce number of arguments.
123
+
124
+ Source code:
125
+
126
+ ```ruby
127
+ module BSFlow
128
+ class LastArg
129
+ def call(*args)
130
+ args.last
131
+ end
132
+ end
133
+ end
134
+ ```
135
+
136
+ #### Require
137
+
138
+ ```ruby
139
+ require "bsflow/last_arg"
140
+ ```
141
+
142
+ #### Constructor
143
+
144
+ ```ruby
145
+ BSFlow:LastArg.new # => new_last_arg
146
+ ```
147
+
148
+
149
+ ### Class BSFlow::Self
150
+
151
+ It returns unmodified argument.
152
+
153
+ Source code:
154
+
155
+ ```ruby
156
+ module BSFlow
157
+ class Self
158
+ def call(input)
159
+ input
160
+ end
161
+ end
162
+ end
163
+ ```
164
+
165
+ #### Require
166
+
167
+ ```ruby
168
+ require "bsflow/self"
169
+ ```
170
+
171
+ #### Constructor
172
+
173
+ ```ruby
174
+ BSFlow:Self.new # => new_self
175
+ ```
176
+
177
+ ### Class BSFlow::True
178
+
179
+ It returns **_true_** no matter what input it takes.
180
+
181
+ Source code:
182
+
183
+ ```ruby
184
+ module BSFlow
185
+ class True
186
+ def call(input)
187
+ true
188
+ end
189
+ end
190
+ end
191
+ ```
192
+
193
+ #### Require
194
+
195
+ ```ruby
196
+ require "bsflow/true"
197
+ ```
198
+
199
+ #### Constructor
200
+
201
+ ```ruby
202
+ BSFlow:True.new # => new_true
203
+ ```
204
+
205
+ ### Class BSFlow::False
206
+
207
+ It returns **_false_** no matter what input it takes.
208
+
209
+ Source code:
210
+
211
+ ```ruby
212
+ module BSFlow
213
+ class False
214
+ def call(input)
215
+ false
216
+ end
217
+ end
218
+ end
219
+ ```
220
+
221
+ #### Require
222
+
223
+ ```ruby
224
+ require "bsflow/false"
225
+ ```
226
+
227
+ #### Constructor
228
+
229
+ ```ruby
230
+ BSFlow:False.new # => new_false
231
+ ```
232
+
233
+ ### Class BSFlow::Pass
234
+
235
+ It passes a value to a proc and returns the unmodified value. So it is a one way ticket for data but it is usefull for sending data to some output stream or queue.
236
+
237
+ Source code:
238
+
239
+ ```ruby
240
+ module BSFlow
241
+ class Pass
242
+ def initialize(proc:)
243
+ @proc = proc
244
+ end
245
+
246
+ def call(input)
247
+ @proc.call(input)
248
+ input
249
+ end
250
+ end
251
+ end
252
+ ```
253
+
254
+ #### Require
255
+
256
+ ```ruby
257
+ require "bsflow/pass"
258
+ ```
259
+
260
+ #### Constructor
261
+
262
+ ```ruby
263
+ BSFlow:Pass.new(proc: proc) # => new_pass
264
+ ```
265
+
266
+ Paramaters:
267
+
268
+ - **_proc_** - an objects responding on `.call` message with one argument.
269
+
270
+ ### Class BSFlow::Combine
271
+
272
+ It passes its `.call` arguments to each injected sub_proc, then it passes their outputs to injected combine_proc and returns the output.
273
+
274
+ Source code:
275
+
276
+ ```ruby
277
+ module BSFlow
278
+ class Combine
279
+ def initialize(combine_proc:, sub_procs:)
280
+ @sub_procs = sub_procs
281
+ @combine_proc = combine_proc
282
+ end
283
+
284
+ def call(*args)
285
+ sub_proc_outputs = []
286
+ @sub_procs.each do |sub_proc|
287
+ sub_proc_outputs << sub_proc.call(*args)
288
+ end
289
+ @combine_proc.call(*sub_proc_outputs)
290
+ end
291
+ end
292
+ end
293
+ ```
294
+
295
+ #### Require
296
+
297
+ ```ruby
298
+ require "bsflow/combine"
299
+ ```
300
+
301
+ #### Constructor
302
+
303
+ ```ruby
304
+ BSFlow::Combine.new(sub_procs: sub_procs, combine_proc: combine_proc) # => new_combine
305
+ ```
306
+
307
+ Paramaters:
308
+
309
+ - **_sub_procs_** - an array of procs or objects responding on `.call` message. Each of them takes arguments from combine object's call method and return an output. All aoutpus are pased to **_combine_proc_**.
310
+ - **_combine_procs_** - a proc or object responding on `.call` message. The output of this proc is the output of the `.call` method of the **Combine** class.
311
+
312
+
313
+ ### Class BSFlow::UntilTrueLoop
314
+
315
+ It passes input to condition_proc and if the result is not true it pases the input to loop_proc until the result is true.
316
+
317
+ Source code:
318
+
319
+ ```ruby
320
+ module BSFlow
321
+ class UntilTrueLoop
322
+ def initialize(condition_proc:, loop_proc:)
323
+ @loop_proc = loop_proc
324
+ @condition_proc = condition_proc
325
+ end
326
+
327
+ def call(input)
328
+ until @condition_proc.call(input) do
329
+ input = @loop_proc.call(input)
330
+ end
331
+ input
332
+ end
333
+ end
334
+ end
335
+ ```
336
+
337
+ #### Require
338
+
339
+ ```ruby
340
+ require "bsflow/until_true_loop"
341
+ ```
342
+
343
+ #### Constructor
344
+
345
+ ```ruby
346
+ BSFlow::UntilTrueLoop.new(condition_proc: condition_proc, loop_proc: loop_proc) # => new_loop
347
+ ```
348
+
349
+ Paramaters:
350
+
351
+ - **_condition_proc_** - proc or object responding on `.call` message with one argument. At the beginning it takes the input from `.call` method from UntilTrueLoop class. If an output is truthy the output is returned as the output of `.call` message of UntilTrueLoop class.
352
+ - **_loop_proc_** - a proc or objects responding on `.call` message with one argument.
353
+
354
+
355
+ ## To do features
356
+
357
+ - Examples in the documentation and source code.
358
+ - More classes.
359
+
360
+ ## License
361
+
362
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bsielski_control_flow"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bsflow.gemspec ADDED
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "bsflow/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bsflow"
8
+ spec.version = BSFlow::VERSION
9
+ spec.authors = ["Bart\xC5\x82omiej Sielski"]
10
+ spec.email = ["b.sielski.webdev@gmail.com"]
11
+
12
+ spec.summary = %q{A couple of classes that represent useful control flow patterns (conditional loops, pipelines etc.}
13
+ spec.homepage = "https://github.com/bsielski/bsflow"
14
+ spec.license = "MIT"
15
+
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
data/lib/bsflow.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "bsflow/version"
2
+
3
+ module BSFlow
4
+
5
+ end
@@ -0,0 +1,16 @@
1
+ module BSFlow
2
+ class Combine
3
+ def initialize(combine_proc:, sub_procs:)
4
+ @sub_procs = sub_procs
5
+ @combine_proc = combine_proc
6
+ end
7
+
8
+ def call(*args)
9
+ sub_proc_outputs = []
10
+ @sub_procs.each do |sub_proc|
11
+ sub_proc_outputs << sub_proc.call(*args)
12
+ end
13
+ @combine_proc.call(*sub_proc_outputs)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ module BSFlow
2
+ class False
3
+ def call(input)
4
+ false
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module BSFlow
2
+ class FirstArg
3
+ def call(*args)
4
+ args.first
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module BSFlow
2
+ class LastArg
3
+ def call(*args)
4
+ args.last
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module BSFlow
2
+ class Pass
3
+ def initialize(proc:)
4
+ @proc = proc
5
+ end
6
+
7
+ def call(input)
8
+ @proc.call(input)
9
+ input
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ module BSFlow
2
+ class Pipeline
3
+ def initialize(procs:)
4
+ @procs = procs
5
+ end
6
+
7
+ def call(*args)
8
+ output = @procs[0].call(*args)
9
+ if @procs.length == 1
10
+ return output
11
+ else
12
+ @procs[1..-1].each do |proc|
13
+ output = proc.call(output)
14
+ end
15
+ output
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ module BSFlow
2
+ class Self
3
+ def call(input)
4
+ input
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module BSFlow
2
+ class True
3
+ def call(input)
4
+ true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module BSFlow
2
+ class UntilTrueLoop
3
+ def initialize(condition_proc:, loop_proc:)
4
+ @loop_proc = loop_proc
5
+ @condition_proc = condition_proc
6
+ end
7
+
8
+ def call(input)
9
+ until @condition_proc.call(input) do
10
+ input = @loop_proc.call(input)
11
+ end
12
+ input
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module BSFlow
2
+ VERSION = "2.2.0"
3
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bsflow
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Bartłomiej Sielski
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - b.sielski.webdev@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - bsflow.gemspec
73
+ - lib/bsflow.rb
74
+ - lib/bsflow/combine.rb
75
+ - lib/bsflow/false.rb
76
+ - lib/bsflow/first_arg.rb
77
+ - lib/bsflow/last_arg.rb
78
+ - lib/bsflow/pass.rb
79
+ - lib/bsflow/pipeline.rb
80
+ - lib/bsflow/self.rb
81
+ - lib/bsflow/true.rb
82
+ - lib/bsflow/until_true_loop.rb
83
+ - lib/bsflow/version.rb
84
+ homepage: https://github.com/bsielski/bsflow
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.7.6
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: A couple of classes that represent useful control flow patterns (conditional
108
+ loops, pipelines etc.
109
+ test_files: []