modware 0.1.1 → 1.0.0

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
- SHA1:
3
- metadata.gz: 3954be9354da6c601d61ef054899259b7fc749c9
4
- data.tar.gz: 6840f5fa4aad0fbd2f4a97200133e12a5362bb25
2
+ SHA256:
3
+ metadata.gz: 507056ec7b90b4f35ca6e927bfa72241176258fb4a33a83d62565920831cff3b
4
+ data.tar.gz: 46596689ab31ae28d5dad8cdcf800578fb25b51f42679a9a69e0f45ba1bcf7e2
5
5
  SHA512:
6
- metadata.gz: 997889d2b9aed15eabab7ebc41f85f52ba1be4213d2cdcd44ab562ce5245c75c6a3b0d9e87515b02b4387eea34e2305c8c841ee93324c8b76319953f4ab2f803
7
- data.tar.gz: 0cfe6a6036f066df4794e96944ac42750f4249d1d4a13da5482412fd63cc9bd051de7e7a7f419cc9c67805cec360ee8eb53bfa104f29c18935c2828599e9887f
6
+ metadata.gz: d9fddb563c69665eb4a4199bda7c0d8cd7f943c06c3865f98c9f9d45eff4992d13bad9d4bfe2b42b54a8d6284b9d99b95b07a69002adcd683530d9b40efbde29
7
+ data.tar.gz: 613c1ad1d11e2b6f89498a04f1f1fbc5c5fb7a273100f7a016ae26d5ff0ed1664a30fedbdd6f43b94118c0c811954d91ce8dead71a68b7e866044aca599df11b
@@ -0,0 +1,49 @@
1
+ name: CI PR Builds
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+
9
+ concurrency:
10
+ group: "ci-${{ github.ref }}"
11
+ cancel-in-progress: true
12
+
13
+ jobs:
14
+ test:
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby-version: ['2.5', '2.6', '2.7', '3.0']
20
+ steps:
21
+ - uses: actions/checkout@v2
22
+
23
+ - name: Set up Ruby
24
+ uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby-version }}
27
+ bundler-cache: true
28
+
29
+ - name: 'Run bundle update'
30
+ run: bundle update
31
+
32
+ - name: Run tests
33
+ run: bundle exec rake spec
34
+
35
+ - name: Coveralls Parallel
36
+ uses: coverallsapp/github-action@master
37
+ with:
38
+ github-token: ${{ secrets.GITHUB_TOKEN }}
39
+ flag-name: run-${{ matrix.ruby-version }}
40
+ parallel: true
41
+ finish:
42
+ needs: 'test'
43
+ runs-on: ubuntu-latest
44
+ steps:
45
+ - name: Coveralls Finished
46
+ uses: coverallsapp/github-action@master
47
+ with:
48
+ github-token: ${{ secrets.GITHUB_TOKEN }}
49
+ parallel-finished: true
data/.simplecov ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.configure do
4
+ enable_coverage :branch
5
+ add_filter '/spec/'
6
+
7
+ add_group 'Libraries', '/lib/'
8
+
9
+ if ENV['CI']
10
+ require 'simplecov-lcov'
11
+
12
+ SimpleCov::Formatter::LcovFormatter.config do |c|
13
+ c.report_with_single_file = true
14
+ c.single_report_path = 'coverage/lcov.info'
15
+ end
16
+
17
+ formatter SimpleCov::Formatter::LcovFormatter
18
+ end
19
+ end
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in modware.gemspec
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/modware.svg)](http://badge.fury.io/rb/modware)
2
- [![Build Status](https://secure.travis-ci.org/ronen/modware.svg)](http://travis-ci.org/ronen/modware)
3
- [![Coverage Status](https://img.shields.io/coveralls/ronen/modware.svg)](https://coveralls.io/r/ronen/modware)
2
+ [![Build Status](https://github.com/SchemaPlus/modware/actions/workflows/prs.yml/badge.svg)](https://github.com/SchemaPlus/modware/actions)
3
+ [![Coverage Status](https://coveralls.io/repos/github/SchemaPlus/modware/badge.svg)](https://coveralls.io/github/SchemaPlus/modware)
4
4
 
5
5
  # Modware
6
6
 
@@ -32,8 +32,7 @@ where `klass` is a Class for the environment instance that will be passed to the
32
32
  stack = Modware::Stack.new(env: [:name, :options, :results])
33
33
  ```
34
34
 
35
- and Modware will define a class that accepts those keys as keyword arguments, and has accessor methods for each (see
36
- [`KeyStruct`](https://rubygems.org/gems/key_struct)).
35
+ and Modware will define a class that accepts those keys as keyword arguments, and has accessor methods for each
37
36
 
38
37
 
39
38
  ### Defining middleware
@@ -102,7 +101,7 @@ class WrapsOperation < BaseClass
102
101
 
103
102
  attr_reader :stack
104
103
 
105
- def initialized(*args)
104
+ def initialize(*args)
106
105
  super
107
106
  @stack = Modware::Stack.new(env: [:time, :place, :result])
108
107
  end
@@ -132,6 +131,10 @@ The [middleware](https://rubygems.org/gems/middleware) gem works well, following
132
131
 
133
132
  ## Change Log
134
133
 
134
+ * 1.0.0 - use a major bump due to breakage with the 0.2.0 version and existing gems
135
+ * 0.2.0 - Add ruby 3.0 support and drop ruby < 2.5 (yanked)
136
+ * 0.1.3 - Remove its-it dependency :( #2
137
+ * 0.1.2 - More thread safety in Stack#start
135
138
  * 0.1.1 - Thread safety in Stack#start
136
139
  * 0.1.0 - Initial release
137
140
 
data/Rakefile CHANGED
@@ -1,10 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
 
3
5
  require 'rspec/core/rake_task'
4
6
  RSpec::Core::RakeTask.new(:spec) do |spec|
5
7
  spec.rspec_opts = '-Ispec'
6
8
  end
7
-
8
- require 'coveralls/rake/task'
9
- Coveralls::RakeTask.new
10
- task :spec_with_coveralls => [:spec, 'coveralls:push']
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Modware
2
4
  class StackError < Exception
3
5
  end
data/lib/modware/stack.rb CHANGED
@@ -1,77 +1,92 @@
1
- require 'its-it'
2
- require 'key_struct'
1
+ # frozen_string_literal: true
3
2
 
4
3
  module Modware
5
4
  class Stack
6
5
  def initialize(env:)
7
6
  @env_klass = case env
8
7
  when Class then env
9
- else KeyStruct[*env]
8
+ else
9
+ Struct.new(*env, keyword_init: true) do
10
+ def to_hash
11
+ to_h.compact
12
+ end
13
+ end
10
14
  end
11
- @middlewares = []
15
+ @middleware_mods = []
12
16
  end
13
17
 
14
18
  def add(mod)
15
- middleware = Middleware.new(self, mod)
16
- @middlewares.last._next = middleware if @middlewares.any?
17
- @middlewares << middleware
19
+ @middleware_mods << mod
18
20
  end
19
21
 
20
- def start(*args, &implementation)
22
+ def start(*args, &base_implementation)
21
23
  env = @env_klass.new(*args)
22
- execute_stack(env, implementation)
24
+ Executor.new(@middleware_mods).execute(env, base_implementation)
23
25
  env
24
26
  end
25
27
 
26
28
  private
27
29
 
28
- def execute_stack(env, base_implementation)
29
- return call_implementation(env, base_implementation) unless @middlewares.any?
30
-
31
- @middlewares.each do |middleware|
32
- middleware.before env if middleware.respond_to? :before
30
+ class Executor
31
+ def initialize(middleware_mods)
32
+ prev = nil
33
+ @middlewares = middleware_mods.map { |mod|
34
+ Middleware.new(self, mod).tap { |middleware|
35
+ prev._modware_next = middleware if prev
36
+ prev = middleware
37
+ }
38
+ }
33
39
  end
34
40
 
35
- @middlewares.first._call(env, base_implementation)
41
+ def execute(env, base_implementation)
42
+ return call_implementation(env, base_implementation) if @middlewares.empty?
43
+
44
+ @middlewares.each do |middleware|
45
+ middleware.before env if middleware.respond_to? :before
46
+ end
47
+
48
+ @middlewares.first._modware_call(env, base_implementation)
36
49
 
37
- @middlewares.each do |middleware|
38
- middleware.after env if middleware.respond_to? :after
50
+ @middlewares.each do |middleware|
51
+ middleware.after env if middleware.respond_to? :after
52
+ end
39
53
  end
40
- end
41
54
 
42
- def call_implementation(env, base_implementation)
43
- if middleware = @middlewares.select(&it.respond_to?(:implement)).last
44
- middleware.implement(env)
45
- elsif base_implementation
46
- base_implementation.call env
47
- else
48
- raise StackError, "No base implementation nor middleware implementation in stack"
55
+ def call_implementation(env, base_implementation)
56
+ if middleware = @middlewares.select { |mw| mw.respond_to?(:implement) }.last
57
+ middleware.implement(env)
58
+ elsif base_implementation
59
+ base_implementation.call env
60
+ else
61
+ raise StackError, "No base implementation nor middleware implementation in stack"
62
+ end
49
63
  end
50
64
  end
51
65
 
66
+
52
67
  class Middleware
53
- attr_accessor :_next
68
+ attr_accessor :_modware_next
54
69
 
55
- def initialize(stack, mod)
56
- @stack = stack
70
+ def initialize(executor, mod)
71
+ @executor = executor
57
72
  singleton_class.send :include, mod
58
73
  end
59
74
 
60
- def _call(env, base_implementation)
75
+ def _modware_call(env, base_implementation)
61
76
  if respond_to? :around
62
77
  around(env) { |env|
63
- _continue env, base_implementation
78
+ _modware_continue env, base_implementation
64
79
  }
65
80
  else
66
- _continue env, base_implementation
81
+ _modware_continue env, base_implementation
67
82
  end
68
83
  end
69
84
 
70
- def _continue(env, base_implementation)
71
- if self._next
72
- self._next._call(env, base_implementation)
85
+ def _modware_continue(env, base_implementation)
86
+ if self._modware_next
87
+ self._modware_next._modware_call(env, base_implementation)
73
88
  else
74
- @stack.send :call_implementation, env, base_implementation
89
+ @executor.call_implementation env, base_implementation
75
90
  end
76
91
  end
77
92
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Modware
2
- VERSION = "0.1.1"
4
+ VERSION = "1.0.0"
3
5
  end
data/lib/modware.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "modware/errors"
2
4
  require "modware/stack"
3
5
  require "modware/version"
data/modware.gemspec CHANGED
@@ -1,4 +1,5 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'modware/version'
@@ -17,15 +18,12 @@ Gem::Specification.new do |spec|
17
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
19
  spec.require_paths = ["lib"]
19
20
 
20
- spec.required_ruby_version = ">= 2.1.0"
21
- spec.add_dependency "key_struct", "~> 0.4"
22
- spec.add_dependency "its-it"
21
+ spec.required_ruby_version = ">= 2.5.0"
23
22
 
24
- spec.add_development_dependency 'coveralls'
25
- spec.add_development_dependency "bundler", "~> 1.7"
26
- spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "rake", "~> 13.0"
27
25
  spec.add_development_dependency "rspec", "~> 3.0"
28
26
  spec.add_development_dependency "rspec-given"
29
27
  spec.add_development_dependency "simplecov"
30
- spec.add_development_dependency "simplecov-gem-profile"
28
+ spec.add_development_dependency 'simplecov-lcov', '~> 0.8.0'
31
29
  end
data/spec/env_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe "Env" do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe "Execution" do
@@ -13,7 +15,7 @@ describe "Execution" do
13
15
 
14
16
  context "when start with base implementation" do
15
17
 
16
- When(:env) { stack.start result: [] { |env| env.result << :base } }
18
+ When(:env) { stack.start(result: []) { |env| env.result << :base } }
17
19
 
18
20
  Then { expect(env.result).to eq [:base] }
19
21
 
@@ -28,6 +30,13 @@ describe "Execution" do
28
30
  Given { stack.add Factory.middleware(2, implement: nil) }
29
31
 
30
32
  Then { expect(env.result).to eq [:before1, :before2, :around_pre2, :implement1, :around_post2, :after1, :after2 ] }
33
+
34
+ context "if add middleware3" do
35
+
36
+ Given { stack.add Factory.middleware(3, around: nil, implement: nil) }
37
+
38
+ Then { expect(env.result).to eq [:before1, :before2, :before3, :around_pre2, :implement1, :around_post2, :after1, :after2, :after3 ] }
39
+ end
31
40
  end
32
41
  end
33
42
 
data/spec/helper_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe "Helper" do
@@ -7,12 +9,12 @@ describe "Helper" do
7
9
  context "Modware.is_middleware?" do
8
10
  [:before, :after, :around, :implement].each do |method|
9
11
  it "returns truthy for a module with #{method.inspect} method" do
10
- expect(Modware.is_middleware? Factory.middleware(none.merge(method => true))).to be_truthy
12
+ expect(Modware.is_middleware? Factory.middleware(**none.merge(method => true))).to be_truthy
11
13
  end
12
14
  end
13
15
 
14
16
  it "returns falsey for other modules" do
15
- expect(Modware.is_middleware? Factory.middleware(none.merge(other: true))).to be_falsey
17
+ expect(Modware.is_middleware? Factory.middleware(**none.merge(other: true))).to be_falsey
16
18
  end
17
19
  end
18
20
 
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simplecov'
2
- require 'simplecov-gem-profile'
3
- SimpleCov.start "gem"
4
+ SimpleCov.start
4
5
 
5
6
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
7
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Factory
2
4
  def self.middleware(n=nil, before: true, after: true, around: true, implement: true, other: nil)
3
5
 
@@ -35,6 +37,8 @@ module Factory
35
37
  end
36
38
  END
37
39
 
38
- Module.new.tap(&it.module_eval(methods.compact.join))
40
+ Module.new do
41
+ module_eval(methods.compact.join)
42
+ end
39
43
  end
40
44
  end
metadata CHANGED
@@ -1,45 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modware
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ronen barzel
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-25 00:00:00.000000000 Z
11
+ date: 2022-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: key_struct
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.4'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.4'
27
- - !ruby/object:Gem::Dependency
28
- name: its-it
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: coveralls
14
+ name: bundler
43
15
  requirement: !ruby/object:Gem::Requirement
44
16
  requirements:
45
17
  - - ">="
@@ -52,34 +24,20 @@ dependencies:
52
24
  - - ">="
53
25
  - !ruby/object:Gem::Version
54
26
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.7'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.7'
69
27
  - !ruby/object:Gem::Dependency
70
28
  name: rake
71
29
  requirement: !ruby/object:Gem::Requirement
72
30
  requirements:
73
31
  - - "~>"
74
32
  - !ruby/object:Gem::Version
75
- version: '10.0'
33
+ version: '13.0'
76
34
  type: :development
77
35
  prerelease: false
78
36
  version_requirements: !ruby/object:Gem::Requirement
79
37
  requirements:
80
38
  - - "~>"
81
39
  - !ruby/object:Gem::Version
82
- version: '10.0'
40
+ version: '13.0'
83
41
  - !ruby/object:Gem::Dependency
84
42
  name: rspec
85
43
  requirement: !ruby/object:Gem::Requirement
@@ -123,28 +81,29 @@ dependencies:
123
81
  - !ruby/object:Gem::Version
124
82
  version: '0'
125
83
  - !ruby/object:Gem::Dependency
126
- name: simplecov-gem-profile
84
+ name: simplecov-lcov
127
85
  requirement: !ruby/object:Gem::Requirement
128
86
  requirements:
129
- - - ">="
87
+ - - "~>"
130
88
  - !ruby/object:Gem::Version
131
- version: '0'
89
+ version: 0.8.0
132
90
  type: :development
133
91
  prerelease: false
134
92
  version_requirements: !ruby/object:Gem::Requirement
135
93
  requirements:
136
- - - ">="
94
+ - - "~>"
137
95
  - !ruby/object:Gem::Version
138
- version: '0'
139
- description:
96
+ version: 0.8.0
97
+ description:
140
98
  email:
141
99
  - ronen@barzel.org
142
100
  executables: []
143
101
  extensions: []
144
102
  extra_rdoc_files: []
145
103
  files:
104
+ - ".github/workflows/prs.yml"
146
105
  - ".gitignore"
147
- - ".travis.yml"
106
+ - ".simplecov"
148
107
  - Gemfile
149
108
  - LICENSE.txt
150
109
  - README.md
@@ -163,7 +122,7 @@ homepage: https://github.com/ronen/modware
163
122
  licenses:
164
123
  - MIT
165
124
  metadata: {}
166
- post_install_message:
125
+ post_install_message:
167
126
  rdoc_options: []
168
127
  require_paths:
169
128
  - lib
@@ -171,16 +130,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
130
  requirements:
172
131
  - - ">="
173
132
  - !ruby/object:Gem::Version
174
- version: 2.1.0
133
+ version: 2.5.0
175
134
  required_rubygems_version: !ruby/object:Gem::Requirement
176
135
  requirements:
177
136
  - - ">="
178
137
  - !ruby/object:Gem::Version
179
138
  version: '0'
180
139
  requirements: []
181
- rubyforge_project:
182
- rubygems_version: 2.4.6
183
- signing_key:
140
+ rubygems_version: 3.0.8
141
+ signing_key:
184
142
  specification_version: 4
185
143
  summary: A middleware library, featuring a simple interface and "callback" style semantics
186
144
  in the middleware stack
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- sudo: false
2
- rvm:
3
- - 2.1.5
4
- script: bundle exec rake spec_with_coveralls
5
- notifications:
6
- recipients:
7
- - ronen@barzel.org