baseapi 0.1.3 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dca945b60e066f84367a241d9ffdf4f63b69742a
4
- data.tar.gz: abd87f5100db1cb5418a82801edc7efcf507dd27
3
+ metadata.gz: 4f5088cdb71d64f395001c1a8258638ae588c82b
4
+ data.tar.gz: 93e1834177068cf3d2c9bd3b106c9ad25cbac73b
5
5
  SHA512:
6
- metadata.gz: c009cb8fc952ec300a1194d82c3e8d83b70351455a4cd6d8069bd6a236e8047e29e905ea2d787b41f87361928e2cc030647ae3e01d7bce735912bc002af821d4
7
- data.tar.gz: 06cbe31f266e92e7d20f55c7ddbe1401a8c0f7a80d12a539f255a2bbe3d5382e419ceb372f90b6840cf1512b331ba7a0780241ed8353f641cdb82f5e982129a1
6
+ metadata.gz: 69807f927ef03e2e6a69e33e2d28c50a7dfbd1784a55d111b0a024930084204482d31625c1b0ed2df986879c82262b0744bcc3ecd007dd03c9458c3734cfce17
7
+ data.tar.gz: d2c5fb8fb8995bfae5e3826b25a0ba6474ea8eb09bc0a5e87467a233587c73f8e005f5be66ede168be966724f096a1c7b878a746c3158fddb7bd78569f321196
data/README.md CHANGED
@@ -269,6 +269,27 @@ relation_match, you can use the relation_like function.
269
269
  The short so please read the [code](https://github.com/arakawamoriyuki/baseapi/blob/master/lib/baseapi/active_record/base_extension.rb) for more information
270
270
 
271
271
 
272
+
273
+ ### hook action
274
+
275
+ Controller of 'create, update, destroy' function in advance by attaching the prefix of before, you can post processing
276
+
277
+ class UsersController < BaseApiController
278
+ def before_create
279
+ if params['name'].blank?
280
+ raise 'Please enter your name'
281
+ end
282
+ end
283
+ end
284
+
285
+ And if not sent the name to api in the above example, it returns an error in the json. Message is a string that was passed to raise.
286
+
287
+ {
288
+ error: true,
289
+ message: "Please enter your name",
290
+ }
291
+
292
+
272
293
  ### jbuilder
273
294
 
274
295
  It uses basically
@@ -22,12 +22,14 @@ class BaseApiController < ActionController::Base
22
22
  # @return String Json(Model)
23
23
  def create
24
24
  render 'model.json.jbuilder' if transaction(-> {
25
+ self.send("before_#{__method__}") if self.methods.include?("before_#{__method__}".to_sym)
25
26
  params.each do |key, value|
26
27
  if key.present? and value.present? and @Model.column_names.include?(key)
27
28
  @model.send("#{key}=", value)
28
29
  end
29
30
  end
30
31
  @model.save
32
+ self.send("after_#{__method__}") if self.methods.include?("after_#{__method__}".to_sym)
31
33
  })
32
34
  end
33
35
 
@@ -36,12 +38,14 @@ class BaseApiController < ActionController::Base
36
38
  # @return String Json(Model)
37
39
  def update
38
40
  render 'model.json.jbuilder' if transaction(-> {
41
+ self.send("before_#{__method__}") if self.methods.include?("before_#{__method__}".to_sym)
39
42
  params.each do |key, value|
40
43
  if key.present? and value.present? and @Model.column_names.include?(key)
41
44
  @model.send("#{key}=", value)
42
45
  end
43
46
  end
44
47
  @model.save
48
+ self.send("after_#{__method__}") if self.methods.include?("after_#{__method__}".to_sym)
45
49
  })
46
50
  end
47
51
 
@@ -50,7 +54,9 @@ class BaseApiController < ActionController::Base
50
54
  # @return String Json(Model)
51
55
  def destroy
52
56
  render 'model.json.jbuilder' if transaction(-> {
57
+ self.send("before_#{__method__}") if self.methods.include?("before_#{__method__}".to_sym)
53
58
  @model._destroy
59
+ self.send("after_#{__method__}") if self.methods.include?("after_#{__method__}".to_sym)
54
60
  })
55
61
  end
56
62
 
data/lib/baseapi/cli.rb CHANGED
@@ -26,11 +26,7 @@ module Baseapi
26
26
 
27
27
  files.each do |file, path|
28
28
  src = File.expand_path("../app/#{path}/#{file}", __FILE__)
29
- if File.exists?("app/#{path}/#{file}")
30
- warn "[skip] app/#{path}/#{file} already exists"
31
- else
32
- FileUtils.cp(src, "app/#{path}/#{file}")
33
- end
29
+ FileUtils.cp(src, "app/#{path}/#{file}")
34
30
  end
35
31
  end
36
32
  end
@@ -1,3 +1,3 @@
1
1
  module Baseapi
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baseapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moriyuki Arakawa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-03 00:00:00.000000000 Z
11
+ date: 2015-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler