array_attribute_handler 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4732afc1a3741de5ad8e4e286e74e835494f94603e2f6f229b9c53aa478f19ad
4
+ data.tar.gz: 5f40aae3a4a68044eeea99282de2daf3666876e45f6bf15c00da02958c6a2e8d
5
+ SHA512:
6
+ metadata.gz: 220955b2f49d88ce5e518fcb52465ed883f826eacc4543dd3c65685c2112a627485aa53ed178eb4ba12e07136e8bfdd690d702512b67391705f01121dd30308a
7
+ data.tar.gz: 2d1abe5e5b6e1af3275e0e7bb206503532b89f2ca6dfbfb240c5b33a20ed0c4ff6555c0ac91df473a9ce8b988186a3841d3eec9b067612373938ef55a6e0f876
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-08-13
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in array_attribute_handler.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,85 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ array_attribute_handler (1.0.0)
5
+ activerecord (>= 6.0, < 7)
6
+ activesupport (>= 6.0, < 7)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (6.1.7.4)
12
+ activesupport (= 6.1.7.4)
13
+ activerecord (6.1.7.4)
14
+ activemodel (= 6.1.7.4)
15
+ activesupport (= 6.1.7.4)
16
+ activesupport (6.1.7.4)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ tzinfo (~> 2.0)
21
+ zeitwerk (~> 2.3)
22
+ ast (2.4.2)
23
+ base64 (0.1.1)
24
+ concurrent-ruby (1.2.2)
25
+ diff-lcs (1.5.0)
26
+ i18n (1.14.1)
27
+ concurrent-ruby (~> 1.0)
28
+ json (2.6.3)
29
+ language_server-protocol (3.17.0.3)
30
+ minitest (5.19.0)
31
+ parallel (1.23.0)
32
+ parser (3.2.2.3)
33
+ ast (~> 2.4.1)
34
+ racc
35
+ racc (1.7.1)
36
+ rainbow (3.1.1)
37
+ rake (13.0.6)
38
+ regexp_parser (2.8.1)
39
+ rexml (3.2.6)
40
+ rspec (3.12.0)
41
+ rspec-core (~> 3.12.0)
42
+ rspec-expectations (~> 3.12.0)
43
+ rspec-mocks (~> 3.12.0)
44
+ rspec-core (3.12.2)
45
+ rspec-support (~> 3.12.0)
46
+ rspec-expectations (3.12.3)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.12.0)
49
+ rspec-mocks (3.12.6)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.12.0)
52
+ rspec-support (3.12.1)
53
+ rubocop (1.56.0)
54
+ base64 (~> 0.1.1)
55
+ json (~> 2.3)
56
+ language_server-protocol (>= 3.17.0)
57
+ parallel (~> 1.10)
58
+ parser (>= 3.2.2.3)
59
+ rainbow (>= 2.2.2, < 4.0)
60
+ regexp_parser (>= 1.8, < 3.0)
61
+ rexml (>= 3.2.5, < 4.0)
62
+ rubocop-ast (>= 1.28.1, < 2.0)
63
+ ruby-progressbar (~> 1.7)
64
+ unicode-display_width (>= 2.4.0, < 3.0)
65
+ rubocop-ast (1.29.0)
66
+ parser (>= 3.2.1.0)
67
+ ruby-progressbar (1.13.0)
68
+ sqlite3 (1.6.3-arm64-darwin)
69
+ tzinfo (2.0.6)
70
+ concurrent-ruby (~> 1.0)
71
+ unicode-display_width (2.4.2)
72
+ zeitwerk (2.6.11)
73
+
74
+ PLATFORMS
75
+ arm64-darwin-22
76
+
77
+ DEPENDENCIES
78
+ array_attribute_handler!
79
+ rake (~> 13.0)
80
+ rspec (~> 3.0)
81
+ rubocop (~> 1.21)
82
+ sqlite3
83
+
84
+ BUNDLED WITH
85
+ 2.4.10
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Jono Feist
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,59 @@
1
+ # ArrayAttributeHandler
2
+
3
+ ArrayAttributeHandler is a simple Ruby gem designed to facilitate the management of array attributes in Rails-based applications.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ ```bash
10
+ bundle add array_attribute_handler
11
+ ```
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ ```bash
16
+ gem install array_attribute_handler
17
+ ```
18
+
19
+ For those wanting the cutting-edge version or for specific branches, you can specify the GitHub repo in your Gemfile:
20
+
21
+ ```bash
22
+ gem 'array_attribute_handler', git: 'https://github.com/defaye/array_attribute_handler_gem.git'
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ Detailed instructions on how to use the gem will be provided soon. For now, refer to the documentation and examples within the code.
28
+
29
+ ## Development
30
+
31
+ Interested in contributing or diving deep into the code? Here's how you can get started:
32
+
33
+ 1. Clone the repository.
34
+ 1. Execute `bin/setup` to set up the development environment.
35
+ 1. Use `rake spec` to run the test suite and ensure everything works as expected.
36
+ 1. `bin/console` provides an interactive console for experimentation.
37
+
38
+ To install the development version of the gem on your local machine:
39
+
40
+ ```bash
41
+ bundle exec rake install
42
+ ```
43
+
44
+ When it's time to cut a new release:
45
+
46
+ 1. Update the version number in version.rb.
47
+ 1. Use bundle exec rake release to handle the rest. This will tag the version, push changes and tags to the repository, and release the gem version on RubyGems.org.
48
+
49
+ 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.
50
+
51
+ 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).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/defaye/array_attribute_handler_gem.
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ArrayAttributeHandler
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "array_attribute_handler/version"
4
+ require "active_support/concern"
5
+
6
+ module ArrayAttributeHandler
7
+ extend ActiveSupport::Concern
8
+
9
+ class_methods do
10
+ # Public: Handle array attributes.
11
+ #
12
+ # attribute_name - The name of the attribute to handle.
13
+ # options - The options hash.
14
+ # :separator - The separator to use when parsing the attribute.
15
+ # Defaults to "\n".
16
+ # :spaced_join - Whether to join the parsed values with a space.
17
+ # Defaults to false.
18
+ def handle_array_attribute(attribute_name, options = {})
19
+ separator = options.fetch(:separator, "\n")
20
+ combinator = separator + (options.fetch(:spaced_join, false) ? " " : "")
21
+
22
+ # Public: Setter for the attribute.
23
+ define_method("#{attribute_name}=") do |value|
24
+ super(parse_values(value, separator))
25
+ end
26
+
27
+ # Public: Getter for the text representation of the attribute.
28
+ define_method("#{attribute_name}_text") do
29
+ send(attribute_name).join(combinator)
30
+ end
31
+
32
+ # Public: Setter for the text representation of the attribute.
33
+ define_method("#{attribute_name}_text=") do |value|
34
+ send("#{attribute_name}=", parse_values(value, separator))
35
+ end
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ # Internal: Parse the given value into an array of strings.
42
+ #
43
+ # value - The value to parse.
44
+ # separator - The separator to use when parsing the value.
45
+ #
46
+ # Returns an array of strings.
47
+ def parse_values(value, separator)
48
+ array = value.is_a?(String) ? value.split(separator) : value.to_a
49
+ # Remove any empty strings from the array.
50
+ array.map { |v| v.strip.presence }.compact
51
+ end
52
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ # Is only used for testing purposes
6
+ class JsonArraySerializer
7
+ def self.dump(array)
8
+ array.to_json
9
+ end
10
+
11
+ def self.load(json_string)
12
+ json_string ? JSON.parse(json_string) : []
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ module ArrayAttributeHandler
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: array_attribute_handler
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jono Feist
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-08-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sqlite3
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '6.0'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '7'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '6.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '7'
47
+ - !ruby/object:Gem::Dependency
48
+ name: activesupport
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '6.0'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '7'
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '6.0'
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '7'
67
+ description: The `handle_array_attribute` concern provides a flexible way to treat
68
+ string attributes in a Rails model as arrays. This includes parsing strings based
69
+ on configurable separators, optional spaces between elements, and optional maximum
70
+ length validation for each element.
71
+ email:
72
+ - j78258334@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - CHANGELOG.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - lib/array_attribute_handler.rb
86
+ - lib/array_attribute_handler/version.rb
87
+ - serializers/json_array_serializer.rb
88
+ - sig/array_attribute_handler.rbs
89
+ homepage: https://github.com/defaye/array_attribute_handler_gem
90
+ licenses:
91
+ - MIT
92
+ metadata:
93
+ allowed_push_host: https://rubygems.org
94
+ homepage_uri: https://github.com/defaye/array_attribute_handler_gem
95
+ source_code_uri: https://github.com/defaye/array_attribute_handler_gem
96
+ changelog_uri: https://github.com/defaye/array_attribute_handler_gem/blob/main/CHANGELOG.md
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: 2.6.0
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubygems_version: 3.4.10
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: A Ruby on Rails concern to handle string attributes as arrays with various
116
+ options.
117
+ test_files: []