array_attribute_handler 1.0.0 → 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/.rubocop.yml +8 -0
- data/CHANGELOG.md +40 -1
- data/Gemfile.lock +7 -3
- data/lib/array_attribute_handler/version.rb +1 -1
- data/lib/array_attribute_handler.rb +18 -5
- 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/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,44 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
1
8
|
## [Unreleased]
|
2
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
|
+
|
21
|
+
## [1.0.2] - 2023-08-13
|
22
|
+
|
23
|
+
### Fixed
|
24
|
+
|
25
|
+
- Resolve Rubocop offences preventing Github CI from processing.
|
26
|
+
|
27
|
+
## [1.0.1] - 2023-08-13
|
28
|
+
|
29
|
+
### Fixed
|
30
|
+
|
31
|
+
- Added support for x86_64-linux.
|
32
|
+
|
33
|
+
## [1.0.0] - 2023-08-13
|
34
|
+
|
35
|
+
### Added
|
36
|
+
|
37
|
+
- First release pushed to RubyGems.
|
38
|
+
- General functionality included.
|
39
|
+
|
3
40
|
## [0.1.0] - 2023-08-13
|
4
41
|
|
5
|
-
|
42
|
+
### Added
|
43
|
+
|
44
|
+
- Initial release.
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
array_attribute_handler (1.
|
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)
|
@@ -66,6 +67,7 @@ GEM
|
|
66
67
|
parser (>= 3.2.1.0)
|
67
68
|
ruby-progressbar (1.13.0)
|
68
69
|
sqlite3 (1.6.3-arm64-darwin)
|
70
|
+
sqlite3 (1.6.3-x86_64-linux)
|
69
71
|
tzinfo (2.0.6)
|
70
72
|
concurrent-ruby (~> 1.0)
|
71
73
|
unicode-display_width (2.4.2)
|
@@ -73,9 +75,11 @@ GEM
|
|
73
75
|
|
74
76
|
PLATFORMS
|
75
77
|
arm64-darwin-22
|
78
|
+
x86_64-linux
|
76
79
|
|
77
80
|
DEPENDENCIES
|
78
81
|
array_attribute_handler!
|
82
|
+
byebug
|
79
83
|
rake (~> 13.0)
|
80
84
|
rspec (~> 3.0)
|
81
85
|
rubocop (~> 1.21)
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative "array_attribute_handler/version"
|
4
4
|
require "active_support/concern"
|
5
5
|
|
6
|
+
# Public: ArrayAttributeHandler is a module for handling array attributes.
|
6
7
|
module ArrayAttributeHandler
|
7
8
|
extend ActiveSupport::Concern
|
8
9
|
|
@@ -12,21 +13,19 @@ module ArrayAttributeHandler
|
|
12
13
|
# attribute_name - The name of the attribute to handle.
|
13
14
|
# options - The options hash.
|
14
15
|
# :separator - The separator to use when parsing the attribute.
|
15
|
-
# Defaults to
|
16
|
+
# Defaults to newline characters.
|
16
17
|
# :spaced_join - Whether to join the parsed values with a space.
|
17
18
|
# Defaults to false.
|
18
19
|
def handle_array_attribute(attribute_name, options = {})
|
19
|
-
separator = options.fetch(:separator,
|
20
|
-
combinator = separator + (options.fetch(:spaced_join, false) ? " " : "")
|
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(
|
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.
|
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
|