mixins 0.1.0.pre.20250527171116 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 931a539b8bc837e347f9e8daaaa3bbf457f48e4c320512be024bc591852f6ddd
4
- data.tar.gz: 94ae6c7269ce07c2578499e51da76641b2b4df11caa5f76bc4dbd691ae61d43e
3
+ metadata.gz: bcf3c9472d6c1277ab2a4d1a78952074b07541119264cfde1843fe0cb50d29d1
4
+ data.tar.gz: 98d7c111b74b1e6d86b32dc71c92560ce819cecfd0f5d3a50c21a00f81564b86
5
5
  SHA512:
6
- metadata.gz: 25a3c87aa1e640ecc6f9b05c48717434d184a0987b35b78e38c19c5c57b399e2f63be87be3239e56f01800bd17dadefe79dfaabf0cad9b3e4274513f473fe2fa
7
- data.tar.gz: 56b6973f4de6917808a36e134575fe30c125f3ac6a9e03f3b507f4b2cae7c8b42ae40d032500d8c8e7f01d106c94811945e2dbd775ca70a2951eba9e141ae239
6
+ metadata.gz: a71863fb45814be58cc2066492c0a76ca3655133deb276d92757ae2893896890bb67ae1295c53ec68187e0d6633e8453a4712dd2779d25b550192a1719dd98b3
7
+ data.tar.gz: 7bed4e7fce7f9260cfb227c4da88db4e53083d2e54f9647514b424893d8991982e679de3edc33acef50a94d918ebba439a69b01698dd6b7ddec480da081bf972
checksums.yaml.gz.sig CHANGED
Binary file
data/History.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Release History for mixins
2
2
 
3
3
  ---
4
-
5
- ## v0.0.1 [2025-05-27] Michael Granger <ged@faeriemud.org>
4
+ ## v0.1.0 [2025-07-12] Michael Granger <ged@faeriemud.org>
6
5
 
7
6
  First release.
7
+
data/README.md CHANGED
@@ -4,7 +4,7 @@ home
4
4
  : https://hg.sr.ht/~ged/Mixins
5
5
 
6
6
  code
7
- : https://hg.sr.ht/~ged/Mixins
7
+ : https://hg.sr.ht/~ged/Mixins/browse
8
8
 
9
9
  github
10
10
  : https://github.com/ged/mixins
@@ -54,11 +54,12 @@ This will install dependencies, and do any other necessary setup for development
54
54
  ## Authors
55
55
 
56
56
  - Michael Granger <ged@faeriemud.org>
57
+ - Mahlon E. Smith <mahlon@martini.nu>
57
58
 
58
59
 
59
60
  ## License
60
61
 
61
- Copyright (c) 2025, Michael Granger
62
+ Copyright (c) 2025, Michael Granger and Mahlon E. Smith
62
63
  All rights reserved.
63
64
 
64
65
  Redistribution and use in source and binary forms, with or without
@@ -8,8 +8,11 @@ require 'mixins' unless defined?( Mixins )
8
8
  # A collection of miscellaneous functions that are useful for manipulating
9
9
  # complex data structures.
10
10
  #
11
- # include Ravn::DataUtilities
12
- # newhash = deep_copy( oldhash )
11
+ # include Mixins::DataUtilities
12
+ # newhash = deep_copy( oldhash )
13
+ #
14
+ # # or called as a module function
15
+ # newhash = Mixins::DataUtilities.deep_copy( oldhash )
13
16
  #
14
17
  module Mixins::DataUtilities
15
18
 
@@ -6,19 +6,35 @@ require 'rubygems'
6
6
  require 'mixins' unless defined?( Mixins )
7
7
 
8
8
 
9
- # When extended in a class, automatically set the path to a DATA_DIR
10
- # constant, derived from the class name. Prefers environmental
9
+ # Adds a #data_dir method and a DATA_DIR constant to extended objects. These
10
+ # will be set to the `Pathname` to the data directory distributed with a gem of the
11
+ # name derived from the `#name` of the extended object. Prefers environmental
11
12
  # override, Gem path, then local filesystem pathing.
