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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e12fe40f870d7fdb3cea6050cd78c2e9fc664645afc834be42036f01261d7078
4
- data.tar.gz: ce539d54b582033f05342045a923313367a307bb999d8ec7c2b7e9aabc550edb
3
+ metadata.gz: 5b3f2e1e80d4b8a81dc439e3932b0742cc127fb6ebbe7b00b10668a0c71f1a59
4
+ data.tar.gz: 47ddb93df9b8071bd0eeac69b3a709b2e7698f24a3cff1615931f8f244298d70
5
5
  SHA512:
6
- metadata.gz: 744f9bf09c7c3ab19c8ea8541f322c498983904ec1b084dc52bb9e07f05e8fdeddc05c30dc5d52d8553412c4b00a1f82c1cdcd83fa08e8cc5e1ca86ed894097f
7
- data.tar.gz: bffa4c272a0e8610d694b3762627eb3ad81416bc979da72f789ea6b29be97e8ff0b3790a14a74108b1a81dc932b69fff2dc27a9cc4bcd07874fe437efc3069d8
6
+ metadata.gz: f46485bfd779e80c4c56fb3e727ab3bdd1beda52f25a6ad923e6952ae114f7ab15b47e9ed529fcfa84094767dd67606872b7cea0bce61c12a81166d49b28ac75
7
+ data.tar.gz: ea59d8e707925e64004493181c5303bc954ddf28e7c518a214ef2d19c9314098a9bc29454cd4bec9b9d697750d1f92e1492d48e2a345fa21518d43c6b2177e2d
@@ -18,7 +18,7 @@ workflows:
18
18
  jobs:
19
19
  test:
20
20
  docker:
21
- - image: darthjee/circleci_rails_gems:0.5.1
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.1
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: scripts/build.sh signin
65
+ command: build_gem.sh signin
66
66
  - run:
67
67
  name: Build Gem
68
- command: scripts/build.sh build
68
+ command: build_gem.sh build
69
69
  - run:
70
70
  name: Push Gem
71
- command: scripts/build.sh push
71
+ command: build_gem.sh push
data/Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
- FROM darthjee/rails_gems:0.5.2 as base
2
- FROM darthjee/scripts:0.1.7 as scripts
1
+ FROM darthjee/rails_gems:0.5.4 as base
2
+ FROM darthjee/scripts:0.1.8 as scripts
3
3
 
4
4
  ######################################
5
5
 
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.0](https://www.rubydoc.info/gems/azeroth/0.7.0)
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
@@ -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.0'
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.4'
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'
@@ -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 options.decorator if options.decorator.is_a?(Class)
90
+ return decorator if decorator.is_a?(Class)
89
91
 
90
92
  klass::Decorator
91
93
  rescue NameError
@@ -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 ||= build_resource
22
+ @resource ||= build_and_save_resource
21
23
  end
22
24
 
23
- # build resource for create
25
+ # @private
26
+ #
27
+ # build resource for create and save it
24
28
  #
25
29
  # @return [Object]
26
- def build_resource
27
- @resource = collection.build(attributes)
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
@@ -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
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Azeroth
4
- VERSION = '0.7.0'
4
+ VERSION = '0.7.1'
5
5
  end
@@ -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.0
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-13 00:00:00.000000000 Z
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.0
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.0
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.4
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.4
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
@@ -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