kix 1.0.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: 73cbb48e3bf3d401859dc5e0bbd21ad01c46a903688c521ae329b34046ac0ad4
4
+ data.tar.gz: '09ad8c04fcf1a91d335383f9c8f17106e844acc1ccaea134e0f79e719f936a00'
5
+ SHA512:
6
+ metadata.gz: 42338e47cae7cc16e94d77fbb08adda60cfc3a7ca977eab03e66657b4fe6d32bff7ee6d5a2ec30e303851f7101f7e05dee3415b600b0bf2627e4c67fe6f32f1b
7
+ data.tar.gz: 226f94242b9a68f53aecebe0fe5afe16abdda44ad8110573c20ee2d735a3ccedea81223cf1a8c1c990f1e3b1f9dae18d9317967fb09e433397742ee93eee1757
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ kix-*.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-04-21
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in kix.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,89 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kix (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
+ rake (13.0.3)
33
+ regexp_parser (2.1.1)
34
+ rexml (3.2.5)
35
+ rspec (3.10.0)
36
+ rspec-core (~> 3.10.0)
37
+ rspec-expectations (~> 3.10.0)
38
+ rspec-mocks (~> 3.10.0)
39
+ rspec-core (3.10.1)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-expectations (3.10.1)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-mocks (3.10.2)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.10.0)
47
+ rspec-support (3.10.2)
48
+ rubocop (1.12.1)
49
+ parallel (~> 1.10)
50
+ parser (>= 3.0.0.0)
51
+ rainbow (>= 2.2.2, < 4.0)
52
+ regexp_parser (>= 1.8, < 3.0)
53
+ rexml
54
+ rubocop-ast (>= 1.2.0, < 2.0)
55
+ ruby-progressbar (~> 1.7)
56
+ unicode-display_width (>= 1.4.0, < 3.0)
57
+ rubocop-ast (1.4.1)
58
+ parser (>= 2.7.1.5)
59
+ rubocop-performance (1.10.1)
60
+ rubocop (>= 0.90.0, < 2.0)
61
+ rubocop-ast (>= 0.4.0)
62
+ ruby-progressbar (1.11.0)
63
+ simplecov (0.21.2)
64
+ docile (~> 1.1)
65
+ simplecov-html (~> 0.11)
66
+ simplecov_json_formatter (~> 0.1)
67
+ simplecov-html (0.12.3)
68
+ simplecov_json_formatter (0.1.2)
69
+ standard (1.0.5)
70
+ rubocop (= 1.12.1)
71
+ rubocop-performance (= 1.10.1)
72
+ tzinfo (2.0.4)
73
+ concurrent-ruby (~> 1.0)
74
+ unicode-display_width (2.0.0)
75
+ zeitwerk (2.4.2)
76
+
77
+ PLATFORMS
78
+ x86_64-linux
79
+
80
+ DEPENDENCIES
81
+ kix!
82
+ pry
83
+ rake (~> 13.0)
84
+ rspec (~> 3.0)
85
+ simplecov
86
+ standard
87
+
88
+ BUNDLED WITH
89
+ 2.2.15
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 TODO: Write your name
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,68 @@
1
+ # Kix
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kix`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'kix'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install kix
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ class UserSerializer < Kix::Serializer
27
+ attributes :name, :email, :phone, :skippable
28
+
29
+ def phone
30
+ _object.phone_number || "N/A"
31
+ end
32
+
33
+ def skippable
34
+ # throw skip if you want to omit this attribute entirely
35
+ throw(:skip)
36
+ end
37
+ end
38
+
39
+ class User
40
+ include Kix::Serializable
41
+ attr_reader :name, :email, :phone_number
42
+
43
+ def initialize(name, email, phone_number = nil)
44
+ @name = name
45
+ @email = email
46
+ @phone_number = phone_number
47
+ end
48
+ end
49
+ ```
50
+
51
+ ```ruby
52
+ User.new("John", "john@example.com").as_json
53
+ #=> {"name"=>"John", "email"=>"john@example.com", "phone"=>"N/A"}
54
+ ```
55
+
56
+ ## Development
57
+
58
+ 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.
59
+
60
+ 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).
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kix.
65
+
66
+ ## License
67
+
68
+ 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,8 @@
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
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "kix"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/kix.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/kix/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "kix"
7
+ spec.version = Kix::VERSION
8
+ spec.authors = ["John Thomas"]
9
+ spec.email = ["thomas07@vt.edu"]
10
+
11
+ spec.summary = "A gem to serialize objects using a similar API to active_model_serializers"
12
+ spec.homepage = "https://github.com/thomas07vt/kix"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/thomas07vt/kix"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "activesupport"
31
+
32
+ spec.add_development_dependency "rspec"
33
+ spec.add_development_dependency "pry"
34
+ spec.add_development_dependency "standard"
35
+ spec.add_development_dependency "simplecov"
36
+ end
data/lib/kix.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
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 "kix/version.rb"
8
+ require_relative "kix/serializer.rb"
9
+ require_relative "kix/serializable.rb"
10
+
11
+ module Kix
12
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kix
4
+ module Serializable
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ # This forces autoloading of the constant.
9
+ serializer("#{self}Serializer".constantize)
10
+ rescue NameError
11
+ end
12
+
13
+ class_methods do
14
+ def inherited(klass)
15
+ super
16
+ klass.serializer(serializer)
17
+ end
18
+
19
+ def serializer(klass = nil)
20
+ @serializer = klass if klass
21
+ @serializer
22
+ end
23
+ end
24
+
25
+ def as_json(*args)
26
+ return super unless self.class.serializer
27
+
28
+ self.class.serializer.new(self).as_json(*args)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kix
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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kix
4
+ VERSION = "1.0.0"
5
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kix
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - John Thomas
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-04-21 00:00:00.000000000 Z
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: standard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
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'
83
+ description:
84
+ email:
85
+ - thomas07@vt.edu
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - CHANGELOG.md
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - kix.gemspec
101
+ - lib/kix.rb
102
+ - lib/kix/serializable.rb
103
+ - lib/kix/serializer.rb
104
+ - lib/kix/version.rb
105
+ homepage: https://github.com/thomas07vt/kix
106
+ licenses:
107
+ - MIT
108
+ metadata:
109
+ allowed_push_host: https://rubygems.org
110
+ homepage_uri: https://github.com/thomas07vt/kix
111
+ source_code_uri: https://github.com/thomas07vt/kix
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 2.4.0
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubygems_version: 3.2.15
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: A gem to serialize objects using a similar API to active_model_serializers
131
+ test_files: []