objectize 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/.irbrc +4 -0
- data/.rspec +3 -0
- data/.rubocop.yml +104 -0
- data/.ruby-version +1 -0
- data/.streerc +9 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE +21 -0
- data/README.md +51 -0
- data/Rakefile +7 -0
- data/lib/objectize/version.rb +3 -0
- data/lib/objectize.rb +37 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3c6d460e1bba365ba6ca8feaf05c5f169a6ea311bb083dbec0cb0eca14bad228
|
4
|
+
data.tar.gz: b50f428ece6080e328300d986b504d9f79982104c21e5f30c1769ab1073298d3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f59e3e82119475a24ac36e1b4638720c9bb70355cbe258d7867d8bad88e444ebb615f52446daaf3b5a03529c82572c8211da469b1c39142b07936a5598ec344
|
7
|
+
data.tar.gz: 7e77899a7840e5d2be877c17d128bce87a9a366ec977a5ef13f28c67cbeb62ab9e37e947e3e6d0c270debe0a530a84e4e031c523f977f8aabd81b98da925fda7
|
data/.irbrc
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rake
|
4
|
+
- rubocop-rspec
|
5
|
+
- rubocop-rubycw
|
6
|
+
- standard
|
7
|
+
- standard-custom
|
8
|
+
- standard-performance
|
9
|
+
|
10
|
+
inherit_gem:
|
11
|
+
standard: config/base.yml
|
12
|
+
standard-performance: config/base.yml
|
13
|
+
standard-custom: config/base.yml
|
14
|
+
syntax_tree: config/rubocop.yml
|
15
|
+
|
16
|
+
inherit_mode:
|
17
|
+
merge:
|
18
|
+
- Exclude
|
19
|
+
|
20
|
+
AllCops:
|
21
|
+
NewCops: enable
|
22
|
+
Exclude:
|
23
|
+
- 'bin/**/*'
|
24
|
+
- 'tmp/**/*'
|
25
|
+
- 'vendor/**/*'
|
26
|
+
|
27
|
+
Bundler/OrderedGems:
|
28
|
+
Enabled: true
|
29
|
+
|
30
|
+
Layout/LineLength:
|
31
|
+
Max: 100
|
32
|
+
Layout/SpaceInsideHashLiteralBraces:
|
33
|
+
EnforcedStyle: space
|
34
|
+
|
35
|
+
Metrics/ClassLength:
|
36
|
+
Max: 250
|
37
|
+
Metrics/MethodLength:
|
38
|
+
Max: 30
|
39
|
+
Exclude:
|
40
|
+
- 'spec/**/*'
|
41
|
+
Metrics/ModuleLength:
|
42
|
+
Max: 250
|
43
|
+
Exclude:
|
44
|
+
- 'spec/**/*'
|
45
|
+
Metrics/ParameterLists:
|
46
|
+
Max: 3
|
47
|
+
CountKeywordArgs: false
|
48
|
+
Exclude:
|
49
|
+
- 'spec/**/*'
|
50
|
+
|
51
|
+
RSpec/AnyInstance:
|
52
|
+
Enabled: false
|
53
|
+
RSpec/BeEq:
|
54
|
+
Enabled: false
|
55
|
+
RSpec/ContextWording:
|
56
|
+
Prefixes:
|
57
|
+
- when
|
58
|
+
RSpec/DescribedClass:
|
59
|
+
EnforcedStyle: explicit
|
60
|
+
RSpec/EmptyLineAfterFinalLet:
|
61
|
+
Enabled: false
|
62
|
+
RSpec/ExampleLength:
|
63
|
+
Max: 30
|
64
|
+
RSpec/ImplicitExpect:
|
65
|
+
EnforcedStyle: should
|
66
|
+
RSpec/ImplicitSubject:
|
67
|
+
Enabled: false
|
68
|
+
RSpec/IndexedLet:
|
69
|
+
Max: 2
|
70
|
+
RSpec/MatchArray:
|
71
|
+
Enabled: false
|
72
|
+
RSpec/MessageChain:
|
73
|
+
Enabled: false
|
74
|
+
RSpec/MissingExampleGroupArgument:
|
75
|
+
Enabled: false
|
76
|
+
RSpec/MultipleExpectations:
|
77
|
+
Enabled: false
|
78
|
+
RSpec/NestedGroups:
|
79
|
+
Max: 6
|
80
|
+
RSpec/VerifiedDoubles:
|
81
|
+
Enabled: false
|
82
|
+
RSpec/VoidExpect:
|
83
|
+
Exclude:
|
84
|
+
- 'spec/support/*'
|
85
|
+
|
86
|
+
Style/ClassMethodsDefinitions:
|
87
|
+
Enabled: true
|
88
|
+
Style/CollectionMethods:
|
89
|
+
Enabled: true
|
90
|
+
Style/DisableCopsWithinSourceCodeDirective:
|
91
|
+
Enabled: true
|
92
|
+
Style/GlobalStdStream:
|
93
|
+
Enabled: false
|
94
|
+
Style/GlobalVars:
|
95
|
+
Enabled: false
|
96
|
+
Style/RescueStandardError:
|
97
|
+
EnforcedStyle: explicit
|
98
|
+
Style/StringLiterals:
|
99
|
+
EnforcedStyle: single_quotes
|
100
|
+
Style/StringLiteralsInInterpolation:
|
101
|
+
EnforcedStyle: single_quotes
|
102
|
+
Style/UnlessLogicalOperators:
|
103
|
+
Enabled: true
|
104
|
+
EnforcedStyle: forbid_logical_operators
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-3.3.2
|
data/.streerc
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Jerome Dalbert
|
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,51 @@
|
|
1
|
+
# Objectize
|
2
|
+
|
3
|
+
This gem converts hashes into objects, so you can do `my_object.a.b.c`
|
4
|
+
instead of `my_hash['a']['b']['c']`. It works with deeply nested hashes and
|
5
|
+
arrays.
|
6
|
+
|
7
|
+
This can be useful for API responses and other nested data.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Install the gem globally:
|
12
|
+
|
13
|
+
```
|
14
|
+
gem install objectize
|
15
|
+
```
|
16
|
+
|
17
|
+
Or add this line to your Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'objectize'
|
21
|
+
```
|
22
|
+
|
23
|
+
and run `bundle install`.
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
my_object = Objectize.to_object(a: { b: { c: 'foo' } })
|
29
|
+
my_object.a.b.c #=> 'foo'
|
30
|
+
```
|
31
|
+
|
32
|
+
To revert an objectized element back to a basic type, you can do:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
my_hash = Objectize.to_basic_type(my_object)
|
36
|
+
my_hash['a']['b']['c'] #=> 'foo'
|
37
|
+
```
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
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.
|
42
|
+
|
43
|
+
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).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jeromedalbert/objectize. 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/jeromedalbert/objectize/blob/main/CODE_OF_CONDUCT.md).
|
48
|
+
|
49
|
+
## Code of Conduct
|
50
|
+
|
51
|
+
Everyone interacting in the Objectize project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jeromedalbert/objectize/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/lib/objectize.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
require_relative 'objectize/version'
|
3
|
+
|
4
|
+
module Objectize
|
5
|
+
module_function
|
6
|
+
|
7
|
+
# Converts a hash or array of hashes into an object.
|
8
|
+
#
|
9
|
+
# my_object = Objectize.to_object(a: { b: { c: 'foo' } })
|
10
|
+
# my_object.a.b.c #=> 'foo'
|
11
|
+
def to_object(element)
|
12
|
+
case element
|
13
|
+
when Hash
|
14
|
+
Hashie::Mash.new(element)
|
15
|
+
when Array
|
16
|
+
element.map { |sub_element| to_object(sub_element) }
|
17
|
+
else
|
18
|
+
element
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Converts an objectized element back to a basic type (i.e. a hash or an
|
23
|
+
# array of hashes)
|
24
|
+
#
|
25
|
+
# my_hash = Objectize.to_basic_type(my_object)
|
26
|
+
# my_hash['a']['b']['c'] #=> 'foo'
|
27
|
+
def to_basic_type(element)
|
28
|
+
case element
|
29
|
+
when Hashie::Mash
|
30
|
+
element.to_hash
|
31
|
+
when Array
|
32
|
+
element.map { |sub_element| to_basic_type(sub_element) }
|
33
|
+
else
|
34
|
+
element
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: objectize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jerome Dalbert
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hashie
|
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
|
+
description: Transforms hashes into objects. Check documentation at https://github.com/jeromedalbert/objectize.
|
28
|
+
email:
|
29
|
+
- jerome.dalbert@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".irbrc"
|
35
|
+
- ".rspec"
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- ".ruby-version"
|
38
|
+
- ".streerc"
|
39
|
+
- CHANGELOG.md
|
40
|
+
- CODE_OF_CONDUCT.md
|
41
|
+
- LICENSE
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- lib/objectize.rb
|
45
|
+
- lib/objectize/version.rb
|
46
|
+
homepage: https://github.com/jeromedalbert/objectize
|
47
|
+
licenses: []
|
48
|
+
metadata:
|
49
|
+
homepage_uri: https://github.com/jeromedalbert/objectize
|
50
|
+
source_code_uri: https://github.com/jeromedalbert/objectize
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 3.0.0
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubygems_version: 3.5.15
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: Transforms hashes into objects.
|
70
|
+
test_files: []
|