bright_serializer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/build.yml +24 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +33 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +66 -0
- data/LICENSE.txt +21 -0
- data/README.md +143 -0
- data/Rakefile +8 -0
- data/bright_serializer.gemspec +44 -0
- data/lib/bright_serializer.rb +7 -0
- data/lib/bright_serializer/attribute.rb +35 -0
- data/lib/bright_serializer/inflector.rb +32 -0
- data/lib/bright_serializer/serializer.rb +79 -0
- data/lib/bright_serializer/version.rb +5 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 411805a8af30f74b73f325ddbd820914d524a3134d1d5d0b9346eb738e9eda59
|
4
|
+
data.tar.gz: 13f44da90680dc3e4058c9888c3711d7c4adb0933ff827757d3aafd95696fbc1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d962a5e41755e14504f97a61b32530e7e5e5236e497b884a6fdf23e599b07ad41ab62acb0e9487b7b0fa39882bbe65dbd6df0f99c74a4a15dc10800095fab422
|
7
|
+
data.tar.gz: 9ed35fa977a777408c84a93ff4e917c0a1f12cadd785b5d88906df8d691a3801138c9144c173ce375e5140bdfe785272149839f7f5358cc843eb0b1459c5223c
|
@@ -0,0 +1,24 @@
|
|
1
|
+
name: Build
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v1
|
12
|
+
- name: Set up Ruby 2.7
|
13
|
+
uses: actions/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: 2.7
|
16
|
+
- name: Bundle install
|
17
|
+
run: |
|
18
|
+
gem install bundler
|
19
|
+
bundle install --jobs 4 --retry 3
|
20
|
+
- name: Specs
|
21
|
+
run: bundle exec rake
|
22
|
+
- name: Rubocop
|
23
|
+
run: bundle exec rubocop
|
24
|
+
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
Metrics/BlockLength:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Layout/LineLength:
|
9
|
+
Max: 120
|
10
|
+
|
11
|
+
Style/Documentation:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
RSpec/ExampleLength:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
RSpec/NamedSubject:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Gemspec/RequiredRubyVersion:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Metrics/PerceivedComplexity:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Metrics/MethodLength:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Metrics/CyclomaticComplexity:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Metrics/AbcSize:
|
33
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.1
|
data/CHANGELOG.md
ADDED
File without changes
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
|
+
|
7
|
+
# Specify your gem's dependencies in bright_serializer.gemspec
|
8
|
+
gemspec
|
9
|
+
|
10
|
+
gem 'oj', require: false
|
11
|
+
|
12
|
+
group :test do
|
13
|
+
gem 'faker'
|
14
|
+
gem 'rubocop'
|
15
|
+
gem 'rubocop-performance'
|
16
|
+
gem 'rubocop-rspec'
|
17
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bright_serializer (0.1.0)
|
5
|
+
oj (~> 3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.0)
|
11
|
+
concurrent-ruby (1.1.5)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
faker (2.9.0)
|
14
|
+
i18n (>= 1.6, < 1.8)
|
15
|
+
i18n (1.7.0)
|
16
|
+
concurrent-ruby (~> 1.0)
|
17
|
+
jaro_winkler (1.5.4)
|
18
|
+
oj (3.10.0)
|
19
|
+
parallel (1.19.1)
|
20
|
+
parser (2.7.0.0)
|
21
|
+
ast (~> 2.4.0)
|
22
|
+
rainbow (3.0.0)
|
23
|
+
rake (13.0.1)
|
24
|
+
rspec (3.9.0)
|
25
|
+
rspec-core (~> 3.9.0)
|
26
|
+
rspec-expectations (~> 3.9.0)
|
27
|
+
rspec-mocks (~> 3.9.0)
|
28
|
+
rspec-core (3.9.2)
|
29
|
+
rspec-support (~> 3.9.3)
|
30
|
+
rspec-expectations (3.9.2)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.9.0)
|
33
|
+
rspec-mocks (3.9.1)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.9.0)
|
36
|
+
rspec-support (3.9.3)
|
37
|
+
rubocop (0.78.0)
|
38
|
+
jaro_winkler (~> 1.5.1)
|
39
|
+
parallel (~> 1.10)
|
40
|
+
parser (>= 2.6)
|
41
|
+
rainbow (>= 2.2.2, < 4.0)
|
42
|
+
ruby-progressbar (~> 1.7)
|
43
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
44
|
+
rubocop-performance (1.5.2)
|
45
|
+
rubocop (>= 0.71.0)
|
46
|
+
rubocop-rspec (1.37.1)
|
47
|
+
rubocop (>= 0.68.1)
|
48
|
+
ruby-progressbar (1.10.1)
|
49
|
+
unicode-display_width (1.6.0)
|
50
|
+
|
51
|
+
PLATFORMS
|
52
|
+
ruby
|
53
|
+
|
54
|
+
DEPENDENCIES
|
55
|
+
bright_serializer!
|
56
|
+
bundler (~> 2)
|
57
|
+
faker
|
58
|
+
oj
|
59
|
+
rake (~> 13.0)
|
60
|
+
rspec (~> 3.0)
|
61
|
+
rubocop
|
62
|
+
rubocop-performance
|
63
|
+
rubocop-rspec
|
64
|
+
|
65
|
+
BUNDLED WITH
|
66
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Jean-Francis Bastien
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
[![Actions Status](https://github.com/petalmd/bright_serializer/workflows/Build/badge.svg)](https://github.com/petalmd/bright_serializer/actions?query=workflow%3ABuild)
|
2
|
+
|
3
|
+
# BrightSerializer
|
4
|
+
|
5
|
+
This is a very light and fast gem to serialize object in a Ruby project.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'bright_serializer'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install bright_serializer
|
22
|
+
|
23
|
+
## Usage and features
|
24
|
+
|
25
|
+
### Basic
|
26
|
+
|
27
|
+
Create a class and include `BrightSerializer::Serializer`
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
class AccountSerializer
|
31
|
+
include BrightSerializer::Serializer
|
32
|
+
attributes :id, :first_name, :last_name
|
33
|
+
|
34
|
+
# With a block
|
35
|
+
attribute :name do |object|
|
36
|
+
"#{object.first_name} #{object.last_name}"
|
37
|
+
end
|
38
|
+
|
39
|
+
# With a block shorter
|
40
|
+
attribute :created_at, &:to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
AccountSerializer.new(Account.first).to_h
|
44
|
+
AccountSerializer.new(Account.first).to_json
|
45
|
+
```
|
46
|
+
|
47
|
+
### Params
|
48
|
+
|
49
|
+
You can pass params to your serializer. For example to have more context with the authenticated user.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
class AccountSerializer
|
53
|
+
include BrightSerializer::Serializer
|
54
|
+
attributes :id, :first_name, :last_name
|
55
|
+
|
56
|
+
attribute :friend do |object, params|
|
57
|
+
object.is_friend_with? params[:current_user]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
current_user = Account.find(authenticated_account_id)
|
62
|
+
AccountSerializer.new(Account.first, params: { current_user: current_user }).to_json
|
63
|
+
```
|
64
|
+
|
65
|
+
### Conditional Attributes
|
66
|
+
|
67
|
+
Attribute can be remove from serialization by passing a `proc` to the option `if`. If the proc return `true` the attibute
|
68
|
+
will be serialize. `object` and `params` or accessible.
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
class AccountSerializer
|
72
|
+
include BrightSerializer::Serializer
|
73
|
+
attributes :id, :first_name, :last_name
|
74
|
+
|
75
|
+
attribute :email, if: -> { |object, params| params[:current_user].is_admin? }
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
### Transform keys
|
80
|
+
|
81
|
+
By default, keys or not transformed.
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
class AccountSerializer
|
85
|
+
include BrightSerializer::Serializer
|
86
|
+
set_key_transform :underscore
|
87
|
+
end
|
88
|
+
|
89
|
+
set_key_transform :underscore # "first_name" => "first_name"
|
90
|
+
set_key_transform :camel # "first_name" => "FirstName"
|
91
|
+
set_key_transform :camel_lower # "first_name" => "firstName"
|
92
|
+
set_key_transform :dash # "first_name" => "first-name"
|
93
|
+
```
|
94
|
+
|
95
|
+
### Instance serializer fieldsets
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
class AccountSerializer
|
99
|
+
include BrightSerializer::Serializer
|
100
|
+
attributes :id, :first_name, :last_name
|
101
|
+
end
|
102
|
+
|
103
|
+
# Only serialize first_name and last_name
|
104
|
+
AccountSerializer.new(Account.first, fields: [:first_name, :last_name]).to_json
|
105
|
+
```
|
106
|
+
|
107
|
+
### Relations
|
108
|
+
|
109
|
+
For now, relations or declared like any other attribute.
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
class FriendSerializer
|
113
|
+
include BrightSerializer::Serializer
|
114
|
+
attributes :id, :first_name, :last_name
|
115
|
+
end
|
116
|
+
|
117
|
+
class AccountSerializer
|
118
|
+
include BrightSerializer::Serializer
|
119
|
+
attributes :id, :first_name, :last_name
|
120
|
+
|
121
|
+
attribute :friends do |object|
|
122
|
+
FriendSerializer.new(object.friends)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
```
|
126
|
+
|
127
|
+
## Development
|
128
|
+
|
129
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
130
|
+
|
131
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
132
|
+
|
133
|
+
## New release
|
134
|
+
|
135
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
136
|
+
|
137
|
+
## Contributing
|
138
|
+
|
139
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/petalmd/bright_serializer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
140
|
+
|
141
|
+
## License
|
142
|
+
|
143
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'bright_serializer/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'bright_serializer'
|
9
|
+
spec.version = BrightSerializer::VERSION
|
10
|
+
spec.authors = ['Jean-Francis Bastien']
|
11
|
+
spec.email = ['jfbastien@petalmd.com']
|
12
|
+
|
13
|
+
spec.summary = 'T O D O: Write a short summary, because RubyGems requires one.'
|
14
|
+
spec.description = 'T O D O: Write a longer description or delete this line.'
|
15
|
+
spec.homepage = 'https://github.com/petalmd/bright_serializer'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
spec.required_ruby_version = '>= 2.5'
|
18
|
+
|
19
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
20
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
21
|
+
if spec.respond_to?(:metadata)
|
22
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
23
|
+
spec.metadata['source_code_uri'] = 'https://github.com/petalmd/bright_serializer'
|
24
|
+
spec.metadata['changelog_uri'] = 'https://github.com/petalmd/bright_serializer/blob/master/CHANGELOG.md'
|
25
|
+
else
|
26
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
27
|
+
'public gem pushes.'
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = 'exe'
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ['lib']
|
38
|
+
|
39
|
+
spec.add_runtime_dependency 'oj', '~> 3'
|
40
|
+
spec.add_development_dependency 'bundler', '~> 2'
|
41
|
+
spec.add_development_dependency 'faker', '~> 2'
|
42
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
43
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
44
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BrightSerializer
|
4
|
+
class Attribute
|
5
|
+
attr_reader :key, :block, :condition
|
6
|
+
attr_accessor :transformed_key
|
7
|
+
|
8
|
+
def initialize(key, condition, &block)
|
9
|
+
@key = key
|
10
|
+
@condition = condition
|
11
|
+
@block = block
|
12
|
+
end
|
13
|
+
|
14
|
+
def serialize(object, params)
|
15
|
+
return unless object
|
16
|
+
|
17
|
+
value =
|
18
|
+
if @block
|
19
|
+
@block.arity.abs == 1 ? object.instance_eval(&@block) : object.instance_exec(object, params, &@block)
|
20
|
+
elsif object.is_a?(Hash)
|
21
|
+
object[key]
|
22
|
+
else
|
23
|
+
object.send(key)
|
24
|
+
end
|
25
|
+
|
26
|
+
value.respond_to?(:serializable_hash) ? value.serializable_hash : value
|
27
|
+
end
|
28
|
+
|
29
|
+
def condition?(object, params)
|
30
|
+
return true unless @condition
|
31
|
+
|
32
|
+
@condition.call(object, params)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Inflector
|
4
|
+
CAMEL_REGEX = /(_[a-zA-Z])/.freeze
|
5
|
+
UNDERSCORE_REGEX = /(.)([A-Z])/.freeze
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def camel(term)
|
9
|
+
return term.capitalize! unless term.include?('_')
|
10
|
+
|
11
|
+
term.capitalize!
|
12
|
+
term.gsub!(CAMEL_REGEX) { Regexp.last_match(1).delete('_').upcase! }
|
13
|
+
end
|
14
|
+
|
15
|
+
def camel_lower(term)
|
16
|
+
return term unless term.include?('_')
|
17
|
+
|
18
|
+
term.gsub!(CAMEL_REGEX) { Regexp.last_match(1).delete('_').upcase! }
|
19
|
+
end
|
20
|
+
|
21
|
+
def underscore(camel_cased_word)
|
22
|
+
camel_cased_word.gsub!(UNDERSCORE_REGEX, '\1_\2')
|
23
|
+
camel_cased_word.downcase!
|
24
|
+
camel_cased_word
|
25
|
+
end
|
26
|
+
|
27
|
+
def dash(underscored_word)
|
28
|
+
underscored_word.tr!('_', '-')
|
29
|
+
underscored_word
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oj'
|
4
|
+
require 'set'
|
5
|
+
require_relative 'attribute'
|
6
|
+
require_relative 'inflector'
|
7
|
+
|
8
|
+
module BrightSerializer
|
9
|
+
module Serializer
|
10
|
+
SUPPORTED_TRANSFORMATION = %i[camel camel_lower dash underscore].freeze
|
11
|
+
DEFAULT_OJ_OPTIONS = { mode: :compat, time_format: :ruby, use_to_json: true }.freeze
|
12
|
+
|
13
|
+
def self.included(base)
|
14
|
+
base.extend ClassMethods
|
15
|
+
base.instance_variable_set(:@attributes_to_serialize, [])
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(object, **options)
|
19
|
+
@object = object
|
20
|
+
@params = options.delete(:params)
|
21
|
+
@fields = Set.new(options.delete(:fields))
|
22
|
+
end
|
23
|
+
|
24
|
+
def serialize(object)
|
25
|
+
self.class.attributes_to_serialize.each_with_object({}) do |attribute, result|
|
26
|
+
next if @fields.any? && !@fields.include?(attribute.key)
|
27
|
+
next unless attribute.condition?(object, @params)
|
28
|
+
|
29
|
+
result[attribute.transformed_key] = attribute.serialize(object, @params)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def serializable_hash
|
34
|
+
if @object.respond_to?(:size) && !@object.respond_to?(:each_pair)
|
35
|
+
@object.map { |o| serialize o }
|
36
|
+
else
|
37
|
+
serialize(@object)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
alias to_hash serializable_hash
|
42
|
+
|
43
|
+
def serializable_json(*_args)
|
44
|
+
::Oj.dump(to_hash, DEFAULT_OJ_OPTIONS)
|
45
|
+
end
|
46
|
+
|
47
|
+
alias to_json serializable_json
|
48
|
+
|
49
|
+
module ClassMethods
|
50
|
+
attr_reader :attributes_to_serialize, :transform_method
|
51
|
+
|
52
|
+
def attributes(*attributes, **options, &block)
|
53
|
+
attributes.each do |key|
|
54
|
+
attribute = Attribute.new(key, options[:if], &block)
|
55
|
+
attribute.transformed_key = run_transform_key(key)
|
56
|
+
@attributes_to_serialize << attribute
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
alias attribute attributes
|
61
|
+
|
62
|
+
def set_key_transform(transform_name) # rubocop:disable Naming/AccessorMethodName
|
63
|
+
unless SUPPORTED_TRANSFORMATION.include?(transform_name)
|
64
|
+
raise ArgumentError "Invalid transformation: #{SUPPORTED_TRANSFORMATION}"
|
65
|
+
end
|
66
|
+
|
67
|
+
@transform_method = transform_name
|
68
|
+
end
|
69
|
+
|
70
|
+
def run_transform_key(input)
|
71
|
+
if transform_method
|
72
|
+
Inflector.send(@transform_method, input.to_s).to_sym
|
73
|
+
else
|
74
|
+
input.to_sym
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bright_serializer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jean-Francis Bastien
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oj
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faker
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '13.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: 'T O D O: Write a longer description or delete this line.'
|
84
|
+
email:
|
85
|
+
- jfbastien@petalmd.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".github/workflows/build.yml"
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".ruby-version"
|
95
|
+
- CHANGELOG.md
|
96
|
+
- Gemfile
|
97
|
+
- Gemfile.lock
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- bright_serializer.gemspec
|
102
|
+
- lib/bright_serializer.rb
|
103
|
+
- lib/bright_serializer/attribute.rb
|
104
|
+
- lib/bright_serializer/inflector.rb
|
105
|
+
- lib/bright_serializer/serializer.rb
|
106
|
+
- lib/bright_serializer/version.rb
|
107
|
+
homepage: https://github.com/petalmd/bright_serializer
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata:
|
111
|
+
homepage_uri: https://github.com/petalmd/bright_serializer
|
112
|
+
source_code_uri: https://github.com/petalmd/bright_serializer
|
113
|
+
changelog_uri: https://github.com/petalmd/bright_serializer/blob/master/CHANGELOG.md
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '2.5'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubygems_version: 3.1.2
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: 'T O D O: Write a short summary, because RubyGems requires one.'
|
133
|
+
test_files: []
|