cerializable 0.0.2 → 0.1.0

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: 866c7ffb7a38212c8b1cf2aa4f893f9a588a9f5f
4
- data.tar.gz: 1d25745ee5cbff5341ba728cdd3faf746a94519b
3
+ metadata.gz: 2bff4e40b2fa2bc45dd2a4e7f0950537c925bd78
4
+ data.tar.gz: 0867c588f5376bc7e1c5a3e313db95ccf7d9814f
5
5
  SHA512:
6
- metadata.gz: 2e86e558bb4069e9b2b79b90e673ae3684a170876e5d974ad5a8d3dda13a69bcb255616ed3dc1805de010f42028135379740b1ac35a520af77fa45b9993d9253
7
- data.tar.gz: e9fa4bffee2db8e6f638f0802f7f1b1ac438fa5758eddba29ce2a4d0879d6a68d622eeefd48e32c8b7adf6c9fe10c88131247838a0ac0b374e8a8af6bc9fe0d7
6
+ metadata.gz: c01555f13d8220d3630f9ada2fc089d98cdb38db5f2344fa5cceba5253b4ae7592fc5c01eb022240c83f9982fabbd9bc1449c9eb1108439f97c5c89bd1167887
7
+ data.tar.gz: bad20fdf34f007a426302e61ec50f9d1a4346469eb24b00d585155e60c90ec65c7d7a8907ad596da6c8d9e6299995400563d5f8cce1d8baae33f71e067553630
@@ -3,19 +3,19 @@ module Cerializable
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- # #serializable_hash delegates to the #run method of the model's 'cerializer' object.
6
+ # #cerializable_hash delegates to the #run method of the model's 'cerializer' object.
7
7
  #
8
8
  # It accepts `:only`, `:except`, and `:methods` options which can be passed as a
9
9
  # symbol or as an array of symbols.
10
10
  #
11
11
  # Using the `:only` option will return a hash that only has the specified keys.
12
12
  #
13
- # > comment.serializable_hash(only: :id)
13
+ # > comment.cerializable_hash(only: :id)
14
14
  # => { id: 1 }
15
15
  #
16
16
  # Using the `:except` option will return a hash that has all default keys except those specified.
17
17
  #
18
- # > comment.serializable_hash(except: [:id, :user_id])
18
+ # > comment.cerializable_hash(except: [:id, :user_id])
19
19
  # => { body: '...sushi? ;)', deleted_at: nil }
20
20
  #
21
21
  # Using the `:methods` option add will add a key and value for each method specified.
@@ -25,10 +25,10 @@ module Cerializable
25
25
  #
26
26
  # The :methods option is processed after the :only and :except options.
27
27
  #
28
- # > comment.serializable_hash(only: id, methods: :hash])
28
+ # > comment.cerializable_hash(only: id, methods: :hash])
29
29
  # => { id: 1, hash: -2535926706119161824 }
30
30
  #
31
- def serializable_hash(options = {})
31
+ def cerializable_hash(options = {})
32
32
  [:only, :except, :methods].each do |option_name|
33
33
  next if options[option_name].nil?
34
34
 
@@ -58,8 +58,6 @@ module Cerializable
58
58
  hash
59
59
  end
60
60
 
61
- alias :as_json :serializable_hash
62
- alias :to_json :serializable_hash
63
61
  end
64
62
 
65
63
  module ClassMethods
@@ -1,3 +1,3 @@
1
1
  module Cerializable
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -15,36 +15,34 @@ class ActsAsCerializableTest < ActiveSupport::TestCase
15
15
  end
16
16
 
17
17
  expected_result = model_class.send(:default_json_representation)
18
- [:serializable_hash, :as_json, :to_json].each do |method_name|
19
18
 
20
- test "#{ model_class.name.downcase }##{ method_name } works as expected" do
21
- instance = model_class.send(:new)
19
+ test "#{ model_class.name.downcase }cerializable_hash works as expected" do
20
+ instance = model_class.new
22
21
 
23
- assert_equal instance.send(method_name), expected_result
22
+ assert_equal instance.cerializable_hash, expected_result
24
23
 
25
- # except option
26
- assert_equal instance.send(method_name, except: :arbitraryKey1), expected_result.except(:arbitraryKey1)
24
+ # except option
25
+ assert_equal instance.cerializable_hash(except: :arbitraryKey1), expected_result.except(:arbitraryKey1)
27
26
 
28
- assert_equal instance.send(method_name, except: [:arbitraryKey1, :arbitraryKey2]),
29
- expected_result.except(:arbitraryKey1, :arbitraryKey2)
27
+ assert_equal instance.cerializable_hash(except: [:arbitraryKey1, :arbitraryKey2]),
28
+ expected_result.except(:arbitraryKey1, :arbitraryKey2)
30
29
 
31
- # only option
32
- assert_equal instance.send(method_name, only: :arbitraryKey1), expected_result.slice(:arbitraryKey1)
30
+ # only option
31
+ assert_equal instance.cerializable_hash(only: :arbitraryKey1), expected_result.slice(:arbitraryKey1)
33
32
 
34
- assert_equal instance.send(method_name, only: [:arbitraryKey1, :arbitraryKey2]),
35
- expected_result.slice(:arbitraryKey1, :arbitraryKey2)
33
+ assert_equal instance.cerializable_hash(only: [:arbitraryKey1, :arbitraryKey2]),
34
+ expected_result.slice(:arbitraryKey1, :arbitraryKey2)
36
35
 
37
- # method option
38
- assert_equal instance.send(method_name, methods: :object_id),
39
- expected_result.merge(object_id: instance.object_id)
36
+ # method option
37
+ assert_equal instance.cerializable_hash(methods: :object_id),
38
+ expected_result.merge(object_id: instance.object_id)
40
39
 
41
- assert_equal instance.send(method_name, methods: [:object_id, :hash]),
42
- expected_result.merge(object_id: instance.object_id, hash: instance.hash)
40
+ assert_equal instance.cerializable_hash(methods: [:object_id, :hash]),
41
+ expected_result.merge(object_id: instance.object_id, hash: instance.hash)
43
42
 
44
- # custom option
45
- assert_equal instance.send(method_name, custom_option: true),
46
- expected_result.merge(customOption: '( ͡° ͜ʖ ͡°)')
47
- end
43
+ # custom option
44
+ assert_equal instance.cerializable_hash(custom_option: true),
45
+ expected_result.merge(customOption: '( ͡° ͜ʖ ͡°)')
48
46
  end
49
47
 
50
48
  }
@@ -20,7 +20,6 @@ module Dummy
20
20
  # config.i18n.default_locale = :de
21
21
 
22
22
  # Do not swallow errors in after_commit/after_rollback callbacks.
23
- config.active_record.raise_in_transactional_callbacks = true
23
+ #config.active_record.raise_in_transactional_callbacks = true
24
24
  end
25
25
  end
26
-