core-define 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 903f1b71df929a6157e1054c3e463ba044ef7054f590db1dd40054adf7db38d5
4
- data.tar.gz: '0877ed46581853d91c92c3effb70948d97d3a0d1e3e05885d8af023c86b16dc7'
3
+ metadata.gz: 13325d7220b750f363a6b24d51f7dc27ef39b24d9f255fd230cb7f575f5005fd
4
+ data.tar.gz: 303f756970914ef75ee2a770af2f0b1e0a26a12d6d1bd331eae07d8426c3851f
5
5
  SHA512:
6
- metadata.gz: cd54d0a1d45f34377bac090a42717a984988b1c5f16f5802595d1978e54c2726f09834b20c61932542dd286c21ea4921ae5cd2f7f855930b3ad9be40389ba1c4
7
- data.tar.gz: 4c4bcbb32ff5b31eb28574028a87f3f0dc76015da6bc608383a2d59df7971c1e6d0eec4b089b2a952a66f5b6ff5d90153b320aaeedac98f335c97d0b43ba6488
6
+ metadata.gz: 4a28352926e10438754517f9125c8f319c6accd5ea0bff85fcd343259c3cb7d0ec91558f8377d37e83bb0bea6a4afd4ae7296084b222818382df8bb16d4e2763
7
+ data.tar.gz: a6fdc9b05cc1c2b7444db372b8c6f2d8928b5180790690489e26ea3e6e52074c4dbde1e6db151ea61bf72223dc08968aec095e9cfee944c1e4719535dd86c391
data/CHANGELOG.md CHANGED
@@ -1,25 +1,33 @@
1
- ## [v0.1.2](https://github.com/metabahn/corerb/releases/tag/2022-01-06)
1
+ ## [v0.2.0](https://github.com/bryanp/corerb/releases/tag/2023-12-24)
2
+
3
+ *released on 2023-12-24*
4
+
5
+ * `dep` [#143](https://github.com/bryanp/corerb/pull/143) Deprecate `Is::*` and `Refine::*` namespaces ([bryanp](https://github.com/bryanp))
6
+ * `dep` [#145](https://github.com/bryanp/corerb/pull/145) Remove `core.define` event ([bryanp](https://github.com/bryanp))
7
+ * `dep` [#135](https://github.com/bryanp/corerb/pull/135) Remove Ruby 2 support ([bryanp](https://github.com/bryanp))
8
+
9
+ ## [v0.1.2](https://github.com/bryanp/corerb/releases/tag/2022-01-06)
2
10
 
3
11
  *released on 2022-01-06*
4
12
 
5
- * `fix` [#113](https://github.com/metabahn/corerb/pull/113) Improve camelization of complex strings ([bryanp](https://github.com/bryanp))
13
+ * `fix` [#113](https://github.com/bryanp/corerb/pull/113) Improve camelization of complex strings ([bryanp](https://github.com/bryanp))
6
14
 
7
- ## [v0.1.1](https://github.com/metabahn/corerb/releases/tag/2021-11-23.1)
15
+ ## [v0.1.1](https://github.com/bryanp/corerb/releases/tag/2021-11-23.1)
8
16
 
9
17
  *released on 2021-11-23*
10
18
 
11
- * `chg` [#109](https://github.com/metabahn/corerb/pull/109) Prefer `__send__` to `send` ([bryanp](https://github.com/bryanp))
19
+ * `chg` [#109](https://github.com/bryanp/corerb/pull/109) Prefer `__send__` to `send` ([bryanp](https://github.com/bryanp))
12
20
 
13
- ## [v0.1.0](https://github.com/metabahn/corerb/releases/tag/2021-11-02)
21
+ ## [v0.1.0](https://github.com/bryanp/corerb/releases/tag/2021-11-02)
14
22
 
15
23
  *released on 2021-11-02*
16
24
 
17
- * `add` [#93](https://github.com/metabahn/corerb/pull/93) Allow locations to be passed to defined objects ([bryanp](https://github.com/bryanp))
25
+ * `add` [#93](https://github.com/bryanp/corerb/pull/93) Allow locations to be passed to defined objects ([bryanp](https://github.com/bryanp))
18
26
 
19
- ## [v0.0.0](https://github.com/metabahn/corerb/releases/tag/2021-10-25)
27
+ ## [v0.0.0](https://github.com/bryanp/corerb/releases/tag/2021-10-25)
20
28
 
21
29
  *released on 2021-10-25*
22
30
 
23
- * `add` [#91](https://github.com/metabahn/corerb/pull/91) Initial implementation of the core-define gem ([bryanp](https://github.com/bryanp))
31
+ * `add` [#91](https://github.com/bryanp/corerb/pull/91) Initial implementation of the core-define gem ([bryanp](https://github.com/bryanp))
24
32
 
25
33
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Core
4
4
  module Define
5
- VERSION = "0.1.2"
5
+ VERSION = "0.2.0"
6
6
 
7
7
  # [public]
8
8
  #
data/lib/core/define.rb CHANGED
@@ -1,7 +1,128 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "core/copy"
4
+ require "core/extension"
5
+ require "core/state"
6
+
3
7
  module Core
8
+ # [public]
9
+ #
4
10
  module Define
11
+ require_relative "define/definition"
12
+ require_relative "define/location"
13
+ require_relative "define/utils"
5
14
  require_relative "define/version"
15
+
16
+ extend Core::Extension
17
+
18
+ using Core::Copy
19
+
20
+ extends :definition do
21
+ # [public] Defines an object by `name`, within `namespace`.
22
+ #
23
+ # Options passed as keyword arguments are defined as state on the new object.
24
+ #
25
+ # The `__location__` keyword argument is considered part of the public api and must be an instance of
26
+ # `Core::Define::Location`. It's passed using an internal naming convention to avoid possible collisions with
27
+ # other passed state. If not given, the object's location is based on `caller`.
28
+ #
29
+ def define(*namespace, name, __location__: nil, **kwargs, &block)
30
+ scope = if namespace.any?
31
+ define_namespace(*namespace)
32
+ else
33
+ Object
34
+ end
35
+
36
+ constant = Core::Define::Utils.camelize(name)
37
+
38
+ if scope.const_defined?(constant)
39
+ defined = scope.const_get(constant)
40
+ else
41
+ location = if __location__
42
+ unless __location__.respond_to?(:path) && __location__.respond_to?(:line)
43
+ raise ArgumentError, "expected location to respond to `path` and `line`"
44
+ end
45
+
46
+ __location__
47
+ else
48
+ path, line = caller(1..1).first.split(":", 3)
49
+ Core::Define::Location.new(path: path, line: line)
50
+ end
51
+
52
+ # Create the right kind of object for `self`.
53
+ #
54
+ defined = case self
55
+ when Class
56
+ Class.new(self)
57
+ when Module
58
+ copy
59
+ end
60
+
61
+ # Make the object available under the given name.
62
+ #
63
+ scope.const_set(constant, defined)
64
+
65
+ # Define the new object to be stateful.
66
+ #
67
+ definition_block = proc do
68
+ unless ancestors.include?(Core::State)
69
+ include Core::State
70
+ end
71
+
72
+ # Create an object holding information about the object's definition.
73
+ #
74
+ definition = Core::Define::Definition.new(*namespace, name, location: location)
75
+ definition.freeze
76
+
77
+ state :definition, default: definition
78
+ end
79
+
80
+ case defined
81
+ when Class
82
+ defined.class_eval(&definition_block)
83
+ when Module
84
+ defined.module_eval(&definition_block)
85
+ end
86
+ end
87
+
88
+ # Define given state on the object.
89
+ #
90
+ kwargs.each_pair do |key, value|
91
+ defined.state key, default: value
92
+ end
93
+
94
+ # Evaluate the given block on the object, extending it with any custom behavior.
95
+ #
96
+ if block
97
+ case defined
98
+ when Class
99
+ defined.class_eval(&block)
100
+ when Module
101
+ defined.module_eval(&block)
102
+ end
103
+ end
104
+
105
+ defined
106
+ end
107
+
108
+ # [public]
109
+ #
110
+ def define_namespace(*namespace)
111
+ scope = Object
112
+
113
+ namespace.each do |part|
114
+ constant = Core::Define::Utils.camelize(part)
115
+
116
+ scope = if scope.const_defined?(constant)
117
+ scope.const_get(constant)
118
+ else
119
+ new_scope = Module.new
120
+ scope.const_set(constant, new_scope)
121
+ end
122
+ end
123
+
124
+ scope
125
+ end
126
+ end
6
127
  end
7
128
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: core-define
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-07 00:00:00.000000000 Z
11
+ date: 2023-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: core-copy
@@ -16,58 +16,44 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.1'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.1'
27
- - !ruby/object:Gem::Dependency
28
- name: core-event
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0.0'
19
+ version: '0.3'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '0.0'
26
+ version: '0.3'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: core-extension
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '0.3'
33
+ version: '0.5'
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '0.3'
40
+ version: '0.5'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: core-state
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '0.1'
47
+ version: '0.2'
62
48
  type: :runtime
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '0.1'
54
+ version: '0.2'
69
55
  description: Easily define isolated objects.
70
- email: bryan@metabahn.com
56
+ email: bryan@bryanp.org
71
57
  executables: []
72
58
  extensions: []
73
59
  extra_rdoc_files: []
@@ -79,8 +65,7 @@ files:
79
65
  - lib/core/define/location.rb
80
66
  - lib/core/define/utils.rb
81
67
  - lib/core/define/version.rb
82
- - lib/is/definable.rb
83
- homepage: https://github.com/metabahn/corerb/
68
+ homepage: https://github.com/bryanp/corerb/
84
69
  licenses:
85
70
  - MPL-2.0
86
71
  metadata: {}
@@ -92,14 +77,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
77
  requirements:
93
78
  - - ">="
94
79
  - !ruby/object:Gem::Version
95
- version: '2.7'
80
+ version: '3.0'
96
81
  required_rubygems_version: !ruby/object:Gem::Requirement
97
82
  requirements:
98
83
  - - ">="
99
84
  - !ruby/object:Gem::Version
100
85
  version: '0'
101
86
  requirements: []
102
- rubygems_version: 3.2.22
87
+ rubygems_version: 3.5.1
103
88
  signing_key:
104
89
  specification_version: 4
105
90
  summary: Easily define isolated objects.
data/lib/is/definable.rb DELETED
@@ -1,134 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "is/eventable"
4
- require "is/extension"
5
-
6
- require "refine/object/copy"
7
-
8
- require_relative "../core/define/definition"
9
- require_relative "../core/define/location"
10
- require_relative "../core/define/utils"
11
-
12
- module Is
13
- # [public]
14
- #
15
- module Definable
16
- extend Is::Extension
17
-
18
- using Refine::Object::Copy
19
-
20
- applies do
21
- event "core.define"
22
- end
23
-
24
- extends :definition, dependencies: [Is::Eventable] do
25
- # [public] Defines an object by `name`, within `namespace`.
26
- #
27
- # Options passed as keyword arguments are defined as state on the new object.
28
- #
29
- # The `__location__` keyword argument is considered part of the public api and must be an instance of
30
- # `Core::Define::Location`. It's passed using an internal naming convention to avoid possible collisions with
31
- # other passed state. If not given, the object's location is based on `caller`.
32
- #
33
- def define(*namespace, name, __location__: nil, **kwargs, &block)
34
- scope = if namespace.any?
35
- define_namespace(*namespace)
36
- else
37
- Object
38
- end
39
-
40
- constant = Core::Define::Utils.camelize(name)
41
-
42
- if scope.const_defined?(constant)
43
- defined = scope.const_get(constant)
44
- else
45
- location = if __location__
46
- unless __location__.respond_to?(:path) && __location__.respond_to?(:line)
47
- raise ArgumentError, "expected location to respond to `path` and `line`"
48
- end
49
-
50
- __location__
51
- else
52
- path, line = caller(1..1).first.split(":", 3)
53
- Core::Define::Location.new(path: path, line: line)
54
- end
55
-
56
- performing "core.define" do
57
- # Create the right kind of object for `self`.
58
- #
59
- defined = case self
60
- when Class
61
- Class.new(self)
62
- when Module
63
- copy
64
- end
65
-
66
- # Make the object available under the given name.
67
- #
68
- scope.const_set(constant, defined)
69
-
70
- # Define the new object to be stateful.
71
- #
72
- definition_block = proc do
73
- unless ancestors.include?(Is::Stateful)
74
- include Is::Stateful
75
- end
76
-
77
- # Create an object holding information about the object's definition.
78
- #
79
- definition = Core::Define::Definition.new(*namespace, name, location: location)
80
- definition.freeze
81
-
82
- state :definition, default: definition
83
- end
84
-
85
- case defined
86
- when Class
87
- defined.class_eval(&definition_block)
88
- when Module
89
- defined.module_eval(&definition_block)
90
- end
91
- end
92
- end
93
-
94
- # Define given state on the object.
95
- #
96
- kwargs.each_pair do |key, value|
97
- defined.state key, default: value
98
- end
99
-
100
- # Evaluate the given block on the object, extending it with any custom behavior.
101
- #
102
- if block
103
- case defined
104
- when Class
105
- defined.class_eval(&block)
106
- when Module
107
- defined.module_eval(&block)
108
- end
109
- end
110
-
111
- defined
112
- end
113
-
114
- # [public]
115
- #
116
- def define_namespace(*namespace)
117
- scope = Object
118
-
119
- namespace.each do |part|
120
- constant = Core::Define::Utils.camelize(part)
121
-
122
- scope = if scope.const_defined?(constant)
123
- scope.const_get(constant)
124
- else
125
- new_scope = Module.new
126
- scope.const_set(constant, new_scope)
127
- end
128
- end
129
-
130
- scope
131
- end
132
- end
133
- end
134
- end