transmutation 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ba12853e3bdaa79b39fb2a8fccb9ce4b1e29680a82529db9d54da2541a160fed
4
+ data.tar.gz: 5e0a34d360c2d898d894a83e003a747f4b80f75662e7c03549f760bf7aa6a96b
5
+ SHA512:
6
+ metadata.gz: 2118e6ff75bef0bc2a6c62fc13e2e66784d1a7777f1a6f1c62d32e9623a0a0e96e86fcbb7440eeec3bd87d4547b407a0f8078a13f9d72eed65d073e3813e223f
7
+ data.tar.gz: d843a53c5e0e687607f07b34e8bc4ce6755df867f3a6424f6bc37047a134e4b1901f94560d11a7d02e1c7d39931e4a2bd8e63e83150e9ff0420a83b090a2b19f
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+ NewCops: disable
4
+ SuggestExtensions: false
5
+
6
+ Style/StringLiterals:
7
+ Enabled: true
8
+ EnforcedStyle: double_quotes
9
+
10
+ Style/StringLiteralsInInterpolation:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Layout/LineLength:
15
+ Max: 120
16
+
17
+ require: rubocop-rspec
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-04-30
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at borrabeer@outlook.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in transmutation.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
13
+ gem "rubocop-rspec", require: false
14
+
15
+ gem "simplecov"
16
+ gem "simplecov-lcov"
17
+ gem "undercover"
data/Gemfile.lock ADDED
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ transmutation (0.1.0)
5
+ json
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ bigdecimal (3.1.7)
12
+ diff-lcs (1.5.1)
13
+ docile (1.4.0)
14
+ imagen (0.1.8)
15
+ parser (>= 2.5, != 2.5.1.1)
16
+ json (2.7.2)
17
+ language_server-protocol (3.17.0.3)
18
+ parallel (1.24.0)
19
+ parser (3.3.1.0)
20
+ ast (~> 2.4.1)
21
+ racc
22
+ racc (1.7.3)
23
+ rainbow (3.1.1)
24
+ rake (13.2.1)
25
+ regexp_parser (2.9.0)
26
+ rexml (3.2.6)
27
+ rspec (3.13.0)
28
+ rspec-core (~> 3.13.0)
29
+ rspec-expectations (~> 3.13.0)
30
+ rspec-mocks (~> 3.13.0)
31
+ rspec-core (3.13.0)
32
+ rspec-support (~> 3.13.0)
33
+ rspec-expectations (3.13.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.13.0)
36
+ rspec-mocks (3.13.0)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.13.0)
39
+ rspec-support (3.13.1)
40
+ rubocop (1.63.4)
41
+ json (~> 2.3)
42
+ language_server-protocol (>= 3.17.0)
43
+ parallel (~> 1.10)
44
+ parser (>= 3.3.0.2)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ regexp_parser (>= 1.8, < 3.0)
47
+ rexml (>= 3.2.5, < 4.0)
48
+ rubocop-ast (>= 1.31.1, < 2.0)
49
+ ruby-progressbar (~> 1.7)
50
+ unicode-display_width (>= 2.4.0, < 3.0)
51
+ rubocop-ast (1.31.3)
52
+ parser (>= 3.3.1.0)
53
+ rubocop-capybara (2.20.0)
54
+ rubocop (~> 1.41)
55
+ rubocop-factory_bot (2.25.1)
56
+ rubocop (~> 1.41)
57
+ rubocop-rspec (2.29.2)
58
+ rubocop (~> 1.40)
59
+ rubocop-capybara (~> 2.17)
60
+ rubocop-factory_bot (~> 2.22)
61
+ rubocop-rspec_rails (~> 2.28)
62
+ rubocop-rspec_rails (2.28.3)
63
+ rubocop (~> 1.40)
64
+ ruby-progressbar (1.13.0)
65
+ rugged (1.7.2)
66
+ simplecov (0.22.0)
67
+ docile (~> 1.1)
68
+ simplecov-html (~> 0.11)
69
+ simplecov_json_formatter (~> 0.1)
70
+ simplecov-html (0.12.3)
71
+ simplecov-lcov (0.8.0)
72
+ simplecov_json_formatter (0.1.4)
73
+ undercover (0.5.0)
74
+ bigdecimal
75
+ imagen (>= 0.1.8)
76
+ rainbow (>= 2.1, < 4.0)
77
+ rugged (>= 0.27, < 1.8)
78
+ unicode-display_width (2.5.0)
79
+
80
+ PLATFORMS
81
+ arm64-darwin-23
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ rake (~> 13.0)
86
+ rspec (~> 3.0)
87
+ rubocop (~> 1.21)
88
+ rubocop-rspec
89
+ simplecov
90
+ simplecov-lcov
91
+ transmutation!
92
+ undercover
93
+
94
+ BUNDLED WITH
95
+ 2.5.11
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Spellbook Technology
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # Transmutation
2
+
3
+ Transmutation is a Ruby gem that provides a simple way to serialize Ruby objects into JSON.
4
+
5
+ It takes inspiration from the [Active Model Serializers](https://github.com/rails-api/active_model_serializers) gem, but strips away adapters.
6
+
7
+ It aims to be a performant and elegant solution for serializing Ruby objects into JSON, with a touch of opinionated "magic" :sparkles:.
8
+
9
+ ## Installation
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add transmutation
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install transmutation
18
+
19
+ ## Usage
20
+
21
+ ### Basic Usage
22
+
23
+ - Define a serializer class that inherits from `Transmutation::Serializer` and define the attributes to be serialized.
24
+
25
+ ```ruby
26
+ class UserSerializer < Transmutation::Serializer
27
+ attributes :id, :name, :email
28
+ end
29
+ ```
30
+
31
+ - Serialize an object using the serializer class.
32
+
33
+ ```ruby
34
+ class User
35
+ attr_reader :id, :name, :email
36
+
37
+ def initialize(id:, name:, email:)
38
+ @id = id
39
+ @name = name
40
+ @email = email
41
+ end
42
+ end
43
+
44
+ user = User.new(id: 1, name: "John Doe", email: "john@example.com")
45
+
46
+ UserSerializer.new(user).to_json # => "{\"id\":1,\"name\":\"John Doe\",\"email\":\"john@example.com\"}"
47
+ ```
48
+
49
+ As long as your object responds to the attributes defined in the serializer, it can be serialized.
50
+
51
+ - Struct
52
+
53
+ ```ruby
54
+ User = Struct.new(:id, :name, :email)
55
+ ```
56
+
57
+ - Class
58
+
59
+ ```ruby
60
+ class User
61
+ attr_reader :id, :name, :email
62
+
63
+ def initialize(id:, name:, email:)
64
+ @id = id
65
+ @name = name
66
+ @email = email
67
+ end
68
+ end
69
+ ```
70
+
71
+ - ActiveRecord
72
+
73
+ ```ruby
74
+ # == Schema Information
75
+ #
76
+ # Table name: users
77
+ #
78
+ # id :bigint
79
+ # name :string
80
+ # email :string
81
+ class User < ApplicationRecord
82
+ end
83
+ ```
84
+
85
+ ### Using the `Transmutation::Serialization` module
86
+
87
+ ## Development
88
+
89
+ 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.
90
+
91
+ To install this gem onto your local machine, run `bundle exec rake install`. 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
92
+
93
+ ## Contributing
94
+
95
+ Bug reports and pull requests are welcome on GitHub at https://github.com/spellbook-technology/transmutation. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/spellbook-technology/transmutation/blob/main/CODE_OF_CONDUCT.md).
96
+
97
+ ## License
98
+
99
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
100
+
101
+ ## Code of Conduct
102
+
103
+ Everyone interacting in the Transmutation project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/spellbook-technology/transmutation/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new do |task|
11
+ task.requires << "rubocop-rspec"
12
+ end
13
+
14
+ task default: %i[spec rubocop]
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Transmutation
4
+ class CollectionSerializer # rubocop:disable Style/Documentation
5
+ include Transmutation::Serialization
6
+
7
+ def initialize(objects, namespace: "", serializer: nil)
8
+ @objects = objects
9
+ @namespace = namespace
10
+ @serializer = serializer
11
+ end
12
+
13
+ def as_json(options = {})
14
+ serializers = serialize(objects, namespace: namespace, serializer: serializer)
15
+
16
+ serializers.map do |serializer|
17
+ serializer.as_json(options)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :objects, :namespace, :serializer
24
+ end
25
+ end
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Transmutation # rubocop:disable Style/Documentation
4
+ using Transmutation::StringRefinements
5
+
6
+ module Serialization # rubocop:disable Style/Documentation
7
+ def self.included(base)
8
+ caller_class = (base.instance_of?(Class) ? base.to_s : self.class.to_s)
9
+ caller_namespace = caller_class.include?("::") ? caller_class.split("::").first : ""
10
+ base.class_eval do
11
+ @caller_namespace = caller_namespace
12
+ end
13
+ end
14
+
15
+ BY_CALLER_NAMESPACE_WITH_NAMESPACE_AND_SERIALIZER = lambda do |caller, _resource_class, namespace:, serializer:|
16
+ caller_namespace = namespace.to_s.include?("::") ? "" : get_caller_namespace(caller.class)
17
+
18
+ converted_namespace = convert_namespace(namespace)
19
+
20
+ converted_serializer = convert_serializer(serializer)
21
+
22
+ serializer_name = serializer_from_resource_name(converted_serializer)
23
+
24
+ "#{caller_namespace}::#{converted_namespace}::#{serializer_name}"
25
+ end
26
+
27
+ BY_RESOURCE_CALLER_NAMESPACE_WITH_NAMESPACE = lambda do |caller, resource_class, namespace:, **_|
28
+ caller_namespace = namespace.to_s.include?("::") ? "" : get_caller_namespace(caller.class)
29
+
30
+ converted_namespace = convert_namespace(namespace)
31
+
32
+ serializer_name = serializer_from_resource_name(resource_class)
33
+
34
+ "#{caller_namespace}::#{converted_namespace}::#{serializer_name}"
35
+ end
36
+
37
+ BY_CALLER_NAMESPACE_WITH_SERIALIZER = lambda do |caller, _resource_class, serializer:, **_|
38
+ caller_namespace = get_caller_namespace(caller.class)
39
+
40
+ converted_serializer = convert_serializer(serializer)
41
+
42
+ serializer_name = serializer_from_resource_name(converted_serializer)
43
+
44
+ "#{caller_namespace}::#{serializer_name}"
45
+ end
46
+
47
+ BY_RESOURCE_CALLER_NAMESPACE = lambda do |caller, resource_class, **_|
48
+ caller_namespace = get_caller_namespace(caller.class)
49
+
50
+ serializer_name = serializer_from_resource_name(resource_class)
51
+
52
+ "#{caller_namespace}::#{serializer_name}"
53
+ end
54
+
55
+ BY_RESOURCE = lambda do |_caller, resource_class, **_|
56
+ serializer_name = serializer_from_resource_name(resource_class)
57
+
58
+ "::#{serializer_name}"
59
+ end
60
+
61
+ LOOKUP_STRATEGIES = [
62
+ BY_CALLER_NAMESPACE_WITH_NAMESPACE_AND_SERIALIZER,
63
+ BY_RESOURCE_CALLER_NAMESPACE_WITH_NAMESPACE,
64
+ BY_CALLER_NAMESPACE_WITH_SERIALIZER,
65
+ BY_RESOURCE_CALLER_NAMESPACE,
66
+ BY_RESOURCE
67
+ ].freeze
68
+
69
+ def lookup_serializer(object, namespace: "", serializer: nil)
70
+ lookup_serializer!(object, namespace: namespace, serializer: serializer)
71
+ rescue NameError
72
+ nil
73
+ end
74
+
75
+ def render(**args)
76
+ return super(**args) unless args[:json]
77
+ return super(**args) if args[:serialize] == false
78
+
79
+ super(**args, json: serialize(args[:json]))
80
+ end
81
+
82
+ def lookup_serializer!(object, namespace: "", serializer: nil)
83
+ LOOKUP_STRATEGIES.each do |strategy|
84
+ return Object.const_get(strategy.call(self, object.class, namespace: namespace, serializer: serializer))
85
+ rescue NameError
86
+ next
87
+ end
88
+
89
+ raise NameError, "Serializer not found for #{object.class}"
90
+ end
91
+
92
+ def serialize(object, namespace: "", serializer: nil)
93
+ unless object.respond_to?(:map)
94
+ return lookup_serializer!(object, namespace: namespace,
95
+ serializer: serializer).new(object)
96
+ end
97
+
98
+ object.map do |entry_object|
99
+ lookup_serializer!(entry_object, namespace: namespace, serializer: serializer).new(entry_object)
100
+ end
101
+ end
102
+
103
+ module_function
104
+
105
+ def get_caller_namespace(base)
106
+ base.class_eval do
107
+ @caller_namespace
108
+ end
109
+ end
110
+
111
+ def convert_namespace(namespace)
112
+ namespace.to_s.camelcase
113
+ end
114
+
115
+ def convert_serializer(serializer)
116
+ serializer.to_s.camelcase.gsub("Serializer", "")
117
+ end
118
+
119
+ def serializer_from_resource_name(name)
120
+ "#{name}Serializer"
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Transmutation
6
+ class Serializer # rubocop:disable Style/Documentation
7
+ def initialize(object)
8
+ @object = object
9
+ end
10
+
11
+ def to_json(options = {})
12
+ as_json(options).to_json
13
+ end
14
+
15
+ def as_json(_options = {})
16
+ _attributes.each_with_object({}) do |(attr_name, attr_options), hash|
17
+ hash[attr_name.to_s] = attr_options[:block] ? instance_exec(&attr_options[:block]) : object.send(attr_name)
18
+ end
19
+ end
20
+
21
+ def self.attribute(attr_name, &block)
22
+ _attributes[attr_name] = { block: block }
23
+ end
24
+
25
+ def self.attributes(*attr_name)
26
+ attr_name.each do |name|
27
+ attribute(name)
28
+ end
29
+ end
30
+
31
+ def self._attributes
32
+ @@attributes ||= {} # rubocop:disable Style/ClassVars
33
+ end
34
+
35
+ def _attributes
36
+ self.class._attributes
37
+ end
38
+
39
+ private
40
+
41
+ attr_reader :object
42
+ end
43
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Transmutation
4
+ module StringRefinements # rubocop:disable Style/Documentation
5
+ DELIMITERS = %r{[a-z][A-Z]|\s*-\s*|\s*/\s*|\s*:+\s*|\s*_\s*|\s+}
6
+
7
+ refine String do
8
+ def camelcase
9
+ return capitalize unless match? DELIMITERS
10
+
11
+ split(%r{\s*-\s*|\s*/\s*|\s*:+\s*}).then { |parts| combine parts, :capitalize, "::" }
12
+ .then { |text| text.split(/\s*_\s*|\s+/) }
13
+ .then { |parts| combine parts, :capitalize }
14
+ end
15
+
16
+ def first(maximum = 0)
17
+ return self if empty?
18
+ return self[0] if maximum.zero?
19
+ return "" if maximum.negative?
20
+
21
+ self[..(maximum - 1)]
22
+ end
23
+
24
+ def capitalize = empty? ? self : first.upcase + self[1, size]
25
+
26
+ private
27
+
28
+ def combine(parts, method, delimiter = "")
29
+ parts.reduce "" do |result, part|
30
+ next part.public_send method if result.empty?
31
+
32
+ "#{result}#{delimiter}#{part.__send__ method}"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Transmutation
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "transmutation/version"
4
+ require_relative "transmutation/string_refinements"
5
+ require_relative "transmutation/serializer"
6
+ require_relative "transmutation/serialization"
7
+ require_relative "transmutation/collection_serializer"
8
+
9
+ module Transmutation
10
+ class Error < StandardError; end
11
+ end
@@ -0,0 +1,4 @@
1
+ module Transmutation
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: transmutation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - nitemaeric
8
+ - borrabeer
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2024-05-30 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email:
16
+ - daniel@spellbook.tech
17
+ - worapath.pakkavesa@spellbook.tech
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".rspec"
23
+ - ".rubocop.yml"
24
+ - ".ruby-version"
25
+ - CHANGELOG.md
26
+ - CODE_OF_CONDUCT.md
27
+ - Gemfile
28
+ - Gemfile.lock
29
+ - LICENSE
30
+ - README.md
31
+ - Rakefile
32
+ - lib/transmutation.rb
33
+ - lib/transmutation/collection_serializer.rb
34
+ - lib/transmutation/serialization.rb
35
+ - lib/transmutation/serializer.rb
36
+ - lib/transmutation/string_refinements.rb
37
+ - lib/transmutation/version.rb
38
+ - sig/transmutation.rbs
39
+ homepage: https://github.com/spellbook-technology/transmutation
40
+ licenses:
41
+ - MIT
42
+ metadata:
43
+ homepage_uri: https://github.com/spellbook-technology/transmutation
44
+ source_code_uri: https://github.com/spellbook-technology/transmutation
45
+ changelog_uri: https://github.com/spellbook-technology/transmutation/CHANGELOG.md
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.2.33
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Ruby JSON serialization library
65
+ test_files: []