embed_callbacks 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/gem-push.yml +12 -7
- data/.github/workflows/test.yml +28 -0
- data/README.md +2 -3
- data/lib/embed_callbacks.rb +2 -38
- data/lib/embed_callbacks/behavior.rb +24 -0
- data/lib/embed_callbacks/condition.rb +13 -0
- data/lib/embed_callbacks/version.rb +1 -1
- metadata +9 -7
- data/Gemfile.lock +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57f1e7749e44b988e0f6b29c490f660a371450d730b4127f221c88fb4e5fa0ff
|
4
|
+
data.tar.gz: 6ed35b660c5a759faf5604b854b7c1a5e64b9ed16255142e922fbadeb18342ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04d7081bf03e41b5f35e3c726807eb9409433532aec07fc7f4a0181621d2395bce3fdd9d1232864c5f21d332366f2790ac2a3d43962090c5d9022b3d5c5e95ca
|
7
|
+
data.tar.gz: 44e748e38213072d6f01fc8bc4b38ab222875b4dedbc4b398eae155ba2d5d81893fd0466985ca3fea63a81601a177ee4fc61b370698a54b47b2a2b286f29c904
|
@@ -3,24 +3,18 @@ name: Ruby Gem
|
|
3
3
|
on:
|
4
4
|
push:
|
5
5
|
branches: [ main ]
|
6
|
-
pull_request:
|
7
|
-
branches: [ main ]
|
8
6
|
|
9
7
|
jobs:
|
10
8
|
build:
|
11
9
|
name: Build + Publish
|
12
10
|
runs-on: ubuntu-latest
|
13
11
|
|
14
|
-
strategy:
|
15
|
-
matrix:
|
16
|
-
ruby: [ '2.7.x', '2.6.x', '2.5.x' ]
|
17
|
-
|
18
12
|
steps:
|
19
13
|
- uses: actions/checkout@v2
|
20
14
|
- name: Set up Ruby
|
21
15
|
uses: actions/setup-ruby@v1
|
22
16
|
with:
|
23
|
-
ruby-version:
|
17
|
+
ruby-version: 2.6.x
|
24
18
|
|
25
19
|
- name: Install dependencies
|
26
20
|
run: |
|
@@ -29,3 +23,14 @@ jobs:
|
|
29
23
|
|
30
24
|
- name: Run test
|
31
25
|
run: bundle exec rspec spec
|
26
|
+
|
27
|
+
- name: Publish to RubyGems
|
28
|
+
run: |
|
29
|
+
mkdir -p $HOME/.gem
|
30
|
+
touch $HOME/.gem/credentials
|
31
|
+
chmod 0600 $HOME/.gem/credentials
|
32
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
33
|
+
gem build *.gemspec
|
34
|
+
gem push *.gem
|
35
|
+
env:
|
36
|
+
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on:
|
4
|
+
[ push, pull_request ]
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
name: Rspec test
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby: [ '2.7.x', '2.6.x', '2.5.x' ]
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- name: Set up Ruby
|
18
|
+
uses: actions/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: ${{ matrix.ruby }}
|
21
|
+
|
22
|
+
- name: Install dependencies
|
23
|
+
run: |
|
24
|
+
gem install bundler --no-document
|
25
|
+
bundle install
|
26
|
+
|
27
|
+
- name: Run test
|
28
|
+
run: bundle exec rspec spec
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ This gem makes it easy to create callbacks.
|
|
10
10
|
Add this line to your application's Gemfile:
|
11
11
|
|
12
12
|
```ruby
|
13
|
-
gem '
|
13
|
+
gem 'embed_callbacks'
|
14
14
|
```
|
15
15
|
|
16
16
|
And then execute:
|
@@ -19,8 +19,7 @@ And then execute:
|
|
19
19
|
|
20
20
|
Or install it yourself as:
|
21
21
|
|
22
|
-
$ gem install
|
23
|
-
$ gem specific_install git@github.com:hotoolong/embed_callbacks.git main
|
22
|
+
$ gem install embed_callbacks
|
24
23
|
|
25
24
|
## Usage
|
26
25
|
|
data/lib/embed_callbacks.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require "embed_callbacks/version"
|
2
|
+
require "embed_callbacks/condition"
|
3
|
+
require "embed_callbacks/behavior"
|
2
4
|
|
3
5
|
module EmbedCallbacks
|
4
6
|
def self.included(base)
|
@@ -27,42 +29,4 @@ module EmbedCallbacks
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
|
-
class Condition
|
31
|
-
def initialize(options)
|
32
|
-
@if = options[:if]
|
33
|
-
@unless = options[:unless]
|
34
|
-
raise ArgumentError, "Don't use if and unless at the same time." if @if && @unless
|
35
|
-
end
|
36
|
-
|
37
|
-
def call(record)
|
38
|
-
return @if.call(record) if @if
|
39
|
-
return !@unless&.call(record) if @unless
|
40
|
-
true
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class Behavior
|
45
|
-
KINDS = %i(before after around rescue ensure)
|
46
|
-
|
47
|
-
def initialize(behavior)
|
48
|
-
@behavior = behavior
|
49
|
-
raise ArgumentError, 'The behavior should be set in the before after around rescue' unless KINDS.include?(behavior)
|
50
|
-
end
|
51
|
-
|
52
|
-
def before?
|
53
|
-
%i(before around).include?(@behavior)
|
54
|
-
end
|
55
|
-
|
56
|
-
def after?
|
57
|
-
%i(after around).include?(@behavior)
|
58
|
-
end
|
59
|
-
|
60
|
-
def rescue?
|
61
|
-
:rescue == @behavior
|
62
|
-
end
|
63
|
-
|
64
|
-
def ensure?
|
65
|
-
:ensure == @behavior
|
66
|
-
end
|
67
|
-
end
|
68
32
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Behavior
|
2
|
+
KINDS = %i(before after around rescue ensure)
|
3
|
+
|
4
|
+
def initialize(behavior)
|
5
|
+
@behavior = behavior
|
6
|
+
raise ArgumentError, 'The behavior should be set in the ' + KINDS.join(' ') unless KINDS.include?(behavior)
|
7
|
+
end
|
8
|
+
|
9
|
+
def before?
|
10
|
+
%i(before around).include?(@behavior)
|
11
|
+
end
|
12
|
+
|
13
|
+
def after?
|
14
|
+
%i(after around).include?(@behavior)
|
15
|
+
end
|
16
|
+
|
17
|
+
def rescue?
|
18
|
+
:rescue == @behavior
|
19
|
+
end
|
20
|
+
|
21
|
+
def ensure?
|
22
|
+
:ensure == @behavior
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Condition
|
2
|
+
def initialize(options)
|
3
|
+
@if = options[:if]
|
4
|
+
@unless = options[:unless]
|
5
|
+
raise ArgumentError, "Don't use if and unless at the same time." if @if && @unless
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(record)
|
9
|
+
return @if.call(record) if @if
|
10
|
+
return !@unless&.call(record) if @unless
|
11
|
+
true
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embed_callbacks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hotoolong
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -75,12 +75,12 @@ extensions: []
|
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
77
|
- ".github/workflows/gem-push.yml"
|
78
|
+
- ".github/workflows/test.yml"
|
78
79
|
- ".gitignore"
|
79
80
|
- ".rspec"
|
80
81
|
- ".travis.yml"
|
81
82
|
- CODE_OF_CONDUCT.md
|
82
83
|
- Gemfile
|
83
|
-
- Gemfile.lock
|
84
84
|
- LICENSE.txt
|
85
85
|
- README.md
|
86
86
|
- Rakefile
|
@@ -88,12 +88,14 @@ files:
|
|
88
88
|
- bin/setup
|
89
89
|
- embed_callbacks.gemspec
|
90
90
|
- lib/embed_callbacks.rb
|
91
|
+
- lib/embed_callbacks/behavior.rb
|
92
|
+
- lib/embed_callbacks/condition.rb
|
91
93
|
- lib/embed_callbacks/version.rb
|
92
94
|
homepage: https://github.com/hotoolong/embed_callbacks
|
93
95
|
licenses:
|
94
96
|
- MIT
|
95
97
|
metadata: {}
|
96
|
-
post_install_message:
|
98
|
+
post_install_message:
|
97
99
|
rdoc_options: []
|
98
100
|
require_paths:
|
99
101
|
- lib
|
@@ -108,8 +110,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
110
|
- !ruby/object:Gem::Version
|
109
111
|
version: '0'
|
110
112
|
requirements: []
|
111
|
-
rubygems_version: 3.
|
112
|
-
signing_key:
|
113
|
+
rubygems_version: 3.0.3
|
114
|
+
signing_key:
|
113
115
|
specification_version: 4
|
114
116
|
summary: Create a method callback.
|
115
117
|
test_files: []
|
data/Gemfile.lock
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
embed_callbacks (0.1.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
codecov (0.2.6)
|
10
|
-
colorize
|
11
|
-
json
|
12
|
-
simplecov
|
13
|
-
colorize (0.8.1)
|
14
|
-
diff-lcs (1.4.4)
|
15
|
-
docile (1.3.2)
|
16
|
-
json (2.3.1)
|
17
|
-
rake (12.3.3)
|
18
|
-
rspec (3.9.0)
|
19
|
-
rspec-core (~> 3.9.0)
|
20
|
-
rspec-expectations (~> 3.9.0)
|
21
|
-
rspec-mocks (~> 3.9.0)
|
22
|
-
rspec-core (3.9.2)
|
23
|
-
rspec-support (~> 3.9.3)
|
24
|
-
rspec-expectations (3.9.2)
|
25
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
-
rspec-support (~> 3.9.0)
|
27
|
-
rspec-mocks (3.9.1)
|
28
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
-
rspec-support (~> 3.9.0)
|
30
|
-
rspec-support (3.9.3)
|
31
|
-
simplecov (0.19.0)
|
32
|
-
docile (~> 1.1)
|
33
|
-
simplecov-html (~> 0.11)
|
34
|
-
simplecov-html (0.12.2)
|
35
|
-
|
36
|
-
PLATFORMS
|
37
|
-
ruby
|
38
|
-
|
39
|
-
DEPENDENCIES
|
40
|
-
codecov
|
41
|
-
embed_callbacks!
|
42
|
-
rake (~> 12.0)
|
43
|
-
rspec (~> 3.0)
|
44
|
-
simplecov
|
45
|
-
|
46
|
-
BUNDLED WITH
|
47
|
-
2.1.4
|