cerializable 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cerializable/acts_as_cerializable.rb +5 -7
- data/lib/cerializable/version.rb +1 -1
- data/test/acts_as_cerializable_test.rb +19 -21
- data/test/dummy/config/application.rb +1 -2
- data/test/dummy/log/test.log +3288 -0
- metadata +5 -6
- data/README.rdoc +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bff4e40b2fa2bc45dd2a4e7f0950537c925bd78
|
4
|
+
data.tar.gz: 0867c588f5376bc7e1c5a3e313db95ccf7d9814f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
# #
|
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.
|
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.
|
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.
|
28
|
+
# > comment.cerializable_hash(only: id, methods: :hash])
|
29
29
|
# => { id: 1, hash: -2535926706119161824 }
|
30
30
|
#
|
31
|
-
def
|
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
|
data/lib/cerializable/version.rb
CHANGED
@@ -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
|
-
|
21
|
-
|
19
|
+
test "#{ model_class.name.downcase }cerializable_hash works as expected" do
|
20
|
+
instance = model_class.new
|
22
21
|
|
23
|
-
|
22
|
+
assert_equal instance.cerializable_hash, expected_result
|
24
23
|
|
25
|
-
|
26
|
-
|
24
|
+
# except option
|
25
|
+
assert_equal instance.cerializable_hash(except: :arbitraryKey1), expected_result.except(:arbitraryKey1)
|
27
26
|
|
28
|
-
|
29
|
-
|
27
|
+
assert_equal instance.cerializable_hash(except: [:arbitraryKey1, :arbitraryKey2]),
|
28
|
+
expected_result.except(:arbitraryKey1, :arbitraryKey2)
|
30
29
|
|
31
|
-
|
32
|
-
|
30
|
+
# only option
|
31
|
+
assert_equal instance.cerializable_hash(only: :arbitraryKey1), expected_result.slice(:arbitraryKey1)
|
33
32
|
|
34
|
-
|
35
|
-
|
33
|
+
assert_equal instance.cerializable_hash(only: [:arbitraryKey1, :arbitraryKey2]),
|
34
|
+
expected_result.slice(:arbitraryKey1, :arbitraryKey2)
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
# method option
|
37
|
+
assert_equal instance.cerializable_hash(methods: :object_id),
|
38
|
+
expected_result.merge(object_id: instance.object_id)
|
40
39
|
|
41
|
-
|
42
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|