casual_support 4.0.0 → 5.0.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 +21 -0
- data/Gemfile +2 -3
- data/README.md +12 -36
- data/casual_support.gemspec +2 -3
- data/lib/casual_support/enumerable.rb +0 -1
- data/lib/casual_support/version.rb +1 -1
- data/lib/casual_support.rb +0 -4
- metadata +4 -24
- data/.gitignore +0 -10
- data/.travis.yml +0 -5
- data/lib/casual_support/date/to_hms.rb +0 -15
- data/lib/casual_support/date/to_ymd.rb +0 -13
- data/lib/casual_support/date.rb +0 -2
- data/lib/casual_support/enumerable/index_to.rb +0 -19
- data/lib/casual_support/hash/displace.rb +0 -26
- data/lib/casual_support/hash/putbang.rb +0 -20
- data/lib/casual_support/hash.rb +0 -2
- data/lib/casual_support/struct/assign_attributes.rb +0 -25
- data/lib/casual_support/struct/from_h.rb +0 -27
- data/lib/casual_support/struct.rb +0 -2
- data/lib/casual_support/time/to_hms.rb +0 -19
- data/lib/casual_support/time/to_ymd.rb +0 -19
- data/lib/casual_support/time.rb +0 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b1b6de67e75bbf7aa49d6b57e04fe896aee7514eda1a9a13c24849ccbf21efce
|
|
4
|
+
data.tar.gz: 9a4eb5b9a69f7935a2e3910b22caaf3cf75550c0cf092f86bfce72af29f10eff
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 93f4a01af09b19777acb8159c33f5baf8bcd1c50763b315725794579d465feb0291a9aae2df97e086b9a44b71003ef45f9149aa0980d72d1c6a7dd67eecdfa27
|
|
7
|
+
data.tar.gz: 5cefb130b0e143798a37ad642b06e23a96d74ed66a351d1fbee89b322338684ea0addce22b298721a70729100a13037e6c28f971d8389858831043040e48ac74
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## 5.0.0
|
|
2
|
+
|
|
3
|
+
* [BREAKING] Drop support for Ruby < 3.4
|
|
4
|
+
* [BREAKING] Remove `Hash#put!`
|
|
5
|
+
* Use `hash.merge!(key => value)` instead
|
|
6
|
+
* [BREAKING] Remove `Hash#displace`
|
|
7
|
+
* [BREAKING] Remove `Struct.from_h`
|
|
8
|
+
* In Ruby 3.2+, call the generated struct class's constructor with
|
|
9
|
+
keyword arguments instead: `Point.new(x: 1, y: 2, z: 3)`
|
|
10
|
+
* [BREAKING] Remove `Struct#assign_attributes`
|
|
11
|
+
* [BREAKING] Remove `Enumerable#index_to`
|
|
12
|
+
* Use Active Support's `Enumerable#index_with` instead
|
|
13
|
+
* [BREAKING] Remove `Date#to_hms`
|
|
14
|
+
* [BREAKING] Remove `Date#to_ymd`
|
|
15
|
+
* Use `date.to_s` instead
|
|
16
|
+
* [BREAKING] Remove `Time#to_hms`
|
|
17
|
+
* Use `time.strftime("%H:%M:%S")` instead
|
|
18
|
+
* [BREAKING] Remove `Time#to_ymd`
|
|
19
|
+
* Use `time.to_date.to_s` or `time.strftime("%Y-%m-%d")` instead
|
|
20
|
+
|
|
21
|
+
|
|
1
22
|
## 4.0.0
|
|
2
23
|
|
|
3
24
|
* [BREAKING] Drop support for Ruby < 2.6
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# casual_support
|
|
1
|
+
# casual_support
|
|
2
2
|
|
|
3
3
|
Utility methods as extensions to core Ruby objects, a la
|
|
4
4
|
[Active Support](https://guides.rubyonrails.org/active_support_core_extensions.html).
|
|
@@ -6,44 +6,20 @@ Utility methods as extensions to core Ruby objects, a la
|
|
|
6
6
|
|
|
7
7
|
## API
|
|
8
8
|
|
|
9
|
-
- [
|
|
10
|
-
- [
|
|
11
|
-
|
|
12
|
-
- [
|
|
13
|
-
- [
|
|
14
|
-
- [
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
19
|
-
- [#after](https://www.rubydoc.info/gems/casual_support/String:after)
|
|
20
|
-
- [#after_last](https://www.rubydoc.info/gems/casual_support/String:after_last)
|
|
21
|
-
- [#before](https://www.rubydoc.info/gems/casual_support/String:before)
|
|
22
|
-
- [#before_last](https://www.rubydoc.info/gems/casual_support/String:before_last)
|
|
23
|
-
- [#between](https://www.rubydoc.info/gems/casual_support/String:between)
|
|
24
|
-
- [#prefix](https://www.rubydoc.info/gems/casual_support/String:prefix)
|
|
25
|
-
- [#suffix](https://www.rubydoc.info/gems/casual_support/String:suffix)
|
|
26
|
-
- [Struct](https://www.rubydoc.info/gems/casual_support/Struct)
|
|
27
|
-
- [#assign_attributes](https://www.rubydoc.info/gems/casual_support/Struct:assign_attributes)
|
|
28
|
-
- [.from_h](https://www.rubydoc.info/gems/casual_support/Struct.from_h)
|
|
29
|
-
- [Time](https://www.rubydoc.info/gems/casual_support/Time)
|
|
30
|
-
- [#to_hms](https://www.rubydoc.info/gems/casual_support/Time:to_hms)
|
|
31
|
-
- [#to_ymd](https://www.rubydoc.info/gems/casual_support/Time:to_ymd)
|
|
32
|
-
|
|
9
|
+
- [`Enumerable`](https://www.rubydoc.info/gems/casual_support/Enumerable)
|
|
10
|
+
- [`#duplicates`](https://www.rubydoc.info/gems/casual_support/Enumerable:duplicates)
|
|
11
|
+
- [`String`](https://www.rubydoc.info/gems/casual_support/String)
|
|
12
|
+
- [`#after`](https://www.rubydoc.info/gems/casual_support/String:after)
|
|
13
|
+
- [`#after_last`](https://www.rubydoc.info/gems/casual_support/String:after_last)
|
|
14
|
+
- [`#before`](https://www.rubydoc.info/gems/casual_support/String:before)
|
|
15
|
+
- [`#before_last`](https://www.rubydoc.info/gems/casual_support/String:before_last)
|
|
16
|
+
- [`#between`](https://www.rubydoc.info/gems/casual_support/String:between)
|
|
17
|
+
- [`#prefix`](https://www.rubydoc.info/gems/casual_support/String:prefix)
|
|
18
|
+
- [`#suffix`](https://www.rubydoc.info/gems/casual_support/String:suffix)
|
|
33
19
|
|
|
34
20
|
## Installation
|
|
35
21
|
|
|
36
|
-
Install the [gem](https://rubygems.org/gems/casual_support)
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
$ gem install casual_support
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Then require in your Ruby code:
|
|
43
|
-
|
|
44
|
-
```ruby
|
|
45
|
-
require "casual_support"
|
|
46
|
-
```
|
|
22
|
+
Install the [`casual_support` gem](https://rubygems.org/gems/casual_support).
|
|
47
23
|
|
|
48
24
|
|
|
49
25
|
## Contributing
|
data/casual_support.gemspec
CHANGED
|
@@ -9,16 +9,15 @@ Gem::Specification.new do |spec|
|
|
|
9
9
|
spec.summary = %q{Utility extensions to core objects, a la Active Support}
|
|
10
10
|
spec.homepage = "https://github.com/jonathanhefner/casual_support"
|
|
11
11
|
spec.license = "MIT"
|
|
12
|
-
spec.required_ruby_version = ">=
|
|
12
|
+
spec.required_ruby_version = ">= 3.4"
|
|
13
13
|
|
|
14
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
|
15
14
|
spec.metadata["source_code_uri"] = spec.homepage
|
|
16
15
|
spec.metadata["changelog_uri"] = spec.metadata["source_code_uri"] + "/blob/master/CHANGELOG.md"
|
|
17
16
|
|
|
18
17
|
# Specify which files should be added to the gem when it is released.
|
|
19
18
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
20
19
|
spec.files = Dir.chdir(__dir__) do
|
|
21
|
-
`git ls-files -z`.split("\x0").reject { |f| f.
|
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.start_with?("test/", ".git") }
|
|
22
21
|
end
|
|
23
22
|
spec.bindir = "exe"
|
|
24
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
data/lib/casual_support.rb
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
require_relative "casual_support/version"
|
|
2
|
-
require_relative "casual_support/date"
|
|
3
2
|
require_relative "casual_support/enumerable"
|
|
4
|
-
require_relative "casual_support/hash"
|
|
5
3
|
require_relative "casual_support/string"
|
|
6
|
-
require_relative "casual_support/struct"
|
|
7
|
-
require_relative "casual_support/time"
|
metadata
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: casual_support
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 5.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jonathan Hefner
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
|
-
description:
|
|
14
12
|
email:
|
|
15
13
|
- jonathan@hefner.pro
|
|
16
14
|
executables: []
|
|
17
15
|
extensions: []
|
|
18
16
|
extra_rdoc_files: []
|
|
19
17
|
files:
|
|
20
|
-
- ".gitignore"
|
|
21
|
-
- ".travis.yml"
|
|
22
18
|
- CHANGELOG.md
|
|
23
19
|
- Gemfile
|
|
24
20
|
- LICENSE.txt
|
|
@@ -26,15 +22,8 @@ files:
|
|
|
26
22
|
- Rakefile
|
|
27
23
|
- casual_support.gemspec
|
|
28
24
|
- lib/casual_support.rb
|
|
29
|
-
- lib/casual_support/date.rb
|
|
30
|
-
- lib/casual_support/date/to_hms.rb
|
|
31
|
-
- lib/casual_support/date/to_ymd.rb
|
|
32
25
|
- lib/casual_support/enumerable.rb
|
|
33
26
|
- lib/casual_support/enumerable/duplicates.rb
|
|
34
|
-
- lib/casual_support/enumerable/index_to.rb
|
|
35
|
-
- lib/casual_support/hash.rb
|
|
36
|
-
- lib/casual_support/hash/displace.rb
|
|
37
|
-
- lib/casual_support/hash/putbang.rb
|
|
38
27
|
- lib/casual_support/string.rb
|
|
39
28
|
- lib/casual_support/string/after.rb
|
|
40
29
|
- lib/casual_support/string/after_last.rb
|
|
@@ -43,21 +32,13 @@ files:
|
|
|
43
32
|
- lib/casual_support/string/between.rb
|
|
44
33
|
- lib/casual_support/string/prefix.rb
|
|
45
34
|
- lib/casual_support/string/suffix.rb
|
|
46
|
-
- lib/casual_support/struct.rb
|
|
47
|
-
- lib/casual_support/struct/assign_attributes.rb
|
|
48
|
-
- lib/casual_support/struct/from_h.rb
|
|
49
|
-
- lib/casual_support/time.rb
|
|
50
|
-
- lib/casual_support/time/to_hms.rb
|
|
51
|
-
- lib/casual_support/time/to_ymd.rb
|
|
52
35
|
- lib/casual_support/version.rb
|
|
53
36
|
homepage: https://github.com/jonathanhefner/casual_support
|
|
54
37
|
licenses:
|
|
55
38
|
- MIT
|
|
56
39
|
metadata:
|
|
57
|
-
homepage_uri: https://github.com/jonathanhefner/casual_support
|
|
58
40
|
source_code_uri: https://github.com/jonathanhefner/casual_support
|
|
59
41
|
changelog_uri: https://github.com/jonathanhefner/casual_support/blob/master/CHANGELOG.md
|
|
60
|
-
post_install_message:
|
|
61
42
|
rdoc_options: []
|
|
62
43
|
require_paths:
|
|
63
44
|
- lib
|
|
@@ -65,15 +46,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
65
46
|
requirements:
|
|
66
47
|
- - ">="
|
|
67
48
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '
|
|
49
|
+
version: '3.4'
|
|
69
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
51
|
requirements:
|
|
71
52
|
- - ">="
|
|
72
53
|
- !ruby/object:Gem::Version
|
|
73
54
|
version: '0'
|
|
74
55
|
requirements: []
|
|
75
|
-
rubygems_version:
|
|
76
|
-
signing_key:
|
|
56
|
+
rubygems_version: 4.0.10
|
|
77
57
|
specification_version: 4
|
|
78
58
|
summary: Utility extensions to core objects, a la Active Support
|
|
79
59
|
test_files: []
|
data/.gitignore
DELETED
data/lib/casual_support/date.rb
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require_relative "../hash/putbang"
|
|
2
|
-
|
|
3
|
-
module Enumerable
|
|
4
|
-
|
|
5
|
-
# Creates a Hash using the Enumerable's elements as keys, and using
|
|
6
|
-
# the given block to compute an associated value for each key.
|
|
7
|
-
#
|
|
8
|
-
# @example
|
|
9
|
-
# cache = id_list.index_to{|id| find_by_id(id) }
|
|
10
|
-
#
|
|
11
|
-
# @yield [key]
|
|
12
|
-
# @yieldparam key [Object]
|
|
13
|
-
# @yieldreturn [Object] value
|
|
14
|
-
# @return [Hash{key => value}]
|
|
15
|
-
def index_to()
|
|
16
|
-
self.reduce({}){|h, k| h.put!(k, (yield k)) }
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
end
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
class Hash
|
|
2
|
-
|
|
3
|
-
# Associates +key+ with +value+, and returns +key+'s previously
|
|
4
|
-
# associated value. If +key+ had no previously associated value,
|
|
5
|
-
# returns +Hash#default+.
|
|
6
|
-
#
|
|
7
|
-
# @example
|
|
8
|
-
# visited = { "id1" => true, "id2" => false }
|
|
9
|
-
#
|
|
10
|
-
# visited.displace("id1", true) # == true
|
|
11
|
-
# visited # == { "id1" => true, "id2" => false }
|
|
12
|
-
# visited.displace("id2", true) # == false
|
|
13
|
-
# visited # == { "id1" => true, "id2" => true }
|
|
14
|
-
# visited.displace("id3", true) # == nil
|
|
15
|
-
# visited # == { "id1" => true, "id2" => true, "id3" => true }
|
|
16
|
-
#
|
|
17
|
-
# @param key
|
|
18
|
-
# @param value
|
|
19
|
-
# @return [Hash]
|
|
20
|
-
def displace(key, value)
|
|
21
|
-
old_value = self[key]
|
|
22
|
-
self[key] = value
|
|
23
|
-
old_value
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
class Hash
|
|
2
|
-
|
|
3
|
-
# Associates +key+ with +value+. Similar to +Hash#[]=+, but returns
|
|
4
|
-
# the Hash instead of the value. Faster than +Hash#merge!+ for single
|
|
5
|
-
# updates in a loop.
|
|
6
|
-
#
|
|
7
|
-
# @example
|
|
8
|
-
# cache = id_list.reduce({}) do |hash, id|
|
|
9
|
-
# hash.put!(id, find_by_id(id))
|
|
10
|
-
# end
|
|
11
|
-
#
|
|
12
|
-
# @param key
|
|
13
|
-
# @param value
|
|
14
|
-
# @return [Hash]
|
|
15
|
-
def put!(key, value)
|
|
16
|
-
self[key] = value
|
|
17
|
-
self
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
end
|
data/lib/casual_support/hash.rb
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
class Struct
|
|
2
|
-
|
|
3
|
-
# Assigns values in the given Hash to corresponding attributes of the
|
|
4
|
-
# Struct. Both Symbol keys and String keys are accepted. Keys which
|
|
5
|
-
# don't correspond to an attribute of the Struct are ignored. Mutates
|
|
6
|
-
# the Struct and returns it.
|
|
7
|
-
#
|
|
8
|
-
# @example
|
|
9
|
-
# Point = Struct.new(:x, :y, :z)
|
|
10
|
-
# point = Point.new(10, 20, 30)
|
|
11
|
-
#
|
|
12
|
-
# point.assign_attributes(y: 30, z: 50).to_h # == { x: 10, y: 30, z: 50 }
|
|
13
|
-
#
|
|
14
|
-
# @param new_attributes [Hash{Symbol => Object}, Hash{String => Object}]
|
|
15
|
-
# @return [self]
|
|
16
|
-
def assign_attributes(new_attributes)
|
|
17
|
-
ms = self.members
|
|
18
|
-
new_attributes.each do |k, v|
|
|
19
|
-
m = k.to_sym
|
|
20
|
-
self[m] = v if ms.include?(m)
|
|
21
|
-
end
|
|
22
|
-
self
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
require_relative "assign_attributes"
|
|
2
|
-
|
|
3
|
-
class Struct
|
|
4
|
-
|
|
5
|
-
# Constructs an instance of a subclass of Struct, and assigns the
|
|
6
|
-
# values of the given +attributes+ Hash to the instance.
|
|
7
|
-
#
|
|
8
|
-
# This method is intended for use only with subclasses of Struct which
|
|
9
|
-
# do not alter the default signature of the +initialize+ method.
|
|
10
|
-
# Specifically, the +initialize+ method must support invocation with
|
|
11
|
-
# no arguments.
|
|
12
|
-
#
|
|
13
|
-
# @see Struct#assign_attributes
|
|
14
|
-
#
|
|
15
|
-
# @example
|
|
16
|
-
# Point = Struct.new(:x, :y, :z)
|
|
17
|
-
#
|
|
18
|
-
# Point.from_h(x: 10, y: 20, z: 30) # == Point.new(10, 20, 30)
|
|
19
|
-
#
|
|
20
|
-
# @param attributes [Hash{Symbol => Object}, Hash{String => Object}]
|
|
21
|
-
# @return [Struct]
|
|
22
|
-
def self.from_h(attributes)
|
|
23
|
-
raise "Struct.from_h is for use only with subclasses of Struct" if self == Struct
|
|
24
|
-
self.new.assign_attributes(attributes)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class Time
|
|
4
|
-
|
|
5
|
-
# Formats the Time as "HH:MM:SS". Equivalent to
|
|
6
|
-
# +strftime("%H:%M:%S")+, but faster.
|
|
7
|
-
#
|
|
8
|
-
# @example
|
|
9
|
-
# Time.new(1999, 12, 31, 23, 59, 59).to_hms # == "23:59:59"
|
|
10
|
-
#
|
|
11
|
-
# @return [String]
|
|
12
|
-
def to_hms
|
|
13
|
-
# Date#strftime appears to be **much** faster than Time#strftime
|
|
14
|
-
# (nearly 3x faster!). If Time#strftime becomes optimized to that
|
|
15
|
-
# level in the future, it should be used instead of sprintf.
|
|
16
|
-
sprintf("%02d:%02d:%02d", hour, min, sec)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class Time
|
|
4
|
-
|
|
5
|
-
# Formats the Time as "YYYY-MM-DD". Equivalent to
|
|
6
|
-
# +strftime("%Y-%m-%d")+, but faster.
|
|
7
|
-
#
|
|
8
|
-
# @example
|
|
9
|
-
# Time.new(1999, 12, 31, 23, 59, 59).to_ymd # == "1999-12-31"
|
|
10
|
-
#
|
|
11
|
-
# @return [String]
|
|
12
|
-
def to_ymd
|
|
13
|
-
# Date#strftime appears to be **much** faster than Time#strftime
|
|
14
|
-
# (nearly 3x faster!). If Time#strftime becomes optimized to that
|
|
15
|
-
# level in the future, it should be used instead of sprintf.
|
|
16
|
-
sprintf("%04d-%02d-%02d", year, month, day)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
end
|
data/lib/casual_support/time.rb
DELETED