12
13
  #
13
14
  # This can also be called manually if the including class name doesn't
14
15
  # match the gem, or something else esoteric.
15
16
  #
16
- # DATA_DIR is a Pathname object.
17
+ # require 'mixins'
18
+ #
19
+ # class Acme
20
+ # extend Mixins::Datadir
21
+ # end
22
+ #
23
+ # # When loading from checked-out source
24
+ # Rhizos.data_dir
25
+ # # => #<Pathname:../data/acme>
26
+ #
27
+ # # With ACME_DATADIR=/path/to/data set in the environment before Ruby starts:
28
+ # Rhizos.data_dir
29
+ # # => #<Pathname:/path/to/data>
30
+ #
31
+ # # When installed via gem
32
+ # Rhizos.data_dir
33
+ # # => #<Pathname:/path/to/lib/ruby/gems/3.4.0/gems/acme-1.0.0/data/acme>
17
34
  #
18
35
  module Mixins::Datadir
19
36
 
20
- ### Extend hook: Set the DATA_DIR constant in the extending
21
- ### class.
37
+ ### Extend hook: Set up the `data_dir` accessor and the `DATA_DIR` constant
22
38
  ###
23
39
  def self::extended( obj )
24
40
  name = obj.name.downcase.gsub( '::', '-' )
@@ -30,10 +46,11 @@ module Mixins::Datadir
30
46
  end
31
47
 
32
48
 
33
- ### Return a pathname object for the extended class DATA_DIR. This
34
- ### allows for the DATA_DIR constant to be used transparently between
35
- ### development (local checkout) and production (gem installation)
36
- ### environments.
49
+ ### Return a pathname object for the gem data directory. Use the `<gemname>_DATADIR`
50
+ ### environment variable if it's set, or the data directory of the loaded gem if
51
+ ### there is one. If neither of those are set, fall back to a relative path of
52
+ ### `../../data/<gemname>`. You can override which environment variable is used for
53
+ ### the override by setting +env+.
37
54
  ###
38
55
  def self::find_datadir( gemname, env: nil )
39
56
  unless env
@@ -50,7 +67,7 @@ module Mixins::Datadir
50
67
  Pathname( loaded_gemspec.datadir )
51
68
  else
52
69
  caller_path = caller_locations( 2, 1 ).first.absolute_path
53
- Pathname( caller_path ).dirname.parent.parent + "data/#{gemname}"
70
+ Pathname( caller_path ).dirname.parent + "data/#{gemname}"
54
71
  end
55
72
 
56
73
  return dir
@@ -10,18 +10,18 @@ module Mixins::Delegation
10
10
  ### Define the given +delegated_methods+ as delegators to the like-named method
11
11
  ### of the return value of the +delegate_method+.
12
12
  ###
13
- ### class MyClass
14
- ### extend Strelka::Delegation
13
+ ### class MyClass
14
+ ### extend Mixins::Delegation
15
15
  ###
16
- ### # Delegate the #bound?, #err, and #result2error methods to the connection
17
- ### # object returned by the #connection method. This allows the connection
18
- ### # to still be loaded on demand/overridden/etc.
19
- ### def_method_delegators :connection, :bound?, :err, :result2error
16
+ ### # Delegate the #bound?, #err, and #result2error methods to the connection
17
+ ### # object returned by the #connection method. This allows the connection
18
+ ### # to still be loaded on demand/overridden/etc.
19
+ ### def_method_delegators :connection, :bound?, :err, :result2error
20
20
  ###
21
- ### def connection
22
- ### @connection ||= self.connect
23
- ### end
24
- ### end
21
+ ### def connection
22
+ ### @connection ||= self.connect
23
+ ### end
24
+ ### end
25
25
  ###
