clamped 0.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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +61 -0
- data/README.md +102 -0
- data/Rakefile +10 -0
- data/clamped.gemspec +33 -0
- data/lib/clamped/array.rb +9 -0
- data/lib/clamped/hash.rb +7 -0
- data/lib/clamped/string.rb +15 -0
- data/lib/clamped/symbol.rb +15 -0
- data/lib/clamped/version.rb +5 -0
- data/lib/clamped.rb +8 -0
- data/sig/clamped.rbs +4 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fcc2cf8878aed212d39404deb09a9a7aecd400b7aaac9d4ace956f7d077157e6
|
4
|
+
data.tar.gz: 15c1643fafce3c7f4f6dd4c449a9002282d60efe103e6209482f5e8f430a25b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0a018d8e1a8801fa482a7cb96e0ecdb8bc2a3c1ab28818e5e20baa0bccae9b1a6623763cabadfa034c2abd06d902f9084a15c38c7041fc8b5ad642a1f1fd3270
|
7
|
+
data.tar.gz: 50965da9de6680e9198e02b2e66ca971739382eab334f67406b68648069e40454ba2fc04bf510623ff88bc24431e032009c4310063aed573cd3c3639f6a03d30
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.2
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
clamped (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
diff-lcs (1.5.0)
|
11
|
+
parallel (1.22.1)
|
12
|
+
parser (3.1.2.0)
|
13
|
+
ast (~> 2.4.1)
|
14
|
+
rainbow (3.1.1)
|
15
|
+
rake (13.0.6)
|
16
|
+
regexp_parser (2.5.0)
|
17
|
+
rexml (3.2.5)
|
18
|
+
rspec (3.11.0)
|
19
|
+
rspec-core (~> 3.11.0)
|
20
|
+
rspec-expectations (~> 3.11.0)
|
21
|
+
rspec-mocks (~> 3.11.0)
|
22
|
+
rspec-core (3.11.0)
|
23
|
+
rspec-support (~> 3.11.0)
|
24
|
+
rspec-expectations (3.11.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.11.0)
|
27
|
+
rspec-mocks (3.11.1)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.11.0)
|
30
|
+
rspec-support (3.11.0)
|
31
|
+
rubocop (1.29.1)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 3.1.0.0)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
regexp_parser (>= 1.8, < 3.0)
|
36
|
+
rexml (>= 3.2.5, < 4.0)
|
37
|
+
rubocop-ast (>= 1.17.0, < 2.0)
|
38
|
+
ruby-progressbar (~> 1.7)
|
39
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
40
|
+
rubocop-ast (1.19.1)
|
41
|
+
parser (>= 3.1.1.0)
|
42
|
+
rubocop-performance (1.13.3)
|
43
|
+
rubocop (>= 1.7.0, < 2.0)
|
44
|
+
rubocop-ast (>= 0.4.0)
|
45
|
+
ruby-progressbar (1.11.0)
|
46
|
+
standard (1.12.1)
|
47
|
+
rubocop (= 1.29.1)
|
48
|
+
rubocop-performance (= 1.13.3)
|
49
|
+
unicode-display_width (2.2.0)
|
50
|
+
|
51
|
+
PLATFORMS
|
52
|
+
x86_64-linux
|
53
|
+
|
54
|
+
DEPENDENCIES
|
55
|
+
clamped!
|
56
|
+
rake (~> 13.0)
|
57
|
+
rspec (~> 3.0)
|
58
|
+
standard
|
59
|
+
|
60
|
+
BUNDLED WITH
|
61
|
+
2.3.16
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# Clamped
|
2
|
+
|
3
|
+
`Clamped` monkey patches a couple of Ruby classes to clamp values to a whitelist.
|
4
|
+
|
5
|
+
For example:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
"apple".clamped(%w[banana orange])
|
9
|
+
# nil
|
10
|
+
|
11
|
+
|
12
|
+
"apple".clamped(%w[apple banana])
|
13
|
+
# "apple"
|
14
|
+
```
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Install the gem and add to the application's Gemfile by executing:
|
19
|
+
|
20
|
+
$ bundle add clamped
|
21
|
+
|
22
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
23
|
+
|
24
|
+
$ gem install clamped
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Supported classes:
|
29
|
+
|
30
|
+
- [`String`](#string)
|
31
|
+
- [`Symbol`](#symbol)
|
32
|
+
- [`Array`](#array)
|
33
|
+
- [`Hash`](#hash)
|
34
|
+
|
35
|
+
### String
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
"apple".clamped(%w[banana orange])
|
39
|
+
# nil
|
40
|
+
|
41
|
+
|
42
|
+
"apple".clamped(%w[apple banana])
|
43
|
+
# "apple"
|
44
|
+
```
|
45
|
+
|
46
|
+
`strict: false` calls `to_s` on the passed array:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
"apple".clamped(%i[apple banana], strict: false)
|
50
|
+
# "apple"
|
51
|
+
```
|
52
|
+
|
53
|
+
### Symbol
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
:apple.clamped(%i[banana orange])
|
57
|
+
# nil
|
58
|
+
|
59
|
+
|
60
|
+
:apple.clamped(%i[apple banana])
|
61
|
+
# :apple
|
62
|
+
```
|
63
|
+
|
64
|
+
`strict: false` calls `to_sym` on the passed array:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
:apple.clamped(%w[apple banana], strict: false)
|
68
|
+
# :apple
|
69
|
+
```
|
70
|
+
|
71
|
+
### Array
|
72
|
+
|
73
|
+
Clamp an array with another array:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
%i[apple banana orange].clamped %i[apple banana]
|
77
|
+
# %i[apple banana]
|
78
|
+
```
|
79
|
+
|
80
|
+
### Hash
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
{
|
84
|
+
apple: 'golden',
|
85
|
+
banana: 'cavendish',
|
86
|
+
orange: 'sinensis'
|
87
|
+
}.clamped %i[apple banana]
|
88
|
+
# {
|
89
|
+
# apple: 'golden',
|
90
|
+
# banana: 'cavendish'
|
91
|
+
# }
|
92
|
+
```
|
93
|
+
|
94
|
+
## Development
|
95
|
+
|
96
|
+
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.
|
97
|
+
|
98
|
+
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).
|
99
|
+
|
100
|
+
## Contributing
|
101
|
+
|
102
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/metikular/clamped.
|
data/Rakefile
ADDED
data/clamped.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/clamped/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "clamped"
|
7
|
+
spec.version = Clamped::VERSION
|
8
|
+
spec.authors = ["Serge Hänni"]
|
9
|
+
spec.email = ["serge@metikular.ch"]
|
10
|
+
|
11
|
+
spec.summary = "Adds convenience methods to clamp values to a whitelist."
|
12
|
+
spec.homepage = "https://github.com/metikular/clamped"
|
13
|
+
spec.required_ruby_version = ">= 2.6.0"
|
14
|
+
|
15
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/metikular/clamped"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/metikular/raw/main/clamped"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(__dir__) do
|
24
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
33
|
+
end
|
data/lib/clamped/hash.rb
ADDED
data/lib/clamped.rb
ADDED
data/sig/clamped.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clamped
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Serge Hänni
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-07-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- serge@metikular.ch
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".rspec"
|
35
|
+
- ".rubocop.yml"
|
36
|
+
- ".ruby-version"
|
37
|
+
- CHANGELOG.md
|
38
|
+
- Gemfile
|
39
|
+
- Gemfile.lock
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- clamped.gemspec
|
43
|
+
- lib/clamped.rb
|
44
|
+
- lib/clamped/array.rb
|
45
|
+
- lib/clamped/hash.rb
|
46
|
+
- lib/clamped/string.rb
|
47
|
+
- lib/clamped/symbol.rb
|
48
|
+
- lib/clamped/version.rb
|
49
|
+
- sig/clamped.rbs
|
50
|
+
homepage: https://github.com/metikular/clamped
|
51
|
+
licenses: []
|
52
|
+
metadata:
|
53
|
+
allowed_push_host: https://rubygems.org
|
54
|
+
homepage_uri: https://github.com/metikular/clamped
|
55
|
+
source_code_uri: https://github.com/metikular/clamped
|
56
|
+
changelog_uri: https://github.com/metikular/raw/main/clamped
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 2.6.0
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubygems_version: 3.3.7
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Adds convenience methods to clamp values to a whitelist.
|
76
|
+
test_files: []
|