alba 0.12.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +34 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +28 -2
- data/CHANGELOG.md +25 -0
- data/Gemfile +10 -4
- data/README.md +269 -37
- data/Rakefile +4 -1
- data/alba.gemspec +2 -2
- data/benchmark/local.rb +315 -0
- data/codecov.yml +5 -0
- data/gemfiles/all.gemfile +19 -0
- data/gemfiles/without_active_support.gemfile +17 -0
- data/gemfiles/without_oj.gemfile +17 -0
- data/lib/alba.rb +42 -19
- data/lib/alba/association.rb +22 -7
- data/lib/alba/key_transformer.rb +32 -0
- data/lib/alba/many.rb +8 -4
- data/lib/alba/one.rb +8 -4
- data/lib/alba/resource.rb +146 -57
- data/lib/alba/version.rb +1 -1
- metadata +13 -8
- data/.travis.yml +0 -10
- data/Gemfile.lock +0 -92
- data/lib/alba/serializer.rb +0 -77
data/.travis.yml
DELETED
data/Gemfile.lock
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
alba (0.12.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
activesupport (6.1.1)
|
10
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
-
i18n (>= 1.6, < 2)
|
12
|
-
minitest (>= 5.1)
|
13
|
-
tzinfo (~> 2.0)
|
14
|
-
zeitwerk (~> 2.3)
|
15
|
-
ast (2.4.1)
|
16
|
-
concurrent-ruby (1.1.7)
|
17
|
-
coveralls (0.8.23)
|
18
|
-
json (>= 1.8, < 3)
|
19
|
-
simplecov (~> 0.16.1)
|
20
|
-
term-ansicolor (~> 1.3)
|
21
|
-
thor (>= 0.19.4, < 2.0)
|
22
|
-
tins (~> 1.6)
|
23
|
-
docile (1.3.2)
|
24
|
-
i18n (1.8.7)
|
25
|
-
concurrent-ruby (~> 1.0)
|
26
|
-
json (2.3.1)
|
27
|
-
minitest (5.14.3)
|
28
|
-
oj (3.11.0)
|
29
|
-
parallel (1.20.1)
|
30
|
-
parser (3.0.0.0)
|
31
|
-
ast (~> 2.4.1)
|
32
|
-
rainbow (3.0.0)
|
33
|
-
rake (13.0.3)
|
34
|
-
regexp_parser (2.0.3)
|
35
|
-
rexml (3.2.4)
|
36
|
-
rubocop (1.8.1)
|
37
|
-
parallel (~> 1.10)
|
38
|
-
parser (>= 3.0.0.0)
|
39
|
-
rainbow (>= 2.2.2, < 4.0)
|
40
|
-
regexp_parser (>= 1.8, < 3.0)
|
41
|
-
rexml
|
42
|
-
rubocop-ast (>= 1.2.0, < 2.0)
|
43
|
-
ruby-progressbar (~> 1.7)
|
44
|
-
unicode-display_width (>= 1.4.0, < 3.0)
|
45
|
-
rubocop-ast (1.4.0)
|
46
|
-
parser (>= 2.7.1.5)
|
47
|
-
rubocop-minitest (0.10.3)
|
48
|
-
rubocop (>= 0.87, < 2.0)
|
49
|
-
rubocop-performance (1.9.2)
|
50
|
-
rubocop (>= 0.90.0, < 2.0)
|
51
|
-
rubocop-ast (>= 0.4.0)
|
52
|
-
rubocop-rake (0.5.1)
|
53
|
-
rubocop
|
54
|
-
rubocop-sensible (0.3.0)
|
55
|
-
rubocop (>= 0.60.0)
|
56
|
-
ruby-progressbar (1.11.0)
|
57
|
-
simplecov (0.16.1)
|
58
|
-
docile (~> 1.1)
|
59
|
-
json (>= 1.8, < 3)
|
60
|
-
simplecov-html (~> 0.10.0)
|
61
|
-
simplecov-html (0.10.2)
|
62
|
-
sync (0.5.0)
|
63
|
-
term-ansicolor (1.7.1)
|
64
|
-
tins (~> 1.0)
|
65
|
-
thor (1.0.1)
|
66
|
-
tins (1.25.0)
|
67
|
-
sync
|
68
|
-
tzinfo (2.0.4)
|
69
|
-
concurrent-ruby (~> 1.0)
|
70
|
-
unicode-display_width (2.0.0)
|
71
|
-
yard (0.9.26)
|
72
|
-
zeitwerk (2.4.2)
|
73
|
-
|
74
|
-
PLATFORMS
|
75
|
-
ruby
|
76
|
-
|
77
|
-
DEPENDENCIES
|
78
|
-
activesupport
|
79
|
-
alba!
|
80
|
-
coveralls
|
81
|
-
minitest (~> 5.14)
|
82
|
-
oj (~> 3.11)
|
83
|
-
rake (~> 13.0)
|
84
|
-
rubocop (>= 0.79.0)
|
85
|
-
rubocop-minitest (~> 0.10.3)
|
86
|
-
rubocop-performance (~> 1.9.2)
|
87
|
-
rubocop-rake (>= 0.5.1)
|
88
|
-
rubocop-sensible (~> 0.3.0)
|
89
|
-
yard
|
90
|
-
|
91
|
-
BUNDLED WITH
|
92
|
-
2.2.6
|
data/lib/alba/serializer.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
module Alba
|
2
|
-
# This module represents how a resource should be serialized.
|
3
|
-
module Serializer
|
4
|
-
# @!parse include InstanceMethods
|
5
|
-
# @!parse extend ClassMethods
|
6
|
-
|
7
|
-
# @private
|
8
|
-
def self.included(base)
|
9
|
-
super
|
10
|
-
base.class_eval do
|
11
|
-
@_opts = {} unless instance_variable_defined?('@_opts')
|
12
|
-
@_metadata = {} unless instance_variable_defined?('@_metadata')
|
13
|
-
end
|
14
|
-
base.include InstanceMethods
|
15
|
-
base.extend ClassMethods
|
16
|
-
end
|
17
|
-
|
18
|
-
# Instance methods
|
19
|
-
module InstanceMethods
|
20
|
-
# @param resource [Alba::Resource]
|
21
|
-
def initialize(resource)
|
22
|
-
@resource = resource
|
23
|
-
@hash = resource.serializable_hash
|
24
|
-
@hash = {key.to_sym => @hash} if key
|
25
|
-
# @hash is either Hash or Array
|
26
|
-
unless metadata.empty?
|
27
|
-
@hash.is_a?(Hash) ? @hash.merge!(metadata.to_h) : @hash << metadata
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# Use real encoder to actually serialize to JSON
|
32
|
-
#
|
33
|
-
# @return [String] JSON string
|
34
|
-
def serialize
|
35
|
-
Alba.encoder.call(@hash)
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def key
|
41
|
-
opts = self.class._opts
|
42
|
-
opts[:key] == true ? @resource.key : opts[:key]
|
43
|
-
end
|
44
|
-
|
45
|
-
def metadata
|
46
|
-
metadata = self.class._metadata
|
47
|
-
metadata.transform_values { |block| block.call(@resource.object) }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# Class methods
|
52
|
-
module ClassMethods
|
53
|
-
attr_reader :_opts, :_metadata
|
54
|
-
|
55
|
-
# @private
|
56
|
-
def inherited(subclass)
|
57
|
-
super
|
58
|
-
%w[_opts _metadata].each { |name| subclass.instance_variable_set("@#{name}", public_send(name).clone) }
|
59
|
-
end
|
60
|
-
|
61
|
-
# Set options, currently key only
|
62
|
-
#
|
63
|
-
# @param key [Boolean, Symbol]
|
64
|
-
def set(key: false)
|
65
|
-
@_opts[:key] = key
|
66
|
-
end
|
67
|
-
|
68
|
-
# Set metadata
|
69
|
-
#
|
70
|
-
# @param name [String, Symbol] key for the metadata
|
71
|
-
# @param block [Block] the content of the metadata
|
72
|
-
def metadata(name, &block)
|
73
|
-
@_metadata[name.to_sym] = block
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|