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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0b92ba05be9a6f0ad71a911c435c78d450f06c094108e07b9bad99bc87ae512
4
- data.tar.gz: 893f5f3e708acd70741c6fd688463aad826f1eacd426bd48ec7b30c820ac8768
3
+ metadata.gz: b1b6de67e75bbf7aa49d6b57e04fe896aee7514eda1a9a13c24849ccbf21efce
4
+ data.tar.gz: 9a4eb5b9a69f7935a2e3910b22caaf3cf75550c0cf092f86bfce72af29f10eff
5
5
  SHA512:
6
- metadata.gz: 944da5f33d43a08cc3af8649123b8577e3c4fe504584c86d5aa31afd514c5a9112af504c8aca204f11a08c7ae078d3d9f9c6125dfaf8a3e45c6f2e80fa98d70f
7
- data.tar.gz: 2b6af778597dc30e0bb378d402c5a5c4504b4064b1f44bdcc38ba6a57014bd2bf74ff529579808d62d05ce5151717a6fa9bea18f600d2560f904ab545a5b63c2
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
@@ -3,6 +3,5 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in casual_support.gemspec
4
4
  gemspec
5
5
 
6
- gem "rake", "~> 12.0"
7
- gem "minitest", "~> 5.0"
8
- gem "benchmark-inputs", "~> 1.0"
6
+ gem "rake", "~> 13.0"
7
+ gem "minitest", "~> 6.0"
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # casual_support [![Build Status](https://travis-ci.org/jonathanhefner/casual_support.svg?branch=master)](https://travis-ci.org/jonathanhefner/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
- - [Date](https://www.rubydoc.info/gems/casual_support/Date)
10
- - [#to_hms](https://www.rubydoc.info/gems/casual_support/Date:to_hms)
11
- - [#to_ymd](https://www.rubydoc.info/gems/casual_support/Date:to_ymd)
12
- - [Enumerable](https://www.rubydoc.info/gems/casual_support/Enumerable)
13
- - [#duplicates](https://www.rubydoc.info/gems/casual_support/Enumerable:duplicates)
14
- - [#index_to](https://www.rubydoc.info/gems/casual_support/Enumerable:index_to)
15
- - [Hash](https://www.rubydoc.info/gems/casual_support/Hash)
16
- - [#displace](https://www.rubydoc.info/gems/casual_support/Hash:displace)
17
- - [#put!](https://www.rubydoc.info/gems/casual_support/Hash:put%21)
18
- - [String](https://www.rubydoc.info/gems/casual_support/String)
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
@@ -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 = ">= 2.6"
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.match(%r{^(test|spec|features|benchmarks)/}) }
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) }
@@ -1,2 +1 @@
1
1
  require_relative "enumerable/duplicates"
2
- require_relative "enumerable/index_to"
@@ -1,3 +1,3 @@
1
1
  module CasualSupport
2
- VERSION = "4.0.0"
2
+ VERSION = "5.0.0"
3
3
  end
@@ -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.0.0
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: 2020-02-02 00:00:00.000000000 Z
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: '2.6'
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: 3.1.2
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
@@ -1,10 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /gemfiles/*.lock
8
- /pkg/
9
- /spec/reports/
10
- /tmp/
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 2.6
5
- - 2.7
@@ -1,15 +0,0 @@
1
- require "date"
2
-
3
-
4
- class Date
5
-
6
- # Returns "00:00:00".
7
- #
8
- # Provided for parity with {Time#to_hms}.
9
- #
10
- # @return [String]
11
- def to_hms
12
- "00:00:00"
13
- end
14
-
15
- end
@@ -1,13 +0,0 @@
1
- require "date"
2
-
3
-
4
- class Date
5
-
6
- # Alias of +Date#to_s+. Formats the Date as "YYYY-MM-DD".
7
- #
8
- # Provided for parity with {Time#to_ymd}.
9
- #
10
- # @return [String]
11
- alias :to_ymd :to_s
12
-
13
- end
@@ -1,2 +0,0 @@
1
- require_relative "date/to_hms"
2
- require_relative "date/to_ymd"
@@ -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
@@ -1,2 +0,0 @@
1
- require_relative "hash/displace"
2
- require_relative "hash/putbang"
@@ -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,2 +0,0 @@
1
- require_relative "struct/assign_attributes"
2
- require_relative "struct/from_h"
@@ -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
@@ -1,2 +0,0 @@
1
- require_relative "time/to_hms"
2
- require_relative "time/to_ymd"