core 0.0.6 → 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
- checksums.yaml.gz.sig +0 -0
- data/LICENSE.adoc +134 -0
- data/README.adoc +93 -0
- data/core.gemspec +29 -0
- data/lib/core/identity.rb +5 -0
- data/lib/core.rb +11 -11
- data.tar.gz.sig +0 -0
- metadata +66 -60
- metadata.gz.sig +1 -0
- data/README.rdoc +0 -11
- data/Rakefile +0 -20
- data/lib/core/accessor.rb +0 -114
- data/lib/core/forwardable.rb +0 -85
- data/lib/core/functor.rb +0 -19
- data/lib/core/hash.rb +0 -13
- data/lib/core/inspect.rb +0 -20
- data/lib/core/module.rb +0 -93
- data/lib/core/object.rb +0 -64
- data/lib/core/this.rb +0 -78
- data/lib/kinda-core.rb +0 -1
- data/test/__all__.rb +0 -5
- data/test/accessor_test.rb +0 -131
- data/test/forwardable_test.rb +0 -51
- data/test/module_test.rb +0 -84
- data/test/object_test.rb +0 -28
- data/test/this_test.rb +0 -11
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6fb7a636ad3f8ebf125afc1e145187c957336a5adefb6deadf6b624785c9e8b1
|
4
|
+
data.tar.gz: f1327f5473b92c33cb0f58943f9e1728166e5197189a136518e46fc7e428cea3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bea3585e533efdaf3ecb5e92e8d06ec1b945cabaa4f91e1b3ebc968d9dabc5299fd93a325413f99c4b47459e7edd5dc36d621104958818dfa4aa88e2b58ed3d4
|
7
|
+
data.tar.gz: 352f945b9e7d135e9fad4971fa17df37b8b4a4029aeec051ba4bf1379b5050b8a0537c4013c5d95c45203f68a47f5f0555b279f820cc440560c8f5d0165312a0
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/LICENSE.adoc
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
= Hippocratic License
|
2
|
+
|
3
|
+
Version: 2.1.0.
|
4
|
+
|
5
|
+
Purpose. The purpose of this License is for the Licensor named above to
|
6
|
+
permit the Licensee (as defined below) broad permission, if consistent
|
7
|
+
with Human Rights Laws and Human Rights Principles (as each is defined
|
8
|
+
below), to use and work with the Software (as defined below) within the
|
9
|
+
full scope of Licensor’s copyright and patent rights, if any, in the
|
10
|
+
Software, while ensuring attribution and protecting the Licensor from
|
11
|
+
liability.
|
12
|
+
|
13
|
+
Permission and Conditions. The Licensor grants permission by this
|
14
|
+
license ("License"), free of charge, to the extent of Licensor’s
|
15
|
+
rights under applicable copyright and patent law, to any person or
|
16
|
+
entity (the "Licensee") obtaining a copy of this software and
|
17
|
+
associated documentation files (the "Software"), to do everything with
|
18
|
+
the Software that would otherwise infringe (i) the Licensor’s copyright
|
19
|
+
in the Software or (ii) any patent claims to the Software that the
|
20
|
+
Licensor can license or becomes able to license, subject to all of the
|
21
|
+
following terms and conditions:
|
22
|
+
|
23
|
+
* Acceptance. This License is automatically offered to every person and
|
24
|
+
entity subject to its terms and conditions. Licensee accepts this
|
25
|
+
License and agrees to its terms and conditions by taking any action with
|
26
|
+
the Software that, absent this License, would infringe any intellectual
|
27
|
+
property right held by Licensor.
|
28
|
+
* Notice. Licensee must ensure that everyone who gets a copy of any part
|
29
|
+
of this Software from Licensee, with or without changes, also receives
|
30
|
+
the License and the above copyright notice (and if included by the
|
31
|
+
Licensor, patent, trademark and attribution notice). Licensee must cause
|
32
|
+
any modified versions of the Software to carry prominent notices stating
|
33
|
+
that Licensee changed the Software. For clarity, although Licensee is
|
34
|
+
free to create modifications of the Software and distribute only the
|
35
|
+
modified portion created by Licensee with additional or different terms,
|
36
|
+
the portion of the Software not modified must be distributed pursuant to
|
37
|
+
this License. If anyone notifies Licensee in writing that Licensee has
|
38
|
+
not complied with this Notice section, Licensee can keep this License by
|
39
|
+
taking all practical steps to comply within 30 days after the notice. If
|
40
|
+
Licensee does not do so, Licensee’s License (and all rights licensed
|
41
|
+
hereunder) shall end immediately.
|
42
|
+
* Compliance with Human Rights Principles and Human Rights Laws.
|
43
|
+
[arabic]
|
44
|
+
. Human Rights Principles.
|
45
|
+
[loweralpha]
|
46
|
+
.. Licensee is advised to consult the articles of the United Nations
|
47
|
+
Universal Declaration of Human Rights and the United Nations Global
|
48
|
+
Compact that define recognized principles of international human rights
|
49
|
+
(the "Human Rights Principles"). Licensee shall use the Software in a
|
50
|
+
manner consistent with Human Rights Principles.
|
51
|
+
.. Unless the Licensor and Licensee agree otherwise, any dispute,
|
52
|
+
controversy, or claim arising out of or relating to (i) Section 1(a)
|
53
|
+
regarding Human Rights Principles, including the breach of Section 1(a),
|
54
|
+
termination of this License for breach of the Human Rights Principles,
|
55
|
+
or invalidity of Section 1(a) or (ii) a determination of whether any Law
|
56
|
+
is consistent or in conflict with Human Rights Principles pursuant to
|
57
|
+
Section 2, below, shall be settled by arbitration in accordance with the
|
58
|
+
Hague Rules on Business and Human Rights Arbitration (the "Rules");
|
59
|
+
provided, however, that Licensee may elect not to participate in such
|
60
|
+
arbitration, in which event this License (and all rights licensed
|
61
|
+
hereunder) shall end immediately. The number of arbitrators shall be one
|
62
|
+
unless the Rules require otherwise.
|
63
|
+
+
|
64
|
+
Unless both the Licensor and Licensee agree to the contrary: (1) All
|
65
|
+
documents and information concerning the arbitration shall be public and
|
66
|
+
may be disclosed by any party; (2) The repository referred to under
|
67
|
+
Article 43 of the Rules shall make available to the public in a timely
|
68
|
+
manner all documents concerning the arbitration which are communicated
|
69
|
+
to it, including all submissions of the parties, all evidence admitted
|
70
|
+
into the record of the proceedings, all transcripts or other recordings
|
71
|
+
of hearings and all orders, decisions and awards of the arbitral
|
72
|
+
tribunal, subject only to the arbitral tribunal’s powers to take such
|
73
|
+
measures as may be necessary to safeguard the integrity of the arbitral
|
74
|
+
process pursuant to Articles 18, 33, 41 and 42 of the Rules; and (3)
|
75
|
+
Article 26(6) of the Rules shall not apply.
|
76
|
+
. Human Rights Laws. The Software shall not be used by any person or
|
77
|
+
entity for any systems, activities, or other uses that violate any Human
|
78
|
+
Rights Laws. "Human Rights Laws" means any applicable laws,
|
79
|
+
regulations, or rules (collectively, "Laws") that protect human,
|
80
|
+
civil, labor, privacy, political, environmental, security, economic, due
|
81
|
+
process, or similar rights; provided, however, that such Laws are
|
82
|
+
consistent and not in conflict with Human Rights Principles (a dispute
|
83
|
+
over the consistency or a conflict between Laws and Human Rights
|
84
|
+
Principles shall be determined by arbitration as stated above). Where
|
85
|
+
the Human Rights Laws of more than one jurisdiction are applicable or in
|
86
|
+
conflict with respect to the use of the Software, the Human Rights Laws
|
87
|
+
that are most protective of the individuals or groups harmed shall
|
88
|
+
apply.
|
89
|
+
. Indemnity. Licensee shall hold harmless and indemnify Licensor (and
|
90
|
+
any other contributor) against all losses, damages, liabilities,
|
91
|
+
deficiencies, claims, actions, judgments, settlements, interest, awards,
|
92
|
+
penalties, fines, costs, or expenses of whatever kind, including
|
93
|
+
Licensor’s reasonable attorneys’ fees, arising out of or relating to
|
94
|
+
Licensee’s use of the Software in violation of Human Rights Laws or
|
95
|
+
Human Rights Principles.
|
96
|
+
* Failure to Comply. Any failure of Licensee to act according to the
|
97
|
+
terms and conditions of this License is both a breach of the License and
|
98
|
+
an infringement of the intellectual property rights of the Licensor
|
99
|
+
(subject to exceptions under Laws, e.g., fair use). In the event of a
|
100
|
+
breach or infringement, the terms and conditions of this License may be
|
101
|
+
enforced by Licensor under the Laws of any jurisdiction to which
|
102
|
+
Licensee is subject. Licensee also agrees that the Licensor may enforce
|
103
|
+
the terms and conditions of this License against Licensee through
|
104
|
+
specific performance (or similar remedy under Laws) to the extent
|
105
|
+
permitted by Laws. For clarity, except in the event of a breach of this
|
106
|
+
License, infringement, or as otherwise stated in this License, Licensor
|
107
|
+
may not terminate this License with Licensee.
|
108
|
+
* Enforceability and Interpretation. If any term or provision of this
|
109
|
+
License is determined to be invalid, illegal, or unenforceable by a
|
110
|
+
court of competent jurisdiction, then such invalidity, illegality, or
|
111
|
+
unenforceability shall not affect any other term or provision of this
|
112
|
+
License or invalidate or render unenforceable such term or provision in
|
113
|
+
any other jurisdiction; provided, however, subject to a court
|
114
|
+
modification pursuant to the immediately following sentence, if any term
|
115
|
+
or provision of this License pertaining to Human Rights Laws or Human
|
116
|
+
Rights Principles is deemed invalid, illegal, or unenforceable against
|
117
|
+
Licensee by a court of competent jurisdiction, all rights in the
|
118
|
+
Software granted to Licensee shall be deemed null and void as between
|
119
|
+
Licensor and Licensee. Upon a determination that any term or provision
|
120
|
+
is invalid, illegal, or unenforceable, to the extent permitted by Laws,
|
121
|
+
the court may modify this License to affect the original purpose that
|
122
|
+
the Software be used in compliance with Human Rights Principles and
|
123
|
+
Human Rights Laws as closely as possible. The language in this License
|
124
|
+
shall be interpreted as to its fair meaning and not strictly for or
|
125
|
+
against any party.
|
126
|
+
* Disclaimer. TO THE FULL EXTENT ALLOWED BY LAW, THIS SOFTWARE COMES
|
127
|
+
"AS IS," WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED, AND LICENSOR AND
|
128
|
+
ANY OTHER CONTRIBUTOR SHALL NOT BE LIABLE TO ANYONE FOR ANY DAMAGES OR
|
129
|
+
OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE
|
130
|
+
OR THIS LICENSE, UNDER ANY KIND OF LEGAL CLAIM.
|
131
|
+
|
132
|
+
This Hippocratic License is an link:https://ethicalsource.dev[Ethical Source license] and is offered
|
133
|
+
for use by licensors and licensees at their own risk, on an "AS IS" basis, and with no warranties
|
134
|
+
express or implied, to the maximum extent permitted by Laws.
|
data/README.adoc
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
:toc: macro
|
2
|
+
:toclevels: 5
|
3
|
+
:figure-caption!:
|
4
|
+
|
5
|
+
= Core
|
6
|
+
|
7
|
+
Provides a collection of core objects missing from the standard Ruby distribution. This is meant to provide common objects for engineering advanced architctures in order to reduce duplication, improve performance, and improve memory usage.
|
8
|
+
|
9
|
+
toc::[]
|
10
|
+
|
11
|
+
== Features
|
12
|
+
|
13
|
+
* Provides commonly needed core objects.
|
14
|
+
|
15
|
+
== Requirements
|
16
|
+
|
17
|
+
. link:https://www.ruby-lang.org[Ruby].
|
18
|
+
|
19
|
+
== Setup
|
20
|
+
|
21
|
+
To set up the project, run:
|
22
|
+
|
23
|
+
[source,bash]
|
24
|
+
----
|
25
|
+
bin/setup
|
26
|
+
----
|
27
|
+
|
28
|
+
== Usage
|
29
|
+
|
30
|
+
The following details what is currently available for use.
|
31
|
+
|
32
|
+
=== Constants
|
33
|
+
|
34
|
+
The following _empty_ constants are frozen by default and available for use as core objects for use throughout your application.
|
35
|
+
|
36
|
+
* `Core::EMPTY_ARRAY`: Provides an empty link:https://rubyapi.org/o/array[Array] instance.
|
37
|
+
* `Core::EMPTY_DATA`: Provides an empty link:https://www.alchemists.io/articles/ruby_data[Data] instance.
|
38
|
+
* `Core::EMPTY_HASH`: Provides an empty link:https://rubyapi.org/o/hash[Hash] instance.
|
39
|
+
* `Core::EMPTY_SET`: Provides an empty link:https://rubyapi.org/o/set[Set] instance.
|
40
|
+
* `Core::EMPTY_STRING`: Provides an empty link:https://rubyapi.org/o/string[String] instance.
|
41
|
+
|
42
|
+
=== Functions
|
43
|
+
|
44
|
+
The following identity function (lambda) is available as a neutral value in link:https://www.alchemists.io/articles/ruby_function_composition[function composition]:
|
45
|
+
|
46
|
+
[source,ruby]
|
47
|
+
----
|
48
|
+
Core::Identity.call "example" # "example"
|
49
|
+
----
|
50
|
+
|
51
|
+
== Development
|
52
|
+
|
53
|
+
To contribute, run:
|
54
|
+
|
55
|
+
[source,bash]
|
56
|
+
----
|
57
|
+
git clone https://github.com/bkuhlmann/core
|
58
|
+
cd core
|
59
|
+
bin/setup
|
60
|
+
----
|
61
|
+
|
62
|
+
You can also use the IRB console for direct access to all objects:
|
63
|
+
|
64
|
+
[source,bash]
|
65
|
+
----
|
66
|
+
bin/console
|
67
|
+
----
|
68
|
+
|
69
|
+
== Tests
|
70
|
+
|
71
|
+
To test, run:
|
72
|
+
|
73
|
+
[source,bash]
|
74
|
+
----
|
75
|
+
bundle exec rake
|
76
|
+
----
|
77
|
+
|
78
|
+
== link:https://www.alchemists.io/policies/license[License]
|
79
|
+
|
80
|
+
== link:https://www.alchemists.io/policies/security[Security]
|
81
|
+
|
82
|
+
== link:https://www.alchemists.io/policies/code_of_conduct[Code of Conduct]
|
83
|
+
|
84
|
+
== link:https://www.alchemists.io/policies/contributions[Contributions]
|
85
|
+
|
86
|
+
== link:https://www.alchemists.io/projects/core/versions[Versions]
|
87
|
+
|
88
|
+
== link:https://www.alchemists.io/community[Community]
|
89
|
+
|
90
|
+
== Credits
|
91
|
+
|
92
|
+
* Built with link:https://www.alchemists.io/projects/gemsmith[Gemsmith].
|
93
|
+
* Engineered by link:https://www.alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].
|
data/core.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "core"
|
5
|
+
spec.version = "0.1.0"
|
6
|
+
spec.authors = ["Brooke Kuhlmann"]
|
7
|
+
spec.email = ["brooke@alchemists.io"]
|
8
|
+
spec.homepage = "https://www.alchemists.io/projects/core"
|
9
|
+
spec.summary = "A collection of core objects missing from the standard distribution."
|
10
|
+
spec.license = "Hippocratic-2.1"
|
11
|
+
|
12
|
+
spec.metadata = {
|
13
|
+
"bug_tracker_uri" => "https://github.com/bkuhlmann/core/issues",
|
14
|
+
"changelog_uri" => "https://www.alchemists.io/projects/core/versions",
|
15
|
+
"documentation_uri" => "https://www.alchemists.io/projects/core",
|
16
|
+
"funding_uri" => "https://github.com/sponsors/bkuhlmann",
|
17
|
+
"label" => "Core",
|
18
|
+
"rubygems_mfa_required" => "true",
|
19
|
+
"source_code_uri" => "https://github.com/bkuhlmann/core"
|
20
|
+
}
|
21
|
+
|
22
|
+
spec.signing_key = Gem.default_key_path
|
23
|
+
spec.cert_chain = [Gem.default_cert_path]
|
24
|
+
|
25
|
+
spec.required_ruby_version = "~> 3.2"
|
26
|
+
|
27
|
+
spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
|
28
|
+
spec.files = Dir["*.gemspec", "lib/**/*"]
|
29
|
+
end
|
data/lib/core.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
|
2
|
-
require File.join(File.dirname(__FILE__), 'core', 'object')
|
3
|
-
ruby_files = Dir.glob(File.join(File.dirname(__FILE__), 'core', '*.rb'))
|
4
|
-
ruby_files.each { |file| require file }
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
3
|
+
require "core/identity"
|
4
|
+
|
5
|
+
# Main namespace.
|
6
|
+
module Core
|
7
|
+
EMPTY_ARRAY = [].freeze
|
8
|
+
EMPTY_DATA = Data.define
|
9
|
+
EMPTY_HASH = {}.freeze
|
10
|
+
EMPTY_SET = Set.new.freeze
|
11
|
+
EMPTY_STRING = ""
|
12
|
+
end
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
CHANGED
@@ -1,71 +1,77 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: core
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
6
|
+
authors:
|
7
|
+
- Brooke Kuhlmann
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIC/jCCAeagAwIBAgIBBTANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBpicm9v
|
14
|
+
a2UvREM9YWxjaGVtaXN0cy9EQz1pbzAeFw0yMjAzMTkxNzI0MzJaFw0yMzAzMTkx
|
15
|
+
NzI0MzJaMCUxIzAhBgNVBAMMGmJyb29rZS9EQz1hbGNoZW1pc3RzL0RDPWlvMIIB
|
16
|
+
IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6l1qpXTiomH1RfMRloyw7MiE
|
17
|
+
xyVx/x8Yc3EupdH7uhNaTXQGyORN6aOY//1QXXMHIZ9tW74nZLhesWMSUMYy0XhB
|
18
|
+
brs+KkurHnc9FnEJAbG7ebGvl/ncqZt72nQvaxpDxvuCBHgJAz+8i5wl6FhLw+oT
|
19
|
+
9z0A8KcGhz67SdcoQiD7qiCjL/2NTeWHOzkpPrdGlt088+VerEEGf5I13QCvaftP
|
20
|
+
D5vkU0YlAm1r98BymuJlcQ1qdkVEI1d48ph4kcS0S0nv1RiuyVb6TCAR3Nu3VaVq
|
21
|
+
3fPzZKJLZBx67UvXdbdicWPiUR75elI4PXpLIic3xytaF52ZJYyKZCNZJhNwfQID
|
22
|
+
AQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU0nzow9vc
|
23
|
+
2CdikiiE3fJhP/gY4ggwDQYJKoZIhvcNAQELBQADggEBAJbbNyWzFjqUNVPPCUCo
|
24
|
+
IMrhDa9xf1xkORXNYYbmXgoxRy/KyNbUr+jgEEoWJAm9GXlcqxxWAUI6pK/i4/Qi
|
25
|
+
X6rPFEFmeObDOHNvuqy8Hd6AYsu+kP94U/KJhe9wnWGMmGoNKJNU3EkW3jM/osSl
|
26
|
+
+JRxiH5t4WtnDiVyoYl5nYC02rYdjJkG6VMxDymXTqn7u6HhYgZkGujq1UPar8x2
|
27
|
+
hNIWJblDKKSu7hA2d6+kUthuYo13o1sg1Da/AEDg0hoZSUvhqDEF5Hy232qb3pDt
|
28
|
+
CxDe2+VuChj4I1nvIHdu+E6XoEVlanUPKmSg6nddhkKn2gC45Kyzh6FZqnzH/CRp
|
29
|
+
RFE=
|
30
|
+
-----END CERTIFICATE-----
|
31
|
+
date: 2023-01-07 00:00:00.000000000 Z
|
14
32
|
dependencies: []
|
15
|
-
|
16
|
-
|
17
|
-
|
33
|
+
description:
|
34
|
+
email:
|
35
|
+
- brooke@alchemists.io
|
18
36
|
executables: []
|
19
|
-
|
20
37
|
extensions: []
|
21
|
-
|
22
|
-
|
23
|
-
-
|
24
|
-
files:
|
25
|
-
-
|
38
|
+
extra_rdoc_files:
|
39
|
+
- README.adoc
|
40
|
+
- LICENSE.adoc
|
41
|
+
files:
|
42
|
+
- LICENSE.adoc
|
43
|
+
- README.adoc
|
44
|
+
- core.gemspec
|
26
45
|
- lib/core.rb
|
27
|
-
- lib/
|
28
|
-
|
29
|
-
|
30
|
-
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
post_install_message:
|
46
|
+
- lib/core/identity.rb
|
47
|
+
homepage: https://www.alchemists.io/projects/core
|
48
|
+
licenses:
|
49
|
+
- Hippocratic-2.1
|
50
|
+
metadata:
|
51
|
+
bug_tracker_uri: https://github.com/bkuhlmann/core/issues
|
52
|
+
changelog_uri: https://www.alchemists.io/projects/core/versions
|
53
|
+
documentation_uri: https://www.alchemists.io/projects/core
|
54
|
+
funding_uri: https://github.com/sponsors/bkuhlmann
|
55
|
+
label: Core
|
56
|
+
rubygems_mfa_required: 'true'
|
57
|
+
source_code_uri: https://github.com/bkuhlmann/core
|
58
|
+
post_install_message:
|
42
59
|
rdoc_options: []
|
43
|
-
|
44
|
-
require_paths:
|
60
|
+
require_paths:
|
45
61
|
- lib
|
46
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
-
requirements:
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '3.2'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
48
69
|
- - ">="
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version:
|
51
|
-
version:
|
52
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
-
requirements:
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: "0"
|
57
|
-
version:
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
58
72
|
requirements: []
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
summary: Basic helpers used by other kinda projects
|
65
|
-
test_files:
|
66
|
-
- test/__all__.rb
|
67
|
-
- test/accessor_test.rb
|
68
|
-
- test/forwardable_test.rb
|
69
|
-
- test/module_test.rb
|
70
|
-
- test/object_test.rb
|
71
|
-
- test/this_test.rb
|
73
|
+
rubygems_version: 3.4.2
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: A collection of core objects missing from the standard distribution.
|
77
|
+
test_files: []
|
metadata.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
�Zn�]������L�X��H\����.�G�r<����A���O�kͮ}?BcSR� �k$|WB�%us]�F����3K�k�&[{��s�Lw{+UF��R ��<��rd���^z>Uv�⫵�jwb�a�����eU�Z����|T7&����R�Jϡ��˧@��Y�#_��=��_�9��r�ب�G1^Pt#TOb����s�yi(9z�@�Gې�@6���!��7�w����`�r���dm���!-
|
data/README.rdoc
DELETED
data/Rakefile
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require "rake/testtask"
|
2
|
-
|
3
|
-
begin
|
4
|
-
require "hanna/rdoctask"
|
5
|
-
rescue LoadError
|
6
|
-
require "rake/rdoctask"
|
7
|
-
end
|
8
|
-
|
9
|
-
task :default => [:test]
|
10
|
-
|
11
|
-
Rake::TestTask.new do |t|
|
12
|
-
t.test_files = Dir["test/*_test.rb"]
|
13
|
-
end
|
14
|
-
|
15
|
-
Rake::RDocTask.new do |t|
|
16
|
-
t.title = "Core Documentation"
|
17
|
-
t.main = "README.rdoc"
|
18
|
-
t.rdoc_files.include("README.rdoc", "lib/**/*.rb")
|
19
|
-
t.rdoc_dir = "doc"
|
20
|
-
end
|
data/lib/core/accessor.rb
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
module Kinda #:nodoc:
|
2
|
-
module Core #:nodoc:
|
3
|
-
# Improves the Ruby buit-in accessor methods
|
4
|
-
module Accessor
|
5
|
-
ClassMethods = inheritable_extend do
|
6
|
-
def __attr_reader__(*attributes, with_filter, &block)
|
7
|
-
attributes.each do |attribute|
|
8
|
-
if attribute.is_a?(Hash)
|
9
|
-
attribute, source = attribute.first
|
10
|
-
else
|
11
|
-
source = "@#{attribute}"
|
12
|
-
end
|
13
|
-
proc = if with_filter || !block
|
14
|
-
Proc.new do |*args|
|
15
|
-
return send("#{attribute}=", *args) unless args.empty?
|
16
|
-
value = if source[0] == '@'
|
17
|
-
instance_variable_get(source)
|
18
|
-
else
|
19
|
-
[*source].inject(self) do |object, symbol|
|
20
|
-
object.send(symbol)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
block ? instance_exec(value, &block) : value
|
24
|
-
end
|
25
|
-
else
|
26
|
-
block
|
27
|
-
end
|
28
|
-
send(:define_method, attribute, &proc)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
private :__attr_reader__
|
33
|
-
|
34
|
-
# attr_reader(:name, :age, :size)
|
35
|
-
# attr_reader(:name => :@name) is the default behaviour but you can use:
|
36
|
-
# attr_reader (:name => @the_name) to use a different instance variable
|
37
|
-
# attr_reader(:name => :first_name) or even an another attribute.
|
38
|
-
# More interesting, you can delegate to another object:
|
39
|
-
# attr_reader(:name => [:father, :name])
|
40
|
-
# attr_reader(:name => [:mother, :husband, :name])
|
41
|
-
def attr_reader(*attributes, &block)
|
42
|
-
__attr_reader__(*attributes, false, &block)
|
43
|
-
end
|
44
|
-
|
45
|
-
def attr_reader_with_filter(*attributes, &block)
|
46
|
-
__attr_reader__(*attributes, true, &block)
|
47
|
-
end
|
48
|
-
|
49
|
-
def __attr_writer__(*attributes, with_filter, &block)
|
50
|
-
attributes.each do |attribute|
|
51
|
-
if attribute.is_a?(Hash)
|
52
|
-
attribute, target = attribute.first
|
53
|
-
else
|
54
|
-
target = "@#{attribute}"
|
55
|
-
end
|
56
|
-
proc = if with_filter || !block
|
57
|
-
Proc.new do |value|
|
58
|
-
value = instance_exec(value, &block) if block
|
59
|
-
if target[0] == '@'
|
60
|
-
instance_variable_set(target, value)
|
61
|
-
else
|
62
|
-
[*target][0..-2].inject(self) do |object, symbol|
|
63
|
-
object.send(symbol)
|
64
|
-
end.send("#{[*target].last}=", value)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
else
|
68
|
-
block
|
69
|
-
end
|
70
|
-
send(:define_method, "#{attribute}=", &proc)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
private :__attr_writer__
|
75
|
-
|
76
|
-
def attr_writer(*attributes, &block)
|
77
|
-
__attr_writer__(*attributes, false, &block)
|
78
|
-
end
|
79
|
-
|
80
|
-
def attr_writer_with_filter(*attributes, &block)
|
81
|
-
__attr_writer__(*attributes, true, &block)
|
82
|
-
end
|
83
|
-
|
84
|
-
def attr_accessor(*attributes, &block)
|
85
|
-
attr_reader(*attributes, &block)
|
86
|
-
attr_writer(*attributes, &block)
|
87
|
-
end
|
88
|
-
|
89
|
-
def attr_accessor_with_filter(*attributes, &block)
|
90
|
-
attr_reader_with_filter(*attributes, &block)
|
91
|
-
attr_writer_with_filter(*attributes, &block)
|
92
|
-
end
|
93
|
-
|
94
|
-
def attr(attribute, writable=false)
|
95
|
-
attr_reader(attribute)
|
96
|
-
attr_writer(attribute) if writable
|
97
|
-
end
|
98
|
-
|
99
|
-
def attr_reader_with_default(attribute, default_value)
|
100
|
-
attr_reader_with_filter(attribute) do |value|
|
101
|
-
value.nil? ? default_value : value
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def attr_accessor_with_default(attribute, default_value)
|
106
|
-
attr_reader_with_default(attribute, default_value)
|
107
|
-
attr_writer(attribute)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
delegate_to_class ClassMethods.public_instance_methods
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
data/lib/core/forwardable.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
|
-
module Kinda
|
4
|
-
module Core
|
5
|
-
module Forwardable
|
6
|
-
ClassMethods = inheritable_extend do
|
7
|
-
include ::Forwardable
|
8
|
-
|
9
|
-
# Add a nice way to specify a different method for the accessor:
|
10
|
-
# delegate :remove => [:book, :delete]
|
11
|
-
# delegate [:add, :remove] => [:book, :<<, :delete]
|
12
|
-
def instance_delegate(hash)
|
13
|
-
hash.each do |delegate_methods, accessor|
|
14
|
-
accessor_methods = [*accessor]
|
15
|
-
accessor_object = accessor_methods.shift
|
16
|
-
[*delegate_methods].each do |delegate_method|
|
17
|
-
accessor_method = accessor_methods.shift || delegate_method
|
18
|
-
def_instance_delegator(accessor_object, accessor_method, delegate_method)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
alias_method :delegate, :instance_delegate
|
24
|
-
|
25
|
-
# Create both reader and writer delegate
|
26
|
-
# Same usage than the simple "delegate" method except the following form
|
27
|
-
# in case the getter and setter symbols are different:
|
28
|
-
# delegate_attr :title => [:book, [:read_title, :write_title]]
|
29
|
-
def delegate_attr_accessor(hash, kind=(:accessor), with_filter=false, &block)
|
30
|
-
hash.each do |delegate_methods, accessor|
|
31
|
-
accessor_methods = [*accessor]
|
32
|
-
accessor_object = accessor_methods.shift
|
33
|
-
[*delegate_methods].each do |delegate_method|
|
34
|
-
accessor_method = accessor_methods.shift || delegate_method
|
35
|
-
accessor_getter, accessor_setter = case kind
|
36
|
-
when :accessor
|
37
|
-
getter, setter = [*accessor_method]
|
38
|
-
setter ||= getter
|
39
|
-
[getter, setter]
|
40
|
-
when :reader
|
41
|
-
[accessor_method, nil]
|
42
|
-
when :writer
|
43
|
-
[nil, accessor_method]
|
44
|
-
end
|
45
|
-
if accessor_getter
|
46
|
-
__attr_reader__({ delegate_method => [accessor_object, accessor_getter] },
|
47
|
-
with_filter, &block)
|
48
|
-
end
|
49
|
-
if accessor_setter
|
50
|
-
__attr_writer__({ delegate_method => [accessor_object, accessor_setter] },
|
51
|
-
with_filter, &block)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
alias_method :delegate_attr, :delegate_attr_accessor
|
58
|
-
|
59
|
-
def delegate_attr_accessor_with_filter(hash, &block)
|
60
|
-
delegate_attr_accessor(hash, :accessor, true, &block)
|
61
|
-
end
|
62
|
-
|
63
|
-
alias_method :delegate_attr_with_filter, :delegate_attr_accessor_with_filter
|
64
|
-
|
65
|
-
def delegate_attr_reader(hash, &block)
|
66
|
-
delegate_attr_accessor(hash, :reader, false, &block)
|
67
|
-
end
|
68
|
-
|
69
|
-
def delegate_attr_reader_with_filter(hash, &block)
|
70
|
-
delegate_attr_accessor(hash, :reader, true, &block)
|
71
|
-
end
|
72
|
-
|
73
|
-
def delegate_attr_writer(hash, &block)
|
74
|
-
delegate_attr_accessor(hash, :writer, false, &block)
|
75
|
-
end
|
76
|
-
|
77
|
-
def delegate_attr_writer_with_filter(hash, &block)
|
78
|
-
delegate_attr_accessor(hash, :writer, true, &block)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
delegate_to_class ClassMethods.public_instance_methods
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
data/lib/core/functor.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Kinda
|
2
|
-
module Core
|
3
|
-
# Thomas Sawyer's Functor Class slightly modified for Ruby 1.9
|
4
|
-
# http://facets.rubyforge.org/apidoc/api/core/classes/Functor.html
|
5
|
-
class Functor < BasicObject
|
6
|
-
def initialize(&proc)
|
7
|
-
@proc = proc
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_proc
|
11
|
-
@proc
|
12
|
-
end
|
13
|
-
|
14
|
-
def method_missing(method_name, *args, &block)
|
15
|
-
@proc.call(method_name, *args, &block)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/core/hash.rb
DELETED
data/lib/core/inspect.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module Kinda
|
2
|
-
module Core
|
3
|
-
def inspect(*args)
|
4
|
-
if %w[Bignum Class Complex Date DateTime FalseClass Fixnum Float
|
5
|
-
Integer NilClass Numeric Range Rational Regexp String Symbol
|
6
|
-
Time TrueClass].include?(self.class.name)
|
7
|
-
super()
|
8
|
-
else
|
9
|
-
result = '#<'
|
10
|
-
result += "#{self.class}:#{object_hexid}"
|
11
|
-
items = args.map do |arg|
|
12
|
-
"#{arg}=#{send(arg).inspect}" if respond_to?(arg)
|
13
|
-
end.compact
|
14
|
-
result += ' ' + items.join(', ') if !items.empty?
|
15
|
-
result += '>'
|
16
|
-
result
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/core/module.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
module Kinda
|
2
|
-
module Core
|
3
|
-
module ModuleExtension
|
4
|
-
def self.included(klass)
|
5
|
-
klass.alias_method_chain :append_features, :inheritable_extensions
|
6
|
-
end
|
7
|
-
|
8
|
-
def alias_method_chain(target, feature)
|
9
|
-
# Strip out punctuation on predicates or bang methods since
|
10
|
-
# e.g. target?_without_feature is not a valid method name.
|
11
|
-
aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
|
12
|
-
yield(aliased_target, punctuation) if block_given?
|
13
|
-
|
14
|
-
with_method, without_method =
|
15
|
-
"#{aliased_target}_with_#{feature}#{punctuation}",
|
16
|
-
"#{aliased_target}_without_#{feature}#{punctuation}"
|
17
|
-
|
18
|
-
alias_method without_method, target
|
19
|
-
alias_method target, with_method
|
20
|
-
|
21
|
-
case
|
22
|
-
when public_method_defined?(without_method)
|
23
|
-
public target
|
24
|
-
when protected_method_defined?(without_method)
|
25
|
-
protected target
|
26
|
-
when private_method_defined?(without_method)
|
27
|
-
private target
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def container
|
32
|
-
space = name[0...(name.rindex( '::' ) || 0)]
|
33
|
-
space.empty? ? Object : eval(space)
|
34
|
-
end
|
35
|
-
|
36
|
-
def extensions
|
37
|
-
singleton_class.ancestors.take_while { |mod| !mod.is_a?(Class) }
|
38
|
-
end
|
39
|
-
|
40
|
-
def inheritable_extend(*mods, &block)
|
41
|
-
if block
|
42
|
-
mod = Module.new
|
43
|
-
mod.extend extensions
|
44
|
-
mod.module_eval(&block)
|
45
|
-
mods << mod
|
46
|
-
end
|
47
|
-
extend *mods
|
48
|
-
(@inheritable_extensions ||= []).unshift(*mods.reverse).uniq!
|
49
|
-
mod
|
50
|
-
end
|
51
|
-
|
52
|
-
def append_features_with_inheritable_extensions(target)
|
53
|
-
append_features_without_inheritable_extensions(target)
|
54
|
-
if @inheritable_extensions
|
55
|
-
target.extend *@inheritable_extensions
|
56
|
-
target.inheritable_extend *@inheritable_extensions.reverse
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# delegate_to_class :singleton_method_added => :method_added
|
61
|
-
# delegate_to_class [:attr_reader, :attr_writer]
|
62
|
-
# delegate_to_class ClassMethods.instance_methods
|
63
|
-
def delegate_to_class(*sources)
|
64
|
-
sources, target = sources.first.first if sources.first.is_a?(Hash)
|
65
|
-
[*sources].flatten.each do |source|
|
66
|
-
define_method(source) do |*args, &block|
|
67
|
-
singleton_class_send(target || source, *args, &block)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def self_and_ancestors
|
73
|
-
result = ancestors
|
74
|
-
result.unshift self unless result.first == self
|
75
|
-
result
|
76
|
-
end
|
77
|
-
|
78
|
-
def ancestors_without_self
|
79
|
-
result = ancestors
|
80
|
-
result.first == self ? result.drop(1) : result
|
81
|
-
end
|
82
|
-
|
83
|
-
def ancestor
|
84
|
-
ancestors_without_self.first
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
class Module #:nodoc:
|
91
|
-
include Kinda::Core::ModuleExtension
|
92
|
-
end
|
93
|
-
|
data/lib/core/object.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
module Kinda
|
2
|
-
module Core
|
3
|
-
module ObjectExtension
|
4
|
-
def self.included(klass)
|
5
|
-
klass.alias_method_chain :extend, :flexible_arguments
|
6
|
-
end
|
7
|
-
|
8
|
-
def object_hexid
|
9
|
-
"0x" + ('%.x' % (self.__id__ * 2))
|
10
|
-
end
|
11
|
-
|
12
|
-
def singleton_class
|
13
|
-
class << self; self; end
|
14
|
-
end
|
15
|
-
|
16
|
-
def singleton_class_eval(&block)
|
17
|
-
singleton_class.class_eval(&block)
|
18
|
-
end
|
19
|
-
|
20
|
-
def singleton_class_send(method_name, *args, &block)
|
21
|
-
singleton_class_eval { send(method_name, *args, &block) }
|
22
|
-
end
|
23
|
-
|
24
|
-
def to_class
|
25
|
-
kind_of?(Module) ? self : singleton_class
|
26
|
-
end
|
27
|
-
|
28
|
-
alias_method :to_module, :to_class
|
29
|
-
|
30
|
-
def extend_with_flexible_arguments(*modules)
|
31
|
-
mods = modules.flatten
|
32
|
-
extend_without_flexible_arguments(*mods) unless mods.empty?
|
33
|
-
end
|
34
|
-
|
35
|
-
def tap
|
36
|
-
return super if block_given?
|
37
|
-
Functor.new { |method, *args| self.send(method, *args); self }
|
38
|
-
end
|
39
|
-
|
40
|
-
def try(method_name, *args, &block)
|
41
|
-
send(method_name, *args, &block) if respond_to?(method_name)
|
42
|
-
end
|
43
|
-
|
44
|
-
def receiver
|
45
|
-
self
|
46
|
-
end
|
47
|
-
|
48
|
-
alias_method :__instance_exec__, :instance_exec
|
49
|
-
|
50
|
-
def parse_arguments(args, *defaults)
|
51
|
-
args = args.dup
|
52
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
53
|
-
raise ArgumentError, "Too many arguments (#{args.size} for #{defaults.size})" if
|
54
|
-
args.size > defaults.size
|
55
|
-
defaults.drop(args.size).each { |default| args << default }
|
56
|
-
args << options
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class Object #:nodoc:
|
63
|
-
include Kinda::Core::ObjectExtension
|
64
|
-
end
|
data/lib/core/this.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
module Kinda
|
2
|
-
module Core
|
3
|
-
module This
|
4
|
-
module ProcExtension
|
5
|
-
def call_with_this(this, *args, &block)
|
6
|
-
binding_self = binding.eval('self')
|
7
|
-
binding_self.push_this(this)
|
8
|
-
call(*args, &block)
|
9
|
-
ensure
|
10
|
-
binding_self.pop_this
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
###
|
15
|
-
|
16
|
-
def call_with_this(proc, *args, &block)
|
17
|
-
return unless proc
|
18
|
-
binding_self = proc.binding.eval('self')
|
19
|
-
raise "Object #{binding_self.inspect} doesn't respond to Kinda::Core::This methods " +
|
20
|
-
"(proc=#{proc.inspect})" unless binding_self.respond_to?(:push_this)
|
21
|
-
begin
|
22
|
-
binding_self.push_this(self)
|
23
|
-
proc.call(*args, &block)
|
24
|
-
ensure
|
25
|
-
binding_self.pop_this
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def push_this(object)
|
30
|
-
(@these ||= []).push(object)
|
31
|
-
end
|
32
|
-
|
33
|
-
def pop_this
|
34
|
-
@these.pop if @these
|
35
|
-
end
|
36
|
-
|
37
|
-
def this
|
38
|
-
(@these && @these.last) || self
|
39
|
-
end
|
40
|
-
|
41
|
-
def this_eval(&block)
|
42
|
-
this.instance_eval(&block)
|
43
|
-
end
|
44
|
-
|
45
|
-
attr_reader :contextual_methods
|
46
|
-
|
47
|
-
def contextual_method(*methods)
|
48
|
-
methods.each do |method|
|
49
|
-
(@contextual_methods ||= []) << method.to_sym
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def contextual_method?(method)
|
54
|
-
to_class.self_and_ancestors.each do |ancestor|
|
55
|
-
return true if ancestor.contextual_methods &&
|
56
|
-
ancestor.contextual_methods.include?(method.to_sym)
|
57
|
-
end
|
58
|
-
false
|
59
|
-
end
|
60
|
-
|
61
|
-
def method_missing(method_name, *args, &block)
|
62
|
-
if this != self && this.contextual_method?(method_name)
|
63
|
-
this.send(method_name, *args, &block)
|
64
|
-
else
|
65
|
-
super
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
class Object #:nodoc:
|
73
|
-
include Kinda::Core::This
|
74
|
-
end
|
75
|
-
|
76
|
-
class Proc #:nodoc:
|
77
|
-
include Kinda::Core::This::ProcExtension
|
78
|
-
end
|
data/lib/kinda-core.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'core')
|
data/test/__all__.rb
DELETED
data/test/accessor_test.rb
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby19
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
|
6
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')).uniq!
|
7
|
-
require 'kinda-core'
|
8
|
-
|
9
|
-
class AccessorTest < Test::Unit::TestCase
|
10
|
-
def setup
|
11
|
-
@human_class = Class.new do
|
12
|
-
include Kinda::Core
|
13
|
-
end
|
14
|
-
@human = @human_class.new
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_attribute_defined_at_class_level
|
18
|
-
@human_class.class_eval do
|
19
|
-
attr_accessor :name
|
20
|
-
end
|
21
|
-
assert_nil @human.name
|
22
|
-
@human.name = 'Dave'
|
23
|
-
assert_equal 'Dave', @human.name
|
24
|
-
@human.name 'Fred'
|
25
|
-
assert_equal 'Fred', @human.name
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_attribute_defined_at_instance_level
|
29
|
-
@human.attr_accessor :name
|
30
|
-
assert_nil @human.name
|
31
|
-
@human.name = 'Dave'
|
32
|
-
assert_equal 'Dave', @human.name
|
33
|
-
@human.name 'Fred'
|
34
|
-
assert_equal 'Fred', @human.name
|
35
|
-
@other_human = @human_class.new
|
36
|
-
assert_raise NoMethodError do
|
37
|
-
@other_human.name
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_attribute_with_block_defined_at_class_level
|
42
|
-
@human_class.class_eval do
|
43
|
-
attr_reader :name do |capitalize=false|
|
44
|
-
capitalize ? @the_name.capitalize : @the_name
|
45
|
-
end
|
46
|
-
attr_writer :name do |value|
|
47
|
-
@the_name = value
|
48
|
-
end
|
49
|
-
end
|
50
|
-
assert_equal nil, @human.name
|
51
|
-
@human.name = 'Dave'
|
52
|
-
assert_equal 'Dave', @human.name
|
53
|
-
@human.name = 'fred'
|
54
|
-
assert_equal 'Fred', @human.name(true)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_attribute_with_filter_defined_at_class_level
|
58
|
-
@human_class.class_eval do
|
59
|
-
attr_accessor :nickname
|
60
|
-
|
61
|
-
attr_reader_with_filter :name do |value|
|
62
|
-
value || nickname || 'Mike'
|
63
|
-
end
|
64
|
-
attr_writer_with_filter :name do |value|
|
65
|
-
value.capitalize
|
66
|
-
end
|
67
|
-
end
|
68
|
-
assert_equal 'Mike', @human.name
|
69
|
-
@human.nickname = 'Mikey'
|
70
|
-
assert_equal 'Mikey', @human.name
|
71
|
-
@human.name = 'dave'
|
72
|
-
assert_equal 'Dave', @human.name
|
73
|
-
@human.name 'FRED'
|
74
|
-
assert_equal 'Fred', @human.name
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_attribute_redirection
|
78
|
-
@human.attr_accessor :name => :@the_name
|
79
|
-
assert_nil @human.name
|
80
|
-
@human.name = 'Dave'
|
81
|
-
assert_equal 'Dave', @human.name
|
82
|
-
assert_equal 'Dave', @human.instance_variable_get(:@the_name)
|
83
|
-
@human.name = 'Fred'
|
84
|
-
assert_equal 'Fred', @human.name
|
85
|
-
@human.attr_accessor :last_name => :name
|
86
|
-
assert_equal 'Fred', @human.last_name
|
87
|
-
@human.last_name = 'Mike'
|
88
|
-
assert_equal 'Mike', @human.last_name
|
89
|
-
assert_equal 'Mike', @human.name
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_attribute_delegation
|
93
|
-
@child = @human_class.new
|
94
|
-
@father = @human_class.new
|
95
|
-
@child.attr_accessor :father
|
96
|
-
@child.father = @father
|
97
|
-
assert_equal @father, @child.father
|
98
|
-
@father.attr_accessor :name
|
99
|
-
@father.name = 'Dave'
|
100
|
-
@child.attr_accessor :name => [:father, :name]
|
101
|
-
assert_equal 'Dave', @child.name
|
102
|
-
@child.name = 'Fred'
|
103
|
-
assert_equal 'Fred', @child.name
|
104
|
-
assert_equal 'Fred', @father.name
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_attribute_double_delegation
|
108
|
-
@child = @human_class.new
|
109
|
-
@mother = @human_class.new
|
110
|
-
@husband = @human_class.new
|
111
|
-
@child.attr_accessor :mother
|
112
|
-
@child.mother = @mother
|
113
|
-
@mother.attr_accessor :husband
|
114
|
-
@mother.husband = @husband
|
115
|
-
assert_equal @husband, @child.mother.husband
|
116
|
-
@husband.attr_accessor :name
|
117
|
-
@husband.name = 'Dave'
|
118
|
-
@child.attr_accessor :name => [:mother, :husband, :name]
|
119
|
-
assert_equal 'Dave', @child.name
|
120
|
-
@child.name = 'Fred'
|
121
|
-
assert_equal 'Fred', @child.name
|
122
|
-
assert_equal 'Fred', @husband.name
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_attribute_with_default
|
126
|
-
@human.attr_accessor_with_default :name, 'Bart'
|
127
|
-
assert_equal 'Bart', @human.name
|
128
|
-
@human.name = 'Dave'
|
129
|
-
assert_equal 'Dave', @human.name
|
130
|
-
end
|
131
|
-
end
|
data/test/forwardable_test.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby19
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
|
6
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')).uniq!
|
7
|
-
require 'kinda-core'
|
8
|
-
|
9
|
-
class ForwardableTest < Test::Unit::TestCase
|
10
|
-
def setup
|
11
|
-
@human_class = Class.new do
|
12
|
-
include Kinda::Core
|
13
|
-
end
|
14
|
-
@human = @human_class.new
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_delegate_attribute
|
18
|
-
@child = @human_class.new
|
19
|
-
@father = @human_class.new
|
20
|
-
@child.attr_accessor :father
|
21
|
-
@child.father = @father
|
22
|
-
assert_equal @father, @child.father
|
23
|
-
@father.attr_accessor :name
|
24
|
-
@father.name = 'Dave'
|
25
|
-
@child.delegate_attr :name => :father
|
26
|
-
assert_equal 'Dave', @child.name
|
27
|
-
@child.name = 'Fred'
|
28
|
-
assert_equal 'Fred', @child.name
|
29
|
-
assert_equal 'Fred', @father.name
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_delegate_attribute_with_filter
|
33
|
-
@child = @human_class.new
|
34
|
-
@father = @human_class.new
|
35
|
-
@child.attr_accessor :father
|
36
|
-
@child.father = @father
|
37
|
-
assert_equal @father, @child.father
|
38
|
-
@father.attr_accessor :name
|
39
|
-
@father.name = 'Dave'
|
40
|
-
@child.delegate_attr_reader_with_filter :name => :father do |value|
|
41
|
-
value + ' junior'
|
42
|
-
end
|
43
|
-
assert_equal 'Dave junior', @child.name
|
44
|
-
@child.delegate_attr_writer_with_filter :name => :father do |value|
|
45
|
-
value.capitalize
|
46
|
-
end
|
47
|
-
@child.name = 'fred'
|
48
|
-
assert_equal 'Fred junior', @child.name
|
49
|
-
assert_equal 'Fred', @father.name
|
50
|
-
end
|
51
|
-
end
|
data/test/module_test.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby19
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
|
6
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')).uniq!
|
7
|
-
require 'kinda-core'
|
8
|
-
|
9
|
-
class ModuleTest < Test::Unit::TestCase
|
10
|
-
def meth
|
11
|
-
'meth'
|
12
|
-
end
|
13
|
-
|
14
|
-
def meth_with_upcase
|
15
|
-
meth_without_upcase.upcase
|
16
|
-
end
|
17
|
-
|
18
|
-
alias_method_chain :meth, :upcase
|
19
|
-
|
20
|
-
def test_alias_method_chain
|
21
|
-
assert_equal 'METH', meth
|
22
|
-
end
|
23
|
-
|
24
|
-
$meth2 = []
|
25
|
-
|
26
|
-
module A
|
27
|
-
module ClassMethods1
|
28
|
-
def meth1
|
29
|
-
'meth1'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
module ClassMethods2
|
34
|
-
def meth2
|
35
|
-
$meth2 << 'ClassMethods2.meth2'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
inheritable_extend ClassMethods1, ClassMethods2
|
40
|
-
end
|
41
|
-
|
42
|
-
module B
|
43
|
-
include A
|
44
|
-
|
45
|
-
ClassMethods3 = inheritable_extend do
|
46
|
-
$meth1 = meth1
|
47
|
-
|
48
|
-
def meth3
|
49
|
-
'meth3'
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
module ClassMethods4
|
54
|
-
def meth2
|
55
|
-
super
|
56
|
-
$meth2 << 'ClassMethods4.meth2'
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
inheritable_extend ClassMethods4
|
61
|
-
end
|
62
|
-
|
63
|
-
class X
|
64
|
-
include B
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_container
|
68
|
-
assert_equal ModuleTest::A, ModuleTest::A::ClassMethods1.container
|
69
|
-
assert_equal ModuleTest::B, ModuleTest::B::ClassMethods3.container
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_extensions
|
73
|
-
assert_equal [ModuleTest::B::ClassMethods4, ModuleTest::B::ClassMethods3,
|
74
|
-
ModuleTest::A::ClassMethods2, ModuleTest::A::ClassMethods1], X.extensions
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_inheritable_extend
|
78
|
-
assert_equal 'meth1', $meth1
|
79
|
-
X.meth2
|
80
|
-
assert_equal ["ClassMethods2.meth2", "ClassMethods4.meth2"], $meth2
|
81
|
-
assert_equal 'meth1', X.meth1
|
82
|
-
assert_equal 'meth3', X.meth3
|
83
|
-
end
|
84
|
-
end
|
data/test/object_test.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby19
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
|
6
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')).uniq!
|
7
|
-
require 'kinda-core'
|
8
|
-
|
9
|
-
class ObjectTest < Test::Unit::TestCase
|
10
|
-
def test_tap
|
11
|
-
assert_equal 'Hello', 'Hello'.tap { |str| assert_equal 'HELLO', str.upcase }
|
12
|
-
assert_equal 'Hello', 'Hello'.tap.upcase
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_try
|
16
|
-
assert_equal nil, 'Hello'.try(:undefined)
|
17
|
-
assert_equal 'HELLO', 'Hello'.try(:upcase)
|
18
|
-
assert_equal 'hello', 'Hello'.try(:upcase).try(:downcase)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_parse_arguments
|
22
|
-
assert_equal [1, 2, {}], parse_arguments([], 1, 2)
|
23
|
-
assert_equal [3, 4, {}], parse_arguments([3, 4], 1, 2)
|
24
|
-
assert_raise(ArgumentError) { parse_arguments([3, 4, 5], 1, 2) }
|
25
|
-
assert_equal [1, 2, {:a => 'c', :b => 'd'}], parse_arguments([:a => 'c', :b => 'd'], 1, 2)
|
26
|
-
assert_equal [3, 2, {:a => 'c', :b => 'd'}], parse_arguments([3, :a => 'c', :b => 'd'], 1, 2)
|
27
|
-
end
|
28
|
-
end
|