azeroth 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +5 -5
- data/Dockerfile +2 -2
- data/README.md +2 -1
- data/azeroth.gemspec +2 -2
- data/lib/azeroth/model.rb +3 -1
- data/lib/azeroth/options.rb +9 -1
- data/lib/azeroth/request_handler/create.rb +27 -4
- data/lib/azeroth/resourceable.rb +3 -0
- data/lib/azeroth/version.rb +1 -1
- data/spec/lib/azeroth/request_handler/create_spec.rb +83 -0
- data/spec/support/app/controllers/request_handler_controller.rb +7 -0
- metadata +6 -7
- data/scripts/build.sh +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b3f2e1e80d4b8a81dc439e3932b0742cc127fb6ebbe7b00b10668a0c71f1a59
|
4
|
+
data.tar.gz: 47ddb93df9b8071bd0eeac69b3a709b2e7698f24a3cff1615931f8f244298d70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f46485bfd779e80c4c56fb3e727ab3bdd1beda52f25a6ad923e6952ae114f7ab15b47e9ed529fcfa84094767dd67606872b7cea0bce61c12a81166d49b28ac75
|
7
|
+
data.tar.gz: ea59d8e707925e64004493181c5303bc954ddf28e7c518a214ef2d19c9314098a9bc29454cd4bec9b9d697750d1f92e1492d48e2a345fa21518d43c6b2177e2d
|
data/.circleci/config.yml
CHANGED
@@ -18,7 +18,7 @@ workflows:
|
|
18
18
|
jobs:
|
19
19
|
test:
|
20
20
|
docker:
|
21
|
-
- image: darthjee/circleci_rails_gems:0.5.
|
21
|
+
- image: darthjee/circleci_rails_gems:0.5.4
|
22
22
|
environment:
|
23
23
|
PROJECT: azeroth
|
24
24
|
steps:
|
@@ -52,7 +52,7 @@ jobs:
|
|
52
52
|
command: check_specs
|
53
53
|
build-and-release:
|
54
54
|
docker:
|
55
|
-
- image: darthjee/circleci_rails_gems:0.5.
|
55
|
+
- image: darthjee/circleci_rails_gems:0.5.4
|
56
56
|
environment:
|
57
57
|
PROJECT: azeroth
|
58
58
|
steps:
|
@@ -62,10 +62,10 @@ jobs:
|
|
62
62
|
command: bundle install
|
63
63
|
- run:
|
64
64
|
name: Signin
|
65
|
-
command:
|
65
|
+
command: build_gem.sh signin
|
66
66
|
- run:
|
67
67
|
name: Build Gem
|
68
|
-
command:
|
68
|
+
command: build_gem.sh build
|
69
69
|
- run:
|
70
70
|
name: Push Gem
|
71
|
-
command:
|
71
|
+
command: build_gem.sh push
|
data/Dockerfile
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@ Azeroth
|
|
11
11
|
|
12
12
|
Yard Documentation
|
13
13
|
-------------------
|
14
|
-
[https://www.rubydoc.info/gems/azeroth/0.7.
|
14
|
+
[https://www.rubydoc.info/gems/azeroth/0.7.1](https://www.rubydoc.info/gems/azeroth/0.7.1)
|
15
15
|
|
16
16
|
Azeroth has been designed making the coding of controllers easier
|
17
17
|
as routes in controllers are usually copy, paste and replace of same
|
@@ -59,6 +59,7 @@ It accepts options
|
|
59
59
|
- except: List of actions to not to be built
|
60
60
|
- decorator: Decorator class or flag allowing/disallowing decorators
|
61
61
|
- before_save: Method/Proc to be ran before saving the resource on create or update
|
62
|
+
- build_with: Method/Block to be ran when building the reource on create
|
62
63
|
|
63
64
|
```ruby
|
64
65
|
# publishers_controller.rb
|
data/azeroth.gemspec
CHANGED
@@ -18,10 +18,10 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ['lib']
|
20
20
|
|
21
|
-
gem.add_runtime_dependency 'activesupport', '~> 5.2.
|
21
|
+
gem.add_runtime_dependency 'activesupport', '~> 5.2.4.2'
|
22
22
|
gem.add_runtime_dependency 'darthjee-active_ext', '>= 1.3.2'
|
23
23
|
gem.add_runtime_dependency 'jace', '>= 0.0.3'
|
24
|
-
gem.add_runtime_dependency 'sinclair', '>= 1.6.
|
24
|
+
gem.add_runtime_dependency 'sinclair', '>= 1.6.5'
|
25
25
|
|
26
26
|
gem.add_development_dependency 'actionpack', '5.2.4.2'
|
27
27
|
gem.add_development_dependency 'activerecord', '5.2.4.2'
|
data/lib/azeroth/model.rb
CHANGED
@@ -62,6 +62,8 @@ module Azeroth
|
|
62
62
|
#
|
63
63
|
# @return [Azeroth::Options]
|
64
64
|
|
65
|
+
delegate :decorator, to: :options
|
66
|
+
|
65
67
|
# @private
|
66
68
|
#
|
67
69
|
# Returns decorator class for the object
|
@@ -85,7 +87,7 @@ module Azeroth
|
|
85
87
|
# @return [Azeroth::Decorator,DummyDecorator]
|
86
88
|
def calculate_decorator_class
|
87
89
|
return DummyDecorator unless options.decorator
|
88
|
-
return
|
90
|
+
return decorator if decorator.is_a?(Class)
|
89
91
|
|
90
92
|
klass::Decorator
|
91
93
|
rescue NameError
|
data/lib/azeroth/options.rb
CHANGED
@@ -18,7 +18,8 @@ module Azeroth
|
|
18
18
|
only: %i[create destroy edit index new show update],
|
19
19
|
except: [],
|
20
20
|
decorator: true,
|
21
|
-
before_save: nil
|
21
|
+
before_save: nil,
|
22
|
+
build_with: nil
|
22
23
|
}.freeze
|
23
24
|
|
24
25
|
with_options DEFAULT_OPTIONS
|
@@ -79,5 +80,12 @@ module Azeroth
|
|
79
80
|
# to database
|
80
81
|
#
|
81
82
|
# @return [Symbol,Proc]
|
83
|
+
|
84
|
+
# @method build_with
|
85
|
+
# @api private
|
86
|
+
#
|
87
|
+
# Block or method name to be ran when building the resource
|
88
|
+
#
|
89
|
+
# @return [Symbol,Proc]
|
82
90
|
end
|
83
91
|
end
|
@@ -8,6 +8,8 @@ module Azeroth
|
|
8
8
|
class Create < RequestHandler
|
9
9
|
private
|
10
10
|
|
11
|
+
delegate :build_with, to: :options
|
12
|
+
|
11
13
|
# @private
|
12
14
|
#
|
13
15
|
# Creates and return an instance of the model
|
@@ -17,14 +19,16 @@ module Azeroth
|
|
17
19
|
#
|
18
20
|
# @return [Object]
|
19
21
|
def resource
|
20
|
-
@resource ||=
|
22
|
+
@resource ||= build_and_save_resource
|
21
23
|
end
|
22
24
|
|
23
|
-
#
|
25
|
+
# @private
|
26
|
+
#
|
27
|
+
# build resource for create and save it
|
24
28
|
#
|
25
29
|
# @return [Object]
|
26
|
-
def
|
27
|
-
@resource =
|
30
|
+
def build_and_save_resource
|
31
|
+
@resource = build_resource
|
28
32
|
controller.instance_variable_set("@#{model.name}", resource)
|
29
33
|
|
30
34
|
trigger_event(:save) do
|
@@ -32,6 +36,25 @@ module Azeroth
|
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
39
|
+
# @private
|
40
|
+
#
|
41
|
+
# build resource without saving it
|
42
|
+
#
|
43
|
+
# when +build_with+ option is given, the proc/method
|
44
|
+
# is called instead of collection.build
|
45
|
+
#
|
46
|
+
# @return [Object] resource built
|
47
|
+
def build_resource
|
48
|
+
return collection.build(attributes) unless build_with
|
49
|
+
|
50
|
+
case build_with
|
51
|
+
when Proc
|
52
|
+
controller.instance_eval(&build_with)
|
53
|
+
else
|
54
|
+
controller.send(build_with)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
35
58
|
# @private
|
36
59
|
#
|
37
60
|
# Response status
|
data/lib/azeroth/resourceable.rb
CHANGED
@@ -35,6 +35,9 @@ module Azeroth
|
|
35
35
|
# Decorator class or flag allowing/disallowing decorators
|
36
36
|
# @option options before_save [Symbol,Proc] method/block
|
37
37
|
# to be ran on the controller before saving the resource
|
38
|
+
# @option options build_with [Symbol,Proc] method/block
|
39
|
+
# to be ran when building resource
|
40
|
+
# (default proc { <resource_collection>.build(resource_params) }
|
38
41
|
#
|
39
42
|
# @return [Array<MethodDefinition>] list of methods created
|
40
43
|
#
|
data/lib/azeroth/version.rb
CHANGED
@@ -108,6 +108,89 @@ describe Azeroth::RequestHandler::Create do
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
+
context 'with build_with as symbol' do
|
112
|
+
it_behaves_like 'a request handler', status: :created do
|
113
|
+
let(:options_hash) do
|
114
|
+
{
|
115
|
+
build_with: :build_magic_document
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
let(:extra_params) do
|
120
|
+
{
|
121
|
+
document: {
|
122
|
+
name: 'My Document'
|
123
|
+
}
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
let(:expected_json) do
|
128
|
+
{
|
129
|
+
'name' => 'My Document',
|
130
|
+
'reference' => 'X-MAGIC-15'
|
131
|
+
}
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'creates entry' do
|
135
|
+
expect { handler.process }
|
136
|
+
.to change(Document, :count)
|
137
|
+
.by(1)
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'builds entity with custom method' do
|
141
|
+
handler.process
|
142
|
+
|
143
|
+
expect(Document.last.reference)
|
144
|
+
.to eq('X-MAGIC-15')
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'with build_with as block' do
|
150
|
+
it_behaves_like 'a request handler', status: :created do
|
151
|
+
let(:block) do
|
152
|
+
proc do
|
153
|
+
documents.where(reference: 'X-MAGIC-20')
|
154
|
+
.build(document_params)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
let(:options_hash) do
|
159
|
+
{
|
160
|
+
build_with: block
|
161
|
+
}
|
162
|
+
end
|
163
|
+
|
164
|
+
let(:extra_params) do
|
165
|
+
{
|
166
|
+
document: {
|
167
|
+
name: 'My Document'
|
168
|
+
}
|
169
|
+
}
|
170
|
+
end
|
171
|
+
|
172
|
+
let(:expected_json) do
|
173
|
+
{
|
174
|
+
'name' => 'My Document',
|
175
|
+
'reference' => 'X-MAGIC-20'
|
176
|
+
}
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'creates entry' do
|
180
|
+
expect { handler.process }
|
181
|
+
.to change(Document, :count)
|
182
|
+
.by(1)
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'builds entity with custom method' do
|
186
|
+
handler.process
|
187
|
+
|
188
|
+
expect(Document.last.reference)
|
189
|
+
.to eq('X-MAGIC-20')
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
111
194
|
context 'when payload is invalid' do
|
112
195
|
it_behaves_like 'a request handler',
|
113
196
|
status: :unprocessable_entity do
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class RequestHandlerController < ActionController::Base
|
4
|
+
private
|
5
|
+
|
4
6
|
def document_params
|
5
7
|
params.require(:document).permit(:name)
|
6
8
|
end
|
@@ -16,4 +18,9 @@ class RequestHandlerController < ActionController::Base
|
|
16
18
|
def add_magic_reference
|
17
19
|
document.reference = 'X-MAGIC-15'
|
18
20
|
end
|
21
|
+
|
22
|
+
def build_magic_document
|
23
|
+
documents.where(reference: 'X-MAGIC-15')
|
24
|
+
.build(document_params)
|
25
|
+
end
|
19
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: azeroth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darthjee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 5.2.
|
19
|
+
version: 5.2.4.2
|
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: 5.2.
|
26
|
+
version: 5.2.4.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: darthjee-active_ext
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.6.
|
61
|
+
version: 1.6.5
|
62
62
|
type: :runtime
|
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: 1.6.
|
68
|
+
version: 1.6.5
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: actionpack
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -449,7 +449,6 @@ files:
|
|
449
449
|
- lib/azeroth/resourceable/class_methods.rb
|
450
450
|
- lib/azeroth/routes_builder.rb
|
451
451
|
- lib/azeroth/version.rb
|
452
|
-
- scripts/build.sh
|
453
452
|
- spec/controllers/documents_controller_spec.rb
|
454
453
|
- spec/controllers/documents_with_error_controller_spec.rb
|
455
454
|
- spec/controllers/index_documents_controller_spec.rb
|
data/scripts/build.sh
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
function version() {
|
4
|
-
echo $(cat lib/$PROJECT/version.rb | grep VERSION | sed -e "s/.*'\\(.*\\)'.*/\\1/g")
|
5
|
-
}
|
6
|
-
|
7
|
-
function isTagged() {
|
8
|
-
VERSION=$(version)
|
9
|
-
TAG=$(git tag | tail -n 1)
|
10
|
-
|
11
|
-
if [ $VERSION = $TAG ]; then
|
12
|
-
return 0
|
13
|
-
else
|
14
|
-
return 1
|
15
|
-
fi
|
16
|
-
}
|
17
|
-
|
18
|
-
ACTION=$1
|
19
|
-
|
20
|
-
case $ACTION in
|
21
|
-
"signin")
|
22
|
-
mkdir ~/.gem
|
23
|
-
echo "---" > ~/.gem/credentials
|
24
|
-
echo ":rubygems_api_key: $RUBY_GEMS_API_KEY" >> ~/.gem/credentials
|
25
|
-
chmod 600 ~/.gem/credentials
|
26
|
-
;;
|
27
|
-
"build")
|
28
|
-
if $(isTagged); then
|
29
|
-
rake build
|
30
|
-
else
|
31
|
-
echo version did not change
|
32
|
-
fi
|
33
|
-
;;
|
34
|
-
"push")
|
35
|
-
if $(isTagged); then
|
36
|
-
VERSION=$(version)
|
37
|
-
gem push "pkg/$PROJECT-$VERSION.gem"
|
38
|
-
else
|
39
|
-
echo version did not change
|
40
|
-
fi
|
41
|
-
;;
|
42
|
-
*)
|
43
|
-
echo Usage:
|
44
|
-
echo "$0 build # builds gem"
|
45
|
-
echo "$0 push # pushes gem"
|
46
|
-
;;
|
47
|
-
esac
|