26
26
  def def_method_delegators( delegate_method, *delegated_methods )
27
27
  delegated_methods.each do |name|
@@ -35,13 +35,13 @@ module Mixins::Delegation
35
35
  ### of the specified +ivar+. This is pretty much identical with how 'Forwardable'
36
36
  ### from the stdlib does delegation, but it's reimplemented here for consistency.
37
37
  ###
38
- ### class MyClass
39
- ### extend Strelka::Delegation
38
+ ### class MyClass
39
+ ### extend Mixins::Delegation
40
40
  ###
41
- ### # Delegate the #each method to the @collection ivar
42
- ### def_ivar_delegators :@collection, :each
41
+ ### # Delegate the #each method to the @collection ivar
42
+ ### def_ivar_delegators :@collection, :each
43
43
  ###
44
- ### end
44
+ ### end
45
45
  ###
46
46
  def def_ivar_delegators( ivar, *delegated_methods )
47
47
  delegated_methods.each do |name|
data/lib/mixins/hooks.rb CHANGED
@@ -5,24 +5,24 @@ require 'mixins' unless defined?( Mixins )
5
5
 
6
6
  # Methods for declaring hook methods.
7
7
  #
8
- # class MyClass
9
- # extend Mixins::Hooks
8
+ # class MyClass
9
+ # extend Mixins::Hooks
10
10
  #
11
- # define_hook :before_fork
12
- # define_hook :after_fork
13
- # end
11
+ # define_hook :before_fork
12
+ # define_hook :after_fork
13
+ # end
14
14
  #
15
- # MyClass.before_fork do
16
- # @socket.close
17
- # end
18
- # MyClass.after_fork do
19
- # @socket = Socket.new
20
- # end
15
+ # MyClass.before_fork do
16
+ # @socket.close
17
+ # end
18
+ # MyClass.after_fork do
19
+ # @socket = Socket.new
20
+ # end
21
21
  #
22
- # MyClass.run_before_fork_hook
23
- # fork do
24
- # MyClass.run_after_fork_hook
25
- # end
22
+ # MyClass.run_before_fork_hook
23
+ # fork do
24
+ # MyClass.run_after_fork_hook
25
+ # end
26
26
  #
27
27
  #
28
28
  module Mixins::Hooks
@@ -4,6 +4,12 @@ require 'mixins' unless defined?( Mixins )
4
4
 
5
5
 
6
6
  # An extensible #inspect.
7
+ #
8
+ # This adds an overloaded #inspect method to including classes that provides
9
+ # a way to easily extend the default #inspect output. To add your own output to
10
+ # the body of the inspected object, implement the #inspect_details method and
11
+ # return your desired output from it. By default it returns the empty string, which
12
+ # will cause #inspect to use the default output.
7
13
  module Mixins::Inspection
8
14
 
9
15
  ### Return a human-readable representation of the object suitable for debugging.
@@ -11,11 +17,9 @@ module Mixins::Inspection
11
17
  details = self.inspect_details
12
18
  details = ' ' + details unless details.empty? || details.start_with?( ' ' )
13
19
 
14
- return "#<%p:#%x%s>" % [
15
- self.class,
16
- self.object_id,
17
- details,
18
- ]
20
+ default = super
21
+
22
+ return default.sub( /\s.*\z/, details << '>' )
19
23
  end
20
24
 
21
25
 
data/lib/mixins.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  module Mixins
7
7
 
8
8
  # Package version
9
- VERSION = '0.0.1'
9
+ VERSION = '0.1.0'
10
10
 
11
11
 
12
12
  autoload :MethodUtilities, 'mixins/method_utilities'
@@ -64,7 +64,7 @@ RSpec.describe( Mixins::Datadir ) do
64
64
  end
65
65
  target_class.extend( described_class )
66
66
 
67
- local_datadir = Pathname( __FILE__ ).parent.parent.parent / 'data' / 'panda'
67
+ local_datadir = Pathname( __FILE__ ).parent.parent / 'data' / 'panda'
68
68
 
