bed 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +47 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +8 -0
- data/lib/bed/schema.rb +99 -0
- data/lib/bed/version.rb +5 -0
- data/lib/bed.rb +9 -0
- data/sig/bed.rbs +4 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1377de7e50abf7f48aba8a104bc6fce6be53bc7b5fef46f18a08c34de88f12fb
|
4
|
+
data.tar.gz: ef45d49fa33044142cf8eab1cc1a0caa2fa6f791467396509ac1746d2d96239c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1ee08f53a9b7ccca782708880be79fb327832029e6e99942016d029446fa0310c7515998b3da521d03eed7ed48926ee577a25cfa0669cec0ed025f59fd44cee5
|
7
|
+
data.tar.gz: 1d74e2f6cb14269c6164b54f95ca4c1bcb8a0893a7f080eedb9573c89fdbe5f1d0c139d991913b1f17f795787bd654f6fdd01b0d7c52a688f15ddfb6e40d21bd
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Code of Conduct
|
2
|
+
|
3
|
+
## Our Commitment
|
4
|
+
|
5
|
+
We are committed to fostering a respectful and productive environment for all project contributors.
|
6
|
+
|
7
|
+
## Expected Behavior
|
8
|
+
|
9
|
+
Contributors are expected to:
|
10
|
+
|
11
|
+
- Treat others with respect and professionalism
|
12
|
+
- Provide and accept constructive feedback graciously
|
13
|
+
- Own their actions and decisions
|
14
|
+
- Prioritize the needs of the project
|
15
|
+
- Keep discussions and contributions focused on the project or task at hand
|
16
|
+
|
17
|
+
## Unacceptable Behavior
|
18
|
+
|
19
|
+
The following behaviors are considered unacceptable:
|
20
|
+
|
21
|
+
- Harassment or discrimination of any kind
|
22
|
+
- Offensive comments or personal attacks
|
23
|
+
- Sharing others' private information without consent
|
24
|
+
- Any conduct deemed inappropriate in a professional setting
|
25
|
+
- Engaging in political discussions
|
26
|
+
- Integrating personal political views into contributions
|
27
|
+
|
28
|
+
## Enforcement
|
29
|
+
|
30
|
+
Project maintainers are responsible for enforcing these standards. They may take appropriate action in response to any
|
31
|
+
behavior that violates this Code of Conduct, including temporary or permanent bans from project communication channels
|
32
|
+
or from contributing to the project itself.
|
33
|
+
|
34
|
+
## Reporting Violations
|
35
|
+
|
36
|
+
Violations can be reported to the repository owner or project maintainers.
|
37
|
+
|
38
|
+
All reports will be reviewed promptly and treated confidentially.
|
39
|
+
|
40
|
+
## Scope
|
41
|
+
|
42
|
+
This Code of Conduct applies to all communication channels related to the project and when representing the project in
|
43
|
+
public spaces.
|
44
|
+
|
45
|
+
## Attribution
|
46
|
+
|
47
|
+
This Code of Conduct is adapted from the Contributor Covenant, version 2.1.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 David Gillis
|
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,39 @@
|
|
1
|
+
# Bed
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
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/bed`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
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).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bed. 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/[USERNAME]/bed/blob/master/CODE_OF_CONDUCT.md).
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
36
|
+
|
37
|
+
## Code of Conduct
|
38
|
+
|
39
|
+
Everyone interacting in the Bed project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/bed/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/lib/bed/schema.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
class Bed::Schema < Data
|
2
|
+
def self.define_with_types(**kwargs)
|
3
|
+
puts 'defining...'
|
4
|
+
old_kwdargs = kwargs
|
5
|
+
kwargs = kwargs.transform_values do |v|
|
6
|
+
v.superclass == Data ? v.new : v
|
7
|
+
end
|
8
|
+
|
9
|
+
keys = kwargs.keys
|
10
|
+
|
11
|
+
puts kwargs
|
12
|
+
|
13
|
+
init_block = Proc.new do
|
14
|
+
define_method :initialize do |args = nil|
|
15
|
+
case args
|
16
|
+
in Hash
|
17
|
+
super(**kwargs.merge(args))
|
18
|
+
in Array
|
19
|
+
super(kwargs.merge(args))
|
20
|
+
else
|
21
|
+
super(**kwargs)
|
22
|
+
end
|
23
|
+
|
24
|
+
unless args.nil?
|
25
|
+
# raise ArgumentError, 'Invalid arguments' unless validate
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
alias_method :_deconstruct, :deconstruct
|
30
|
+
|
31
|
+
define_method :deconstruct do
|
32
|
+
puts 'deconstructing...'
|
33
|
+
val = _deconstruct
|
34
|
+
case val
|
35
|
+
in *beginning, Class => data, *ending
|
36
|
+
[*beginning, *data.deconstruct, *ending]
|
37
|
+
in [*rest, Data => data]
|
38
|
+
[*rest, *data.deconstruct]
|
39
|
+
in [Data => data, *rest]
|
40
|
+
[*data.deconstruct, *rest]
|
41
|
+
else
|
42
|
+
_deconstruct
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
alias_method :_deconstruct_keys, :deconstruct_keys
|
47
|
+
|
48
|
+
define_method :deconstruct_keys do |keys = self.class.schema.keys|
|
49
|
+
puts keys
|
50
|
+
_deconstruct_keys(keys)
|
51
|
+
# _deconstruct_keys(keys).transform_values do |v|
|
52
|
+
# v.respond_to?(:deconstruct_keys) ? v.deconstruct_keys(keys) : v
|
53
|
+
# end
|
54
|
+
end
|
55
|
+
|
56
|
+
define_method :to_hash do
|
57
|
+
to_h.transform_values do |v|
|
58
|
+
v.respond_to?(:to_hash) ? v.to_hash : v
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
define_method :validate do
|
63
|
+
arr = self.class.new.deconstruct
|
64
|
+
pattern = <<-RUBY
|
65
|
+
case self
|
66
|
+
in #{arr}
|
67
|
+
true
|
68
|
+
else
|
69
|
+
false
|
70
|
+
end
|
71
|
+
RUBY
|
72
|
+
eval(pattern)
|
73
|
+
end
|
74
|
+
|
75
|
+
define_singleton_method :schema do
|
76
|
+
old_kwdargs
|
77
|
+
end
|
78
|
+
|
79
|
+
define_singleton_method :create_nested_objects do |grouped_data|
|
80
|
+
grouped_data.to_a.reverse.reduce(nil) do |inner, (klass, values)|
|
81
|
+
args = values.map(&:first)
|
82
|
+
args << inner if inner
|
83
|
+
klass.new(*args)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
define_singleton_method :go do
|
88
|
+
schema.values.map { |v| v.respond_to?(:superclass) && v.superclass == Data ? v.go : self }.flatten
|
89
|
+
end
|
90
|
+
|
91
|
+
define_singleton_method :reconstruct do |*args|
|
92
|
+
grouped = args.zip(go).group_by(&:last)
|
93
|
+
|
94
|
+
create_nested_objects(grouped)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
Data.define(*keys, &init_block)
|
98
|
+
end
|
99
|
+
end
|
data/lib/bed/version.rb
ADDED
data/lib/bed.rb
ADDED
data/sig/bed.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Gillis
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-08-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Bed is a simple, modern schema library built on top of Data. It provides
|
14
|
+
a simple, declarative way to define schemas for your data, and a way to validate
|
15
|
+
that data against those schemas.
|
16
|
+
email:
|
17
|
+
- david.gillis@hey.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- CODE_OF_CONDUCT.md
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/bed.rb
|
27
|
+
- lib/bed/schema.rb
|
28
|
+
- lib/bed/version.rb
|
29
|
+
- sig/bed.rbs
|
30
|
+
homepage: https://github.com/gillisd/bed
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata:
|
34
|
+
homepage_uri: https://github.com/gillisd/bed
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 3.0.0
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubygems_version: 3.5.11
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: A simple, modern schema library built on top of Data class
|
54
|
+
test_files: []
|