cyrax 0.3.0 → 0.3.1

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzU3YmM0Nzg2NzIzY2ZiYTZiOGFiYzJjYjYzNTE1Y2ZiNDFjOThjOA==
4
+ NWU3ZmQ1ZGUwYzViOTNiYTRiNGEyMDk5YzgwNWRiMGE2NmE0ZDljMQ==
5
5
  data.tar.gz: !binary |-
6
- Mjc3MGVjZjhhZGExZTI3MjAyODZkMzZjZGRjNTJiY2U5N2I1YzgwOQ==
6
+ ZTcwZjlkOGQ2NGJmNzA1OGVlYTE4ZDhjMjk0Mzk2ODdiMDc1Y2Q3Mg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YzEyZjJiMzc2NWVkYjk4NDdmYzU2ZTRmYjQ1NDhlNTVkZjdlYWUwODRiN2Q5
10
- Y2ViN2QyZGJiMTk3MTlkYjllYTc2NzEyZDZmZjE0MzVkNDFiYTI0MjA0NzA0
11
- NzViOWIwZTdhZWRmNzFjY2UwODU4NjA1NjA1MjczMDc0ZTM5ZTI=
9
+ YTMyMjg1NTNjOGJiYzIyZGVkMDUwYzMwNWMxZDA0NTRmOGRiYTljMWZmMWFk
10
+ YWQ1NjZmNmJlMmI0MDFlNzAxOGZhNDEwNTk5NDk3MmE4MjYyNzU3ZDc5ZGRh
11
+ YzY2Zjk1NDBlNjgzNjJkZjgzMDZkZTU5OThiZmZiM2QxMDM1NjI=
12
12
  data.tar.gz: !binary |-
13
- NTdlZTYwNDlhYjE3YTMwZGE4ZGRhM2FkN2M1ZmI3NTM4NGI2ZmIzOWM2Njg2
14
- ZGM2ZmQ2YjA4MmFiOWFjYTk5ODZkZGIwZDYxNmQ0YjI2MGMyMTdkZmYwYWE2
15
- ZGVkOTlhZWRhYjU3YTBjNzhkMTA2YWE5MTMwMGNhZDdhOWM2Mzc=
13
+ N2NjMWZlZWY2ZmIwMmZiZjBkZTljZjUzYzIzMDk5ZTBlODkzMDgxNTU0MjYz
14
+ Yzg3ZGNkMDc3ODdlZjUwOGRhZDVlNjk4NGJjOTI0YzAxMjkzNWE1YjQzZGFi
15
+ YmRlN2QwNDI2MDI2NmIxZTA1ODRjMWVjMGI1Nzk2ZjRmNjQ4Yzc=
@@ -1,5 +1,6 @@
1
1
  require 'active_support/core_ext/object'
2
2
  require 'active_support/core_ext/class'
3
+ require 'active_support/deprecation'
3
4
 
4
5
  module Cyrax::Extensions
5
6
  module HasCallbacks
@@ -17,6 +18,7 @@ module Cyrax::Extensions
17
18
 
18
19
  module ClassMethods
19
20
  def callbacks_handler(name, options = {})
21
+ ActiveSupport::Deprecation.warn "#callbacks_handler is deprecated. Redefine method and use short alias instead"
20
22
  self.resource_callbacks_handler_class = name
21
23
  end
22
24
  end
@@ -6,12 +6,14 @@ module Cyrax::Extensions
6
6
  respond_with build_collection, name: collection_name, present: :collection
7
7
  end
8
8
  alias_method :read_all, :collection
9
+ alias_method :read_all!, :collection
9
10
 
10
11
  def build
11
12
  respond_with build_resource(nil)
12
13
  end
14
+ alias_method :build!, :build
13
15
 
14
- def create(custom_attributes=nil)
16
+ def create(custom_attributes = nil, &block)
15
17
  resource = build_resource(nil, custom_attributes||resource_attributes)
16
18
  transaction do
17
19
  invoke_callback(:before_create, resource)
@@ -20,20 +22,24 @@ module Cyrax::Extensions
20
22
  invoke_callback(:after_create, resource)
21
23
  invoke_callback(:after_save, resource)
22
24
  set_message("#{resource_name.titleize} successfully created")
25
+ block.call if block_given?
23
26
  else
24
27
  add_errors_from(resource)
25
28
  end
26
29
  end
27
30
  respond_with(resource)
28
31
  end
32
+ alias_method :create!, :create
29
33
 
30
34
  def read
31
35
  respond_with find_resource(params[:id])
32
36
  end
37
+ alias_method :read!, :read
33
38
  alias_method :edit, :read
39
+ alias_method :edit!, :read
34
40
 
35
41
 
36
- def update(custom_attributes=nil)
42
+ def update(custom_attributes = nil, &block)
37
43
  resource = build_resource(params[:id], custom_attributes||resource_attributes)
38
44
  transaction do
39
45
  invoke_callback(:before_update, resource)
@@ -42,22 +48,26 @@ module Cyrax::Extensions
42
48
  invoke_callback(:after_update, resource)
43
49
  invoke_callback(:after_save, resource)
44
50
  set_message("#{resource_name.titleize} successfully updated")
51
+ block.call if block_given?
45
52
  else
46
53
  add_errors_from(resource)
47
54
  end
48
55
  end
49
56
  respond_with(resource)
50
57
  end
58
+ alias_method :update!, :update
51
59
 
52
- def destroy
60
+ def destroy(&block)
53
61
  resource = find_resource(params[:id])
54
62
  transaction do
55
63
  invoke_callback(:before_destroy, resource)
56
64
  delete_resource(resource)
57
65
  invoke_callback(:after_destroy, resource)
66
+ block.call if block_given?
58
67
  end
59
68
  respond_with(resource)
60
69
  end
70
+ alias_method :destroy!, :destroy
61
71
 
62
72
  def find_resource(id)
63
73
  resource_scope.find(id)
data/lib/cyrax/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cyrax
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cyrax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Droidlabs