69
69
  expect( target_class.data_dir ).to eq( local_datadir )
70
70
  end
@@ -16,7 +16,7 @@ RSpec.describe( Mixins::Inspection ) do
16
16
  oclass.include( described_class )
17
17
  instance = oclass.new( 11 )
18
18
 
19
- expect( instance.inspect ).to match( /#<#{oclass.inspect}:#\h+/ )
19
+ expect( instance.inspect ).to match( /#<#{oclass.inspect}:0x\h+/ )
20
20
  end
21
21
 
22
22
 
@@ -37,5 +37,23 @@ RSpec.describe( Mixins::Inspection ) do
37
37
  expect( instance.inspect ).to match( /#<\S+ serial: 13>/ )
38
38
  end
39
39
 
40
+
41
+ it "doesn't add a separator space if the details already being with a space" do
42
+ oclass = Class.new do
43
+ def initialize( serial )
44
+ @serial = serial
45
+ end
46
+ attr_reader :serial
47
+ def inspect_details
48
+ return " serial: %d" % [ self.serial ]
49
+ end
50
+ end
51
+ oclass.include( described_class )
52
+
53
+ instance = oclass.new( 13 )
54
+
55
+ expect( instance.inspect ).not_to match( /[ ]{2}/ )
56
+ end
57
+
40
58
  end
41
59
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.20250527171116
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
8
+ - Mahlon E. Smith
8
9
  bindir: bin
9
10
  cert_chain:
10
11
  - |
@@ -34,7 +35,7 @@ cert_chain:
34
35
  8qAqdfV+4u6Huu1KzAuDQCheyEyISsLST37sU/irV3czV6BiFipWag1XiJciRT3A
35
36
  wZqCfTNVHTdtsCbfdA1DsA3RdG2iEH3TOHzv1Rqzqh4=
36
37
  -----END CERTIFICATE-----
37
- date: 2025-05-27 00:00:00.000000000 Z
38
+ date: 2025-07-12 00:00:00.000000000 Z
38
39
  dependencies:
39
40
  - !ruby/object:Gem::Dependency
40
41
  name: rake-deveiate
@@ -55,6 +56,7 @@ description: This is a collection of zero-dependency mixins. They’re intended
55
56
  dependencies.
56
57
  email:
57
58
  - ged@faeriemud.org
59
+ - mahlon@martini.nu
58
60
  executables: []
59
61
  extensions: []
60
62
  extra_rdoc_files: []
@@ -81,11 +83,11 @@ homepage: https://hg.sr.ht/~ged/Mixins
81
83
  licenses:
82
84
  - BSD-3-Clause
83
85
  metadata:
84
- bug_tracker_uri: https://todo.sr.ht/~ged/Mixins
85
- changelog_uri: https://deveiate.org/code/mixins/History_md.html
86
- documentation_uri: https://deveiate.org/code/mixins
87
86
  homepage_uri: https://hg.sr.ht/~ged/Mixins
88
- source_uri: https://hg.sr.ht/~ged/Mixins
87
+ documentation_uri: https://deveiate.org/code/mixins
88
+ changelog_uri: https://deveiate.org/code/mixins/History_md.html
89
+ source_uri: https://hg.sr.ht/~ged/Mixins/browse
90
+ bug_tracker_uri: https://todo.sr.ht/~ged/Mixins/browse
89
91
  rdoc_options: []
90
92
  require_paths:
91
93
  - lib
@@ -100,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
102
  - !ruby/object:Gem::Version
101
103
  version: '0'
102
104
  requirements: []
103
- rubygems_version: 3.6.7
105
+ rubygems_version: 3.6.9
104
106
  specification_version: 4
105
107
  summary: This is a collection of zero-dependency mixins.
106
108
  test_files: []
metadata.gz.sig CHANGED
Binary file