atacama 0.1.11 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.lock +19 -17
- data/README.md +61 -9
- data/atacama.gemspec +4 -4
- data/lib/atacama/version.rb +1 -1
- metadata +19 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4276fcd0b870a97b83a3be44fb100758f5211c60d6a2457e2b874e7493fe599b
|
4
|
+
data.tar.gz: fd54fc14b128af9b090e73b986082588e6cf671fcc0cf99b8f5c0cb1c4518d36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa1f42aa04e922b35aeee8fa3fbe471ad16f0533756ae039127809775932dcfb992fcc33f469c6bdf114a6922ee6d8e9fe2d3db27fec328a276cc90f84384ae1
|
7
|
+
data.tar.gz: 338d66d627f30c353f1310ab4232df3cfa74cbefc128c6e1d7dd72030c0069441120b1cf6075ca71103cf702ab0b5912772ac69d85b9fd1c142e96d0980850d8
|
data/Gemfile.lock
CHANGED
@@ -1,34 +1,36 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
atacama (0.
|
5
|
-
dry-types
|
4
|
+
atacama (0.2.0)
|
5
|
+
dry-types
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
coderay (1.1.2)
|
11
|
-
concurrent-ruby (1.
|
12
|
-
dry-configurable (0.
|
11
|
+
concurrent-ruby (1.1.6)
|
12
|
+
dry-configurable (0.11.3)
|
13
13
|
concurrent-ruby (~> 1.0)
|
14
|
-
|
14
|
+
dry-core (~> 0.4, >= 0.4.7)
|
15
|
+
dry-equalizer (~> 0.2)
|
16
|
+
dry-container (0.7.2)
|
15
17
|
concurrent-ruby (~> 1.0)
|
16
18
|
dry-configurable (~> 0.1, >= 0.1.3)
|
17
|
-
dry-core (0.4.
|
19
|
+
dry-core (0.4.9)
|
20
|
+
concurrent-ruby (~> 1.0)
|
21
|
+
dry-equalizer (0.3.0)
|
22
|
+
dry-inflector (0.2.0)
|
23
|
+
dry-logic (1.0.6)
|
18
24
|
concurrent-ruby (~> 1.0)
|
19
|
-
dry-equalizer (0.2.1)
|
20
|
-
dry-inflector (0.1.2)
|
21
|
-
dry-logic (0.4.2)
|
22
|
-
dry-container (~> 0.2, >= 0.2.6)
|
23
25
|
dry-core (~> 0.2)
|
24
26
|
dry-equalizer (~> 0.2)
|
25
|
-
dry-types (
|
27
|
+
dry-types (1.3.1)
|
26
28
|
concurrent-ruby (~> 1.0)
|
27
29
|
dry-container (~> 0.3)
|
28
30
|
dry-core (~> 0.4, >= 0.4.4)
|
29
|
-
dry-equalizer (~> 0.
|
31
|
+
dry-equalizer (~> 0.3)
|
30
32
|
dry-inflector (~> 0.1, >= 0.1.2)
|
31
|
-
dry-logic (~> 0
|
33
|
+
dry-logic (~> 1.0, >= 1.0.2)
|
32
34
|
method_source (0.9.2)
|
33
35
|
minitest (5.11.3)
|
34
36
|
pry (0.12.2)
|
@@ -41,10 +43,10 @@ PLATFORMS
|
|
41
43
|
|
42
44
|
DEPENDENCIES
|
43
45
|
atacama!
|
44
|
-
bundler
|
45
|
-
minitest
|
46
|
+
bundler
|
47
|
+
minitest
|
46
48
|
pry
|
47
|
-
rake
|
49
|
+
rake
|
48
50
|
|
49
51
|
BUNDLED WITH
|
50
|
-
1.
|
52
|
+
1.17.2
|
data/README.md
CHANGED
@@ -30,7 +30,7 @@ Or install it yourself as:
|
|
30
30
|
|
31
31
|
The basic object is `Contract`. It enforces type contracts by utilizing `dry-types`.
|
32
32
|
|
33
|
-
```
|
33
|
+
```ruby
|
34
34
|
class UserFetcher < Atacama::Contract
|
35
35
|
option :id, Types::Strict::Number.gt(0)
|
36
36
|
returns Types.Instance(User)
|
@@ -43,19 +43,30 @@ end
|
|
43
43
|
UserFetcher.call(id: 1)
|
44
44
|
```
|
45
45
|
|
46
|
-
With the use of two classes, we can compose together multiple Contracts to yield a pipeline
|
47
|
-
of changes to execute.
|
46
|
+
With the use of two classes, we can compose together multiple Contracts to yield a pipeline of changes to execute.
|
48
47
|
|
49
|
-
|
48
|
+
Steps contain two flow control objects:
|
49
|
+
* `Option(key: value)` which informs the Transformer to take this value and yield it to the subsequent steps in the chain.
|
50
|
+
* `Return(value)` halts execution and early returns from the pipeline. Useful for things like validation and error handling.
|
51
|
+
|
52
|
+
The `Transformer` always returns a value object.
|
53
|
+
|
54
|
+
```ruby
|
50
55
|
class UserFetcher < Atacama::Step
|
51
56
|
option :id, type: Types::Strict::Number.gt(0)
|
52
57
|
returns Types.Option(model: Types.Instance(User))
|
53
58
|
|
59
|
+
# Both #Option and #Return are flow control values that tell the transaction what is a
|
60
|
+
# value object and what should halt execution and return.
|
54
61
|
def call
|
55
|
-
Option(model: User.find(id))
|
62
|
+
Option(model: User.find!(id))
|
63
|
+
rescue ActiveRecord::RecordNotFound
|
64
|
+
Return(Error.new('Not found'))
|
56
65
|
end
|
57
66
|
end
|
58
67
|
|
68
|
+
# Around steps allow for yielding to child steps for things like instrumentation or
|
69
|
+
# ActiveRecord::Transactions.
|
59
70
|
class Duration < Atacama::Step
|
60
71
|
def call
|
61
72
|
start = Time.now
|
@@ -64,11 +75,19 @@ class Duration < Atacama::Step
|
|
64
75
|
end
|
65
76
|
end
|
66
77
|
|
78
|
+
# The transaction class descends the queue of steps, yielding options to each step
|
79
|
+
# defined.
|
80
|
+
#
|
81
|
+
# Steps can be defined with:
|
82
|
+
# * Procs
|
83
|
+
# * Class references
|
84
|
+
# * Instance methods
|
85
|
+
#
|
67
86
|
class UpdateUser < Atacama::Transformer
|
68
|
-
option :
|
87
|
+
option :id, type: Types::Strict::Number.gt(0)
|
69
88
|
option :attributes, type: Types::Strict::Hash
|
70
89
|
|
71
|
-
returns_option :model, Types.Instance(User)
|
90
|
+
returns_option :model, Types.Instance(User) | Types.Instance(Error)
|
72
91
|
|
73
92
|
step :duration, with: Duration do
|
74
93
|
step :find, with: UserFetcher
|
@@ -90,14 +109,47 @@ UpdateUser.call(id: 1, attributes: {
|
|
90
109
|
Any step can be mocked out without the need for a third party library. Just pass any object that
|
91
110
|
responds to `#call` in the class initializer.
|
92
111
|
|
93
|
-
```
|
112
|
+
```ruby
|
94
113
|
UpdateUser.new(steps: {
|
95
|
-
save: lambda do
|
114
|
+
save: lambda do
|
96
115
|
puts "skipping save"
|
97
116
|
end
|
98
117
|
})
|
99
118
|
```
|
100
119
|
|
120
|
+
Sometimes you need to compose these objects together and inject dependencies. Those injected values
|
121
|
+
will be passed in to the object when it's later invoked with `#call`.
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
UpdateUser.inject(id: 1).call(attributes: { email: 'hello@world.com' })
|
125
|
+
```
|
126
|
+
|
127
|
+
Injected contracts can then be used inside of a Contract. Useful for Polymorphic objects.
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
class HistoryCreate < Atacama::Step
|
131
|
+
option :history_class, type: Types::Strict::Class
|
132
|
+
option :model, type: Types.Instance(ActiveRecord::Base)
|
133
|
+
|
134
|
+
def call
|
135
|
+
history_class.from_model(model)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
class UpdateUser < Atacama::Transformer
|
140
|
+
option :id, type: Types::Strict::Number.gt(0)
|
141
|
+
option :attributes, type: Types::Strict::Hash
|
142
|
+
|
143
|
+
returns_option :model, Types.Instance(User) | Types.Instance(Error)
|
144
|
+
|
145
|
+
step :duration, with: Duration do
|
146
|
+
step :find, with: UserFetcher
|
147
|
+
step :save, with: Saver
|
148
|
+
step :history, with: HistoryCreate.inject(history_class: UserHistory)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
```
|
152
|
+
|
101
153
|
## Development
|
102
154
|
|
103
155
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/atacama.gemspec
CHANGED
@@ -23,10 +23,10 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ['lib']
|
25
25
|
|
26
|
-
spec.add_dependency 'dry-types'
|
26
|
+
spec.add_dependency 'dry-types'
|
27
27
|
|
28
|
-
spec.add_development_dependency 'bundler'
|
29
|
-
spec.add_development_dependency 'minitest'
|
30
|
-
spec.add_development_dependency 'rake'
|
28
|
+
spec.add_development_dependency 'bundler'
|
29
|
+
spec.add_development_dependency 'minitest'
|
30
|
+
spec.add_development_dependency 'rake'
|
31
31
|
spec.add_development_dependency 'pry'
|
32
32
|
end
|
data/lib/atacama/version.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atacama
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Johnston
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-types
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '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: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pry
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,8 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
- !ruby/object:Gem::Version
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
|
-
|
131
|
-
rubygems_version: 2.6.11
|
130
|
+
rubygems_version: 3.0.6
|
132
131
|
signing_key:
|
133
132
|
specification_version: 4
|
134
133
|
summary: DRY Service Objects
|