shirinji-rails 0.0.3 → 0.0.4
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/.travis.yml +10 -0
- data/Gemfile.lock +35 -35
- data/README.md +42 -1
- data/lib/shirinji-rails/railtie.rb +4 -2
- data/lib/shirinji-rails/resolver_binding.rb +25 -0
- data/lib/shirinji-rails/version.rb +1 -1
- data/lib/shirinji-rails.rb +2 -1
- data/shirinji-rails.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ba2074a1253de14110ff4086a0f670ef766807da
|
|
4
|
+
data.tar.gz: d65935189fbfe865c055b408c04be42a57650d4b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6c701e777444d64a878beb4469c12e00fcf9a24a6da326168b2ac19883ee28a2a9d6f4e25ab2abc47e3a36ff555969434deffdadcf313cd439c489c10151af1d
|
|
7
|
+
data.tar.gz: 9e35d5e0ad789451be08e52b20fce67557322c58efbc5de38afbfda77b6379d4f157365b2a4ffbb9cf37b25fe9d92e497f9045a47698c0194c211d76564ec592
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
shirinji-rails (0.0.
|
|
4
|
+
shirinji-rails (0.0.4)
|
|
5
5
|
railties (>= 5.0.0)
|
|
6
6
|
shirinji (= 0.0.3)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
actionpack (5.2.
|
|
12
|
-
actionview (= 5.2.
|
|
13
|
-
activesupport (= 5.2.
|
|
11
|
+
actionpack (5.2.2)
|
|
12
|
+
actionview (= 5.2.2)
|
|
13
|
+
activesupport (= 5.2.2)
|
|
14
14
|
rack (~> 2.0)
|
|
15
15
|
rack-test (>= 0.6.3)
|
|
16
16
|
rails-dom-testing (~> 2.0)
|
|
17
17
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
18
|
-
actionview (5.2.
|
|
19
|
-
activesupport (= 5.2.
|
|
18
|
+
actionview (5.2.2)
|
|
19
|
+
activesupport (= 5.2.2)
|
|
20
20
|
builder (~> 3.1)
|
|
21
21
|
erubi (~> 1.4)
|
|
22
22
|
rails-dom-testing (~> 2.0)
|
|
23
23
|
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
|
24
|
-
activesupport (5.2.
|
|
24
|
+
activesupport (5.2.2)
|
|
25
25
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
26
26
|
i18n (>= 0.7, < 2)
|
|
27
27
|
minitest (~> 5.1)
|
|
28
28
|
tzinfo (~> 1.1)
|
|
29
29
|
builder (3.2.3)
|
|
30
|
-
concurrent-ruby (1.
|
|
30
|
+
concurrent-ruby (1.1.4)
|
|
31
31
|
crass (1.0.4)
|
|
32
32
|
diff-lcs (1.3)
|
|
33
|
-
erubi (1.
|
|
34
|
-
i18n (1.
|
|
33
|
+
erubi (1.8.0)
|
|
34
|
+
i18n (1.5.3)
|
|
35
35
|
concurrent-ruby (~> 1.0)
|
|
36
|
-
loofah (2.2.
|
|
36
|
+
loofah (2.2.3)
|
|
37
37
|
crass (~> 1.0.2)
|
|
38
38
|
nokogiri (>= 1.5.9)
|
|
39
|
-
method_source (0.9.
|
|
40
|
-
mini_portile2 (2.
|
|
39
|
+
method_source (0.9.2)
|
|
40
|
+
mini_portile2 (2.4.0)
|
|
41
41
|
minitest (5.11.3)
|
|
42
|
-
nokogiri (1.
|
|
43
|
-
mini_portile2 (~> 2.
|
|
44
|
-
rack (2.0.
|
|
45
|
-
rack-test (1.
|
|
42
|
+
nokogiri (1.10.1)
|
|
43
|
+
mini_portile2 (~> 2.4.0)
|
|
44
|
+
rack (2.0.6)
|
|
45
|
+
rack-test (1.1.0)
|
|
46
46
|
rack (>= 1.0, < 3)
|
|
47
47
|
rails-dom-testing (2.0.3)
|
|
48
48
|
activesupport (>= 4.2.0)
|
|
49
49
|
nokogiri (>= 1.6)
|
|
50
50
|
rails-html-sanitizer (1.0.4)
|
|
51
51
|
loofah (~> 2.2, >= 2.2.2)
|
|
52
|
-
railties (5.2.
|
|
53
|
-
actionpack (= 5.2.
|
|
54
|
-
activesupport (= 5.2.
|
|
52
|
+
railties (5.2.2)
|
|
53
|
+
actionpack (= 5.2.2)
|
|
54
|
+
activesupport (= 5.2.2)
|
|
55
55
|
method_source
|
|
56
56
|
rake (>= 0.8.7)
|
|
57
|
-
thor (>= 0.
|
|
57
|
+
thor (>= 0.19.0, < 2.0)
|
|
58
58
|
rake (10.5.0)
|
|
59
|
-
rspec (3.
|
|
60
|
-
rspec-core (~> 3.
|
|
61
|
-
rspec-expectations (~> 3.
|
|
62
|
-
rspec-mocks (~> 3.
|
|
63
|
-
rspec-core (3.
|
|
64
|
-
rspec-support (~> 3.
|
|
65
|
-
rspec-expectations (3.
|
|
59
|
+
rspec (3.8.0)
|
|
60
|
+
rspec-core (~> 3.8.0)
|
|
61
|
+
rspec-expectations (~> 3.8.0)
|
|
62
|
+
rspec-mocks (~> 3.8.0)
|
|
63
|
+
rspec-core (3.8.0)
|
|
64
|
+
rspec-support (~> 3.8.0)
|
|
65
|
+
rspec-expectations (3.8.2)
|
|
66
66
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
67
|
-
rspec-support (~> 3.
|
|
68
|
-
rspec-mocks (3.
|
|
67
|
+
rspec-support (~> 3.8.0)
|
|
68
|
+
rspec-mocks (3.8.0)
|
|
69
69
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
70
|
-
rspec-support (~> 3.
|
|
71
|
-
rspec-support (3.
|
|
70
|
+
rspec-support (~> 3.8.0)
|
|
71
|
+
rspec-support (3.8.0)
|
|
72
72
|
shirinji (0.0.3)
|
|
73
|
-
thor (0.20.
|
|
73
|
+
thor (0.20.3)
|
|
74
74
|
thread_safe (0.3.6)
|
|
75
75
|
tzinfo (1.2.5)
|
|
76
76
|
thread_safe (~> 0.1)
|
|
@@ -79,10 +79,10 @@ PLATFORMS
|
|
|
79
79
|
ruby
|
|
80
80
|
|
|
81
81
|
DEPENDENCIES
|
|
82
|
-
bundler (~>
|
|
82
|
+
bundler (~> 2.0)
|
|
83
83
|
rake (~> 10.0)
|
|
84
84
|
rspec (~> 3.0)
|
|
85
85
|
shirinji-rails!
|
|
86
86
|
|
|
87
87
|
BUNDLED WITH
|
|
88
|
-
|
|
88
|
+
2.0.1
|
data/README.md
CHANGED
|
@@ -14,7 +14,7 @@ And then execute:
|
|
|
14
14
|
|
|
15
15
|
$ bundle
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## General usage
|
|
18
18
|
|
|
19
19
|
Add this file in `config/dependencies.rb`
|
|
20
20
|
|
|
@@ -48,6 +48,47 @@ service = MyApp.bean(:user_sign_up_service)
|
|
|
48
48
|
service.call(user)
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
+
## Rails entities DSL
|
|
52
|
+
|
|
53
|
+
Since controllers and jobs (and maybe other rails entities) are not under
|
|
54
|
+
Shirinji's control, they can not receive dependencies through their constructors.
|
|
55
|
+
|
|
56
|
+
One solution is to manually create a method for each dependency but it's painful
|
|
57
|
+
and make the code harder to read.
|
|
58
|
+
|
|
59
|
+
Rails integration actually provides a simple DSL to express dependencies.
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
# application_controller.rb
|
|
63
|
+
|
|
64
|
+
class ApplicationController < ActionController::Base
|
|
65
|
+
include ShirinjiRails::ResolverBinding
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# in any controller
|
|
69
|
+
|
|
70
|
+
class FooController < ApplicationController
|
|
71
|
+
dependency :config
|
|
72
|
+
# Alias
|
|
73
|
+
dependency foo_create_service: :create_service
|
|
74
|
+
|
|
75
|
+
def index
|
|
76
|
+
config #=> `config` dependency
|
|
77
|
+
create_service # => `foo_create_service` dependency
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
class FooJob < ActiveJob::Base
|
|
82
|
+
include ShirinjiRails::ResolverBinding
|
|
83
|
+
|
|
84
|
+
dependency :config
|
|
85
|
+
|
|
86
|
+
def perform
|
|
87
|
+
config #=> `config` dependency
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
```
|
|
91
|
+
|
|
51
92
|
## Contributing
|
|
52
93
|
|
|
53
94
|
Bug reports and pull requests are welcome on GitHub at https://github.com/fdutey/shirinji-rails.
|
|
@@ -14,12 +14,14 @@ module ShirinjiRails
|
|
|
14
14
|
return unless (conf = config_path)
|
|
15
15
|
|
|
16
16
|
map = eval File.read(conf)
|
|
17
|
-
|
|
17
|
+
resolver = Shirinji::Resolver.new(map)
|
|
18
18
|
|
|
19
19
|
ActiveSupport::Reloader.to_prepare do
|
|
20
20
|
map = eval File.read(conf)
|
|
21
|
-
|
|
21
|
+
resolver.reload(map)
|
|
22
22
|
end
|
|
23
|
+
|
|
24
|
+
config.shirinji.resolver = resolver
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
private
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module ShirinjiRails
|
|
2
|
+
module ResolverBinding
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
module ClassMethods
|
|
6
|
+
def dependency(*deps)
|
|
7
|
+
deps.each { |dep| _define_dependency_reader(dep) }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def _define_dependency_reader(bean, method = bean)
|
|
11
|
+
if bean.is_a?(Hash)
|
|
12
|
+
return bean.each { |k,v| _define_dependency_reader(k, v) }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
define_method(method) do
|
|
16
|
+
resolver.resolve(bean)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def resolver
|
|
22
|
+
::Rails.application.config.shirinji.resolver
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/shirinji-rails.rb
CHANGED
data/shirinji-rails.gemspec
CHANGED
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
|
23
23
|
spec.add_dependency 'railties', '>= 5.0.0'
|
|
24
24
|
spec.add_dependency 'shirinji', '0.0.3'
|
|
25
25
|
|
|
26
|
-
spec.add_development_dependency 'bundler', '~>
|
|
26
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
|
27
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
|
28
28
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
29
29
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shirinji-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Dutey
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2019-02-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: railties
|
|
@@ -44,14 +44,14 @@ dependencies:
|
|
|
44
44
|
requirements:
|
|
45
45
|
- - "~>"
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
47
|
+
version: '2.0'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
54
|
+
version: '2.0'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: rake
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -102,6 +102,7 @@ files:
|
|
|
102
102
|
- bin/setup
|
|
103
103
|
- lib/shirinji-rails.rb
|
|
104
104
|
- lib/shirinji-rails/railtie.rb
|
|
105
|
+
- lib/shirinji-rails/resolver_binding.rb
|
|
105
106
|
- lib/shirinji-rails/version.rb
|
|
106
107
|
- shirinji-rails.gemspec
|
|
107
108
|
homepage: https://github.com/fdutey/shirinji-rails
|