serializable_rails 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -4
- data/Gemfile.lock +87 -0
- data/lib/serializable_rails.rb +7 -3
- data/lib/serializable_rails/serializable.rb +29 -0
- data/lib/serializable_rails/serializer.rb +38 -0
- data/lib/serializable_rails/version.rb +1 -1
- data/serializable_rails.gemspec +3 -0
- metadata +32 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b98ff5c7420edebd790125fdaa685fa3e7d73dbcce0e7f437f4d1458672103a9
|
4
|
+
data.tar.gz: be7fee76f0b0c3ee8b99ddfaca22f616f34f5fa03632eed79cd8f92973a063c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3d0f673fe0d4b69aca2d54890af686bd138eb62ebfaba0afb0884b5a095cfe7c655ffec2d5690cca1722baf05882d0db85de24908b98d6a22ac2aa392dc3aa3
|
7
|
+
data.tar.gz: 5e28dae08f3ffea90b35d5e70f2196d52e3e8b5512c6a18bc68d6478e5557623487170cbfc9518c3a5b693e17666967776c486a811c6b2dfe37f4b5d44f6d45f
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
serializable_rails (0.1.0)
|
5
|
+
activesupport
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (6.1.3.1)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (>= 1.6, < 2)
|
13
|
+
minitest (>= 5.1)
|
14
|
+
tzinfo (~> 2.0)
|
15
|
+
zeitwerk (~> 2.3)
|
16
|
+
ast (2.4.2)
|
17
|
+
coderay (1.1.3)
|
18
|
+
concurrent-ruby (1.1.8)
|
19
|
+
diff-lcs (1.4.4)
|
20
|
+
docile (1.3.5)
|
21
|
+
i18n (1.8.10)
|
22
|
+
concurrent-ruby (~> 1.0)
|
23
|
+
method_source (1.0.0)
|
24
|
+
minitest (5.14.4)
|
25
|
+
parallel (1.20.1)
|
26
|
+
parser (3.0.1.0)
|
27
|
+
ast (~> 2.4.1)
|
28
|
+
pry (0.14.1)
|
29
|
+
coderay (~> 1.1)
|
30
|
+
method_source (~> 1.0)
|
31
|
+
rainbow (3.0.0)
|
32
|
+
regexp_parser (2.1.1)
|
33
|
+
rexml (3.2.5)
|
34
|
+
rspec (3.10.0)
|
35
|
+
rspec-core (~> 3.10.0)
|
36
|
+
rspec-expectations (~> 3.10.0)
|
37
|
+
rspec-mocks (~> 3.10.0)
|
38
|
+
rspec-core (3.10.1)
|
39
|
+
rspec-support (~> 3.10.0)
|
40
|
+
rspec-expectations (3.10.1)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.10.0)
|
43
|
+
rspec-mocks (3.10.2)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.10.0)
|
46
|
+
rspec-support (3.10.2)
|
47
|
+
rubocop (1.12.1)
|
48
|
+
parallel (~> 1.10)
|
49
|
+
parser (>= 3.0.0.0)
|
50
|
+
rainbow (>= 2.2.2, < 4.0)
|
51
|
+
regexp_parser (>= 1.8, < 3.0)
|
52
|
+
rexml
|
53
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
54
|
+
ruby-progressbar (~> 1.7)
|
55
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
56
|
+
rubocop-ast (1.4.1)
|
57
|
+
parser (>= 2.7.1.5)
|
58
|
+
rubocop-performance (1.10.1)
|
59
|
+
rubocop (>= 0.90.0, < 2.0)
|
60
|
+
rubocop-ast (>= 0.4.0)
|
61
|
+
ruby-progressbar (1.11.0)
|
62
|
+
simplecov (0.21.2)
|
63
|
+
docile (~> 1.1)
|
64
|
+
simplecov-html (~> 0.11)
|
65
|
+
simplecov_json_formatter (~> 0.1)
|
66
|
+
simplecov-html (0.12.3)
|
67
|
+
simplecov_json_formatter (0.1.2)
|
68
|
+
standard (1.0.5)
|
69
|
+
rubocop (= 1.12.1)
|
70
|
+
rubocop-performance (= 1.10.1)
|
71
|
+
tzinfo (2.0.4)
|
72
|
+
concurrent-ruby (~> 1.0)
|
73
|
+
unicode-display_width (2.0.0)
|
74
|
+
zeitwerk (2.4.2)
|
75
|
+
|
76
|
+
PLATFORMS
|
77
|
+
x86_64-linux
|
78
|
+
|
79
|
+
DEPENDENCIES
|
80
|
+
pry
|
81
|
+
rspec
|
82
|
+
serializable_rails!
|
83
|
+
simplecov
|
84
|
+
standard
|
85
|
+
|
86
|
+
BUNDLED WITH
|
87
|
+
2.2.15
|
data/lib/serializable_rails.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "active_support"
|
4
|
+
require "active_support/core_ext/object/json.rb"
|
5
|
+
require "active_support/core_ext/string/inflections.rb"
|
6
|
+
|
7
|
+
require_relative "serializable_rails/version.rb"
|
8
|
+
require_relative "serializable_rails/serializer.rb"
|
9
|
+
require_relative "serializable_rails/serializable.rb"
|
4
10
|
|
5
11
|
module SerializableRails
|
6
|
-
class Error < StandardError; end
|
7
|
-
# Your code goes here...
|
8
12
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module SerializableRails
|
2
|
+
module Serializable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
# This forces autoloading of the constant.
|
7
|
+
serializer("#{self}Serializer".constantize)
|
8
|
+
rescue NameError
|
9
|
+
end
|
10
|
+
|
11
|
+
class_methods do
|
12
|
+
def inherited(klass)
|
13
|
+
super
|
14
|
+
klass.serializer(serializer)
|
15
|
+
end
|
16
|
+
|
17
|
+
def serializer(klass = nil)
|
18
|
+
@serializer = klass if klass
|
19
|
+
@serializer
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def as_json(*args)
|
24
|
+
return super unless self.class.serializer
|
25
|
+
|
26
|
+
self.class.serializer.new(self).as_json(*args)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SerializableRails
|
4
|
+
class Serializer
|
5
|
+
attr_reader :_object
|
6
|
+
|
7
|
+
def initialize(object)
|
8
|
+
@_object = object
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_json(*args)
|
12
|
+
self.class.defined_attributes.each_with_object({}) { |attr, h|
|
13
|
+
catch(:skip) { h[attr] = value_for(attr, args).as_json }
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def value_for(attr, args)
|
20
|
+
if respond_to?(attr)
|
21
|
+
send(attr)
|
22
|
+
else
|
23
|
+
_object.send(attr)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class << self
|
28
|
+
def attributes(*attrs)
|
29
|
+
attrs.each { |attr| defined_attributes.push(attr.to_s) }
|
30
|
+
end
|
31
|
+
alias_method :attribute, :attributes
|
32
|
+
|
33
|
+
def defined_attributes
|
34
|
+
@defined_attributes ||= []
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/serializable_rails.gemspec
CHANGED
@@ -27,7 +27,10 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
+
spec.add_dependency "activesupport"
|
31
|
+
|
30
32
|
spec.add_development_dependency "rspec"
|
31
33
|
spec.add_development_dependency "pry"
|
32
34
|
spec.add_development_dependency "standard"
|
35
|
+
spec.add_development_dependency "simplecov"
|
33
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serializable_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Thomas
|
@@ -10,6 +10,20 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2021-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rspec
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,20 @@ dependencies:
|
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
description:
|
56
84
|
email:
|
57
85
|
- thomas07@vt.edu
|
@@ -63,12 +91,15 @@ files:
|
|
63
91
|
- ".rspec"
|
64
92
|
- CHANGELOG.md
|
65
93
|
- Gemfile
|
94
|
+
- Gemfile.lock
|
66
95
|
- LICENSE.txt
|
67
96
|
- README.md
|
68
97
|
- Rakefile
|
69
98
|
- bin/console
|
70
99
|
- bin/setup
|
71
100
|
- lib/serializable_rails.rb
|
101
|
+
- lib/serializable_rails/serializable.rb
|
102
|
+
- lib/serializable_rails/serializer.rb
|
72
103
|
- lib/serializable_rails/version.rb
|
73
104
|
- serializable_rails.gemspec
|
74
105
|
homepage: https://github.com/thomas07vt/serializable_rails
|