object_path 1.0.2 → 1.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 +4 -4
- data/.rspec +1 -0
- data/.rubocop.yml +31 -0
- data/CHANGELOG.md +15 -0
- data/README.md +35 -0
- data/Rakefile +6 -6
- data/lib/object_paths/model_support.rb +40 -0
- data/lib/object_paths/version.rb +1 -1
- metadata +15 -23
- data/Gemfile +0 -5
- /data/{object_path.gemspec → object_path.gemspec_old} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73b11a2ea0353715c8934f80433bc5b5175d3f88781be4fbc2d3ce39a3ef8b56
|
4
|
+
data.tar.gz: f8fd262ce4e472dd1156afd5c579aa78c979d4dca5f4de4114699b261deae1fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f7346b4b1252e7c9a8f79362dec99f4d83f00509b8b338106fb15a5fbec97d4c815105d913f237e1dd5014e36a5e8756963b1b357228913fe4940cc451a58c6
|
7
|
+
data.tar.gz: 0a25bf7d3d9d6e25730f134667d8d02ae282b055e2e07e4d66cca893ba1d0bd3ab1b330323b26494bcf2fc0daa1f6550bb111ee406e9ae86b45deb3cf7c394b3
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 3.0
|
7
|
+
SuggestExtensions: false
|
8
|
+
NewCops: enable
|
9
|
+
Exclude:
|
10
|
+
- "bin/**/*"
|
11
|
+
|
12
|
+
Style/StringLiteralsInInterpolation:
|
13
|
+
EnforcedStyle: double_quotes
|
14
|
+
|
15
|
+
Metrics/BlockLength:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/AbcSize:
|
19
|
+
Exclude:
|
20
|
+
- "spec/**/*"
|
21
|
+
|
22
|
+
Metrics/CyclomaticComplexity:
|
23
|
+
Exclude:
|
24
|
+
- "spec/**/*"
|
25
|
+
|
26
|
+
Metrics/MethodLength:
|
27
|
+
Exclude:
|
28
|
+
- "spec/**/*"
|
29
|
+
|
30
|
+
RSpec/MultipleExpectations:
|
31
|
+
Max: 2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
# Unreleased
|
2
|
+
- No changes yet
|
3
|
+
|
4
|
+
# 1.1.0 / 2025-06-08
|
5
|
+
|
6
|
+
## Development
|
7
|
+
|
8
|
+
- Converted testing to RSpec
|
9
|
+
- Added RuboCop to the default rake task
|
10
|
+
- Added RuboCop for rake
|
11
|
+
- Added RuboCop for RSpec
|
12
|
+
- Added module to provide helper methods for working with Object Paths
|
13
|
+
- Added class & instance methods for creating Object Paths
|
14
|
+
- Added method to directly resolve Object Paths against the current instance
|
15
|
+
|
1
16
|
# 1.0.2 / 2024-09-18
|
2
17
|
|
3
18
|
## Documentation
|
data/README.md
CHANGED
@@ -103,3 +103,38 @@ require 'object_paths/object_path'
|
|
103
103
|
['address', 'street'].to_object_path
|
104
104
|
%i[address street].to_object_path
|
105
105
|
```
|
106
|
+
|
107
|
+
### Class/Module Support
|
108
|
+
|
109
|
+
The +ObjectPaths::ModelSupport+ module can be included in a class or module to provide additional methods for working with Object Paths. This includes the +object_path+ class & instance methods which can be used to define a path witch a cleaner syntax than `ObjectPaths::ObjectPath.new`.
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
require 'object_paths/model_support'
|
113
|
+
class Address
|
114
|
+
include ObjectPaths::ModelSupport
|
115
|
+
end
|
116
|
+
|
117
|
+
Address.object_path('street') # => ObjectPaths::ObjectPath
|
118
|
+
Address.new.object_path('street') # => ObjectPaths::ObjectPath
|
119
|
+
```
|
120
|
+
|
121
|
+
The resulting path object is not in anyway directly tied to the enclosing class. The methods are just syntactic sugar for creating a new Object Path.
|
122
|
+
|
123
|
+
The +object_path!+ method can be used to directly resolve the path against the current instance of the class or module. This is useful for quickly resolving a path without having to create a new Object Path instance.
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
require 'object_paths/model_support'
|
127
|
+
|
128
|
+
class Address
|
129
|
+
include ObjectPaths::ModelSupport
|
130
|
+
|
131
|
+
attr_accessor :street
|
132
|
+
|
133
|
+
def initialize(street)
|
134
|
+
@street = street
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
address = Address.new('123 Main Street')
|
139
|
+
address.object_path!('street') # => '123 Main Street'
|
140
|
+
```
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
end
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
RuboCop::RakeTask.new
|
8
9
|
|
9
|
-
|
10
|
-
task default: :test
|
10
|
+
task default: %i[spec rubocop]
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'object_paths/object_path'
|
4
|
+
|
5
|
+
module ObjectPaths
|
6
|
+
# Adds convenience & helper methods to to models, classes and modules to ease the creation, use
|
7
|
+
# and resolution of ObjectPaths.
|
8
|
+
module ModelSupport
|
9
|
+
def self.included(base)
|
10
|
+
base.extend(ClassMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Adds a convenience method to the object level for creating ObjectPaths.
|
14
|
+
#
|
15
|
+
# @param path_definition [String, Array] The path definition to convert into an ObjectPath.
|
16
|
+
# @return [ObjectPaths::ObjectPath] The created ObjectPath.
|
17
|
+
def object_path(path_definition)
|
18
|
+
ObjectPaths::ObjectPath.new(path_definition)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Resolves the ObjectPath against the current object.
|
22
|
+
#
|
23
|
+
# @param path_definition [String, Array] The path definition to resolve.
|
24
|
+
# @return [Object, nil] The resolved object or nil if the path cannot be resolved.
|
25
|
+
def object_path!(path_definition)
|
26
|
+
object_path(path_definition)&.resolve(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
# ClassMethods module provides class-level methods for ObjectPaths.
|
30
|
+
module ClassMethods
|
31
|
+
# Adds a convenience method to the class level for creating ObjectPaths.
|
32
|
+
#
|
33
|
+
# @param path_definition [String, Array] The path definition to convert into an ObjectPath.
|
34
|
+
# @return [ObjectPaths::ObjectPath] The created ObjectPath.
|
35
|
+
def object_path(path_definition)
|
36
|
+
ObjectPaths::ObjectPath.new(path_definition)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/object_paths/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: object_path
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- drewthorp
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rubocop
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.6'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.6'
|
11
|
+
date: 2025-06-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: Allow the creation of an object that holds the steps through an object
|
28
14
|
graph to retrieve a value(s).
|
29
15
|
email:
|
@@ -33,21 +19,27 @@ extensions: []
|
|
33
19
|
extra_rdoc_files:
|
34
20
|
- README.md
|
35
21
|
files:
|
22
|
+
- ".rspec"
|
23
|
+
- ".rubocop.yml"
|
36
24
|
- CHANGELOG.md
|
37
|
-
- Gemfile
|
38
25
|
- LICENSE
|
39
26
|
- README.md
|
40
27
|
- Rakefile
|
41
28
|
- lib/array_object_path.rb
|
42
29
|
- lib/object_paths/errors.rb
|
30
|
+
- lib/object_paths/model_support.rb
|
43
31
|
- lib/object_paths/object_path.rb
|
44
32
|
- lib/object_paths/version.rb
|
45
33
|
- lib/string_object_path.rb
|
46
|
-
- object_path.
|
34
|
+
- object_path.gemspec_old
|
47
35
|
homepage: https://github.com/Fish-Fur/object_path
|
48
36
|
licenses:
|
49
37
|
- Apache-2.0
|
50
|
-
metadata:
|
38
|
+
metadata:
|
39
|
+
homepage_uri: https://github.com/Fish-Fur/object_path
|
40
|
+
source_code_uri: https://github.com/Fish-Fur/object_path
|
41
|
+
changelog_uri: https://github.com/Fish-Fur/object_path
|
42
|
+
rubygems_mfa_required: 'true'
|
51
43
|
post_install_message:
|
52
44
|
rdoc_options: []
|
53
45
|
require_paths:
|
@@ -56,7 +48,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
48
|
requirements:
|
57
49
|
- - ">="
|
58
50
|
- !ruby/object:Gem::Version
|
59
|
-
version: 3.
|
51
|
+
version: 3.0.0
|
60
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
53
|
requirements:
|
62
54
|
- - ">="
|
data/Gemfile
DELETED
File without changes
|