array_attribute_handler 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/CHANGELOG.md +11 -0
- data/Gemfile.lock +5 -3
- data/lib/array_attribute_handler/version.rb +1 -1
- data/lib/array_attribute_handler.rb +17 -4
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35b1114a4a1f986c605368a48d4f89bfb5f62ef310f3883c2cf6ad805ab2bf4b
|
4
|
+
data.tar.gz: 20e44e3bcdbb4f7211f9969b4bc483400cda76a30c42aeabff7c49703acd175e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3a0753f13ec236711570e977ad338d56d3e1352abefd4b2e8de2be0ee3d85e4ce42d7d8ab090c18eb1b85005c4f317f162189f3e705a9f9c0b73c59acf42b82
|
7
|
+
data.tar.gz: 6857b4f5c9e9bb51dc218647859303fae305389031780cf84c4c8226581462511ddf9a6a04fdf531ddfde1291b9934bfff3792df28a375568438cf47e1368a59
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [1.1.0] - 2023-08-14
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- Byebug for development.
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
|
18
|
+
- Allow gem to be installed in Rails 7 apps.
|
19
|
+
- Handle various platform newlines by default e.g. `\r`, `\r\n` as well as `\n`.
|
20
|
+
|
10
21
|
## [1.0.2] - 2023-08-13
|
11
22
|
|
12
23
|
### Fixed
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
array_attribute_handler (1.0
|
5
|
-
activerecord (>= 6.0, <
|
6
|
-
activesupport (>= 6.0, <
|
4
|
+
array_attribute_handler (1.1.0)
|
5
|
+
activerecord (>= 6.0, < 8)
|
6
|
+
activesupport (>= 6.0, < 8)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
@@ -21,6 +21,7 @@ GEM
|
|
21
21
|
zeitwerk (~> 2.3)
|
22
22
|
ast (2.4.2)
|
23
23
|
base64 (0.1.1)
|
24
|
+
byebug (11.1.3)
|
24
25
|
concurrent-ruby (1.2.2)
|
25
26
|
diff-lcs (1.5.0)
|
26
27
|
i18n (1.14.1)
|
@@ -78,6 +79,7 @@ PLATFORMS
|
|
78
79
|
|
79
80
|
DEPENDENCIES
|
80
81
|
array_attribute_handler!
|
82
|
+
byebug
|
81
83
|
rake (~> 13.0)
|
82
84
|
rspec (~> 3.0)
|
83
85
|
rubocop (~> 1.21)
|
@@ -13,20 +13,19 @@ module ArrayAttributeHandler
|
|
13
13
|
# attribute_name - The name of the attribute to handle.
|
14
14
|
# options - The options hash.
|
15
15
|
# :separator - The separator to use when parsing the attribute.
|
16
|
-
# Defaults to
|
16
|
+
# Defaults to newline characters.
|
17
17
|
# :spaced_join - Whether to join the parsed values with a space.
|
18
18
|
# Defaults to false.
|
19
19
|
def handle_array_attribute(attribute_name, options = {})
|
20
|
-
separator = options.fetch(:separator,
|
20
|
+
separator = options.fetch(:separator, /\r\n?|\n/)
|
21
21
|
|
22
|
-
# Public: Setter for the attribute.
|
23
22
|
define_method("#{attribute_name}=") do |value|
|
24
23
|
super(parse_values(value, separator))
|
25
24
|
end
|
26
25
|
|
27
26
|
# Public: Getter for the text representation of the attribute.
|
28
27
|
define_method("#{attribute_name}_text") do
|
29
|
-
send(attribute_name).join(separator + (options.fetch(:spaced_join, false) ? " " : ""))
|
28
|
+
send(attribute_name).join(determine_delimiter(separator) + (options.fetch(:spaced_join, false) ? " " : ""))
|
30
29
|
end
|
31
30
|
|
32
31
|
# Public: Setter for the text representation of the attribute.
|
@@ -49,4 +48,18 @@ module ArrayAttributeHandler
|
|
49
48
|
# Remove any empty strings from the array.
|
50
49
|
array.map { |v| v.strip.presence }.compact
|
51
50
|
end
|
51
|
+
|
52
|
+
# Internal: Determine the delimiter to use when parsing the attribute.
|
53
|
+
#
|
54
|
+
# separator - The separator to use when parsing the attribute.
|
55
|
+
#
|
56
|
+
# Returns the delimiter to use when parsing the attribute.
|
57
|
+
def determine_delimiter(separator)
|
58
|
+
if separator.is_a?(Regexp) && separator.match?("\r\n|\r|\n")
|
59
|
+
# Check for a specific condition you want to match, e.g., a regex that matches both \r and \n
|
60
|
+
return "\n"
|
61
|
+
end
|
62
|
+
|
63
|
+
separator # Return the separator as-is if it's not a regex or doesn't match the condition
|
64
|
+
end
|
52
65
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: array_attribute_handler
|
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
|
- Jono Feist
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: byebug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: sqlite3
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -33,7 +47,7 @@ dependencies:
|
|
33
47
|
version: '6.0'
|
34
48
|
- - "<"
|
35
49
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
50
|
+
version: '8'
|
37
51
|
type: :runtime
|
38
52
|
prerelease: false
|
39
53
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -43,7 +57,7 @@ dependencies:
|
|
43
57
|
version: '6.0'
|
44
58
|
- - "<"
|
45
59
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
60
|
+
version: '8'
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
62
|
name: activesupport
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +67,7 @@ dependencies:
|
|
53
67
|
version: '6.0'
|
54
68
|
- - "<"
|
55
69
|
- !ruby/object:Gem::Version
|
56
|
-
version: '
|
70
|
+
version: '8'
|
57
71
|
type: :runtime
|
58
72
|
prerelease: false
|
59
73
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -63,7 +77,7 @@ dependencies:
|
|
63
77
|
version: '6.0'
|
64
78
|
- - "<"
|
65
79
|
- !ruby/object:Gem::Version
|
66
|
-
version: '
|
80
|
+
version: '8'
|
67
81
|
description: The `handle_array_attribute` concern provides a flexible way to treat
|
68
82
|
string attributes in a Rails model as arrays. This includes parsing strings based
|
69
83
|
on configurable separators, optional spaces between elements, and optional maximum
|