coactive 0.2.2 → 0.4.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/.github/workflows/ci.yml +14 -2
- data/CHANGELOG.md +8 -0
- data/bin/console +2 -2
- data/gemfiles/rails70.gemfile +1 -1
- data/lib/coactive/coactants.rb +33 -0
- data/lib/coactive/coaction.rb +9 -0
- data/lib/coactive/coactions.rb +23 -0
- data/lib/coactive/coactor.rb +4 -4
- data/lib/coactive/context.rb +4 -5
- data/lib/coactive/contexts/inspect.rb +39 -0
- data/lib/coactive/loader.rb +21 -5
- data/lib/coactive/lookups/base.rb +1 -0
- data/lib/coactive/lookups/name.rb +2 -5
- data/lib/coactive/lookups/object.rb +3 -3
- data/lib/coactive/railtie.rb +1 -0
- data/lib/coactive/version.rb +1 -1
- metadata +7 -6
- data/lib/coactive/coactors/coactants.rb +0 -35
- data/lib/coactive/coactors/coaction.rb +0 -11
- data/lib/coactive/coactors/coactions.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55895695a2ad27b38fd2ca9f1d8c38b1135975cd3e3ff41fe3f7e53b4564c5ba
|
4
|
+
data.tar.gz: e51d7e8e74748cd29284e9795d199c7fe9b2737ecdc79f57412632114c3bdee8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92e2fbe3d500452f8b9584174e2f34c9383b03e12b2eb70d58324caf5ba48b793bb86d6f8153f5a54c454141e1dd223825d1d3fd1ad1c6b8f0c375a5a2c40a8d
|
7
|
+
data.tar.gz: c9c6da5d6f236221af0f20927eeff9c4846a3ef5cb3940c481a0409842d98186b778b772f777589743d525b2f0914206ef41206530a3043e91098663e937fafe
|
data/.github/workflows/ci.yml
CHANGED
@@ -8,7 +8,7 @@ jobs:
|
|
8
8
|
strategy:
|
9
9
|
fail-fast: false
|
10
10
|
matrix:
|
11
|
-
ruby: [2.3, 2.4, 2.5, 2.6, 2.7, '3.0']
|
11
|
+
ruby: [2.3, 2.4, 2.5, 2.6, 2.7, '3.0', 3.1, 3.2]
|
12
12
|
gemfile: ['rails50', 'rails51', 'rails52', 'rails60', 'rails61', 'rails70']
|
13
13
|
exclude:
|
14
14
|
- ruby: 2.3
|
@@ -33,6 +33,18 @@ jobs:
|
|
33
33
|
gemfile: rails51
|
34
34
|
- ruby: 3.0
|
35
35
|
gemfile: rails52
|
36
|
+
- ruby: 3.1
|
37
|
+
gemfile: rails50
|
38
|
+
- ruby: 3.1
|
39
|
+
gemfile: rails51
|
40
|
+
- ruby: 3.1
|
41
|
+
gemfile: rails52
|
42
|
+
- ruby: 3.2
|
43
|
+
gemfile: rails50
|
44
|
+
- ruby: 3.2
|
45
|
+
gemfile: rails51
|
46
|
+
- ruby: 3.2
|
47
|
+
gemfile: rails52
|
36
48
|
|
37
49
|
name: ruby ${{ matrix.ruby }}, ${{ matrix.gemfile }}
|
38
50
|
|
@@ -40,7 +52,7 @@ jobs:
|
|
40
52
|
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
41
53
|
|
42
54
|
steps:
|
43
|
-
- uses: actions/checkout@
|
55
|
+
- uses: actions/checkout@v3
|
44
56
|
- uses: ruby/setup-ruby@v1
|
45
57
|
with:
|
46
58
|
ruby-version: ${{ matrix.ruby }}
|
data/CHANGELOG.md
CHANGED
data/bin/console
CHANGED
data/gemfiles/rails70.gemfile
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Coactive
|
4
|
+
module Coactants
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
class_attribute :_coactants
|
9
|
+
self._coactants = []
|
10
|
+
end
|
11
|
+
|
12
|
+
class_methods do
|
13
|
+
def coact(*coactants, **options, &block)
|
14
|
+
if block
|
15
|
+
self._coactants = _coactants + [block]
|
16
|
+
elsif options[:before]
|
17
|
+
index = self._coactants.index { |coactant| coactant == options[:before] }
|
18
|
+
self._coactants = self._coactants.insert(index, *coactants)
|
19
|
+
else
|
20
|
+
self._coactants = _coactants + coactants
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def coactants
|
25
|
+
self._coactants
|
26
|
+
end
|
27
|
+
|
28
|
+
def clear_coactants
|
29
|
+
self._coactants = []
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'coaction'
|
4
|
+
|
5
|
+
module Coactive
|
6
|
+
module Coactions
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
class_attribute :coactions_map
|
11
|
+
self.coactions_map = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
class_methods do
|
15
|
+
def coaction(*names, **options)
|
16
|
+
names.each do |name|
|
17
|
+
coactions = coactions_map[name].to_a + [Coaction.new(self, name, options)]
|
18
|
+
coactions_map[name] = coactions.sort_by.with_index { |coaction, i| [coaction.priority, i] }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/coactive/coactor.rb
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
require_relative 'loader'
|
4
4
|
require_relative 'lookup'
|
5
|
-
require_relative '
|
6
|
-
require_relative '
|
5
|
+
require_relative 'coactants'
|
6
|
+
require_relative 'coactions'
|
7
7
|
|
8
8
|
module Coactive
|
9
9
|
module Coactor
|
10
10
|
extend ActiveSupport::Concern
|
11
|
-
include
|
12
|
-
include
|
11
|
+
include Coactants
|
12
|
+
include Coactions
|
13
13
|
|
14
14
|
def coactors
|
15
15
|
self.class._coactants.map do |coactant|
|
data/lib/coactive/context.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'contexts/inspect'
|
4
|
+
|
3
5
|
module Coactive
|
4
6
|
class Context
|
7
|
+
include Contexts::Inspect
|
8
|
+
|
5
9
|
attr_reader :_data
|
6
10
|
|
7
11
|
def initialize(data = {}, &block)
|
@@ -25,11 +29,6 @@ module Coactive
|
|
25
29
|
@_data
|
26
30
|
end
|
27
31
|
|
28
|
-
def to_s
|
29
|
-
attrs = @_data.map { |k, v| "#{k}=#{v.to_s.truncate(300)}" }.join(', ')
|
30
|
-
"#<#{self.class} #{attrs}>"
|
31
|
-
end
|
32
|
-
|
33
32
|
def define_accessors!(keys)
|
34
33
|
Array(keys).each do |key|
|
35
34
|
define_singleton_method key do
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Coactive
|
4
|
+
module Contexts
|
5
|
+
module Inspect
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
def to_s
|
9
|
+
"#<#{self.class} #{self.class.inspect(@_data)}>"
|
10
|
+
end
|
11
|
+
|
12
|
+
class_methods do
|
13
|
+
def inspect(data)
|
14
|
+
data.map { |k, v| "#{k}=#{Coactive::Contexts::Inspect.call(v)}" }.join(', ')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class << self
|
19
|
+
class_attribute :max_num, :max_length
|
20
|
+
self.max_num = 5
|
21
|
+
self.max_length = 300
|
22
|
+
|
23
|
+
def call(data)
|
24
|
+
if data.is_a?(Array)
|
25
|
+
str = data.take(max_num).map { |v| call(v) }.join(', ')
|
26
|
+
str += '...' if data.size > max_num
|
27
|
+
"[#{str}]"
|
28
|
+
elsif data.is_a?(Hash)
|
29
|
+
str = data.take(max_num).map { |k, v| "#{k}: #{call(v)}" }.join(', ')
|
30
|
+
str += '...' if data.size > max_num
|
31
|
+
"{#{str}}"
|
32
|
+
else
|
33
|
+
data.to_s.truncate(max_length)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/coactive/loader.rb
CHANGED
@@ -3,18 +3,34 @@
|
|
3
3
|
module Coactive
|
4
4
|
module Loader
|
5
5
|
class << self
|
6
|
+
class_attribute :loaded
|
7
|
+
self.loaded = {}
|
8
|
+
|
6
9
|
def call(paths)
|
7
10
|
return unless defined?(Rails)
|
8
|
-
return if Rails.application.config.eager_load
|
9
|
-
|
11
|
+
return if Rails.application.config.eager_load || paths.blank?
|
12
|
+
|
13
|
+
Array.wrap(paths).each do |path|
|
14
|
+
unless loaded[path]
|
15
|
+
load(path)
|
16
|
+
loaded[path] = true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
10
22
|
|
11
|
-
|
12
|
-
|
13
|
-
Dir["#{engine.root}
|
23
|
+
def load(path)
|
24
|
+
rails_engines.each do |engine|
|
25
|
+
Dir["#{engine.root}/#{path}/**/*.rb"].each do |file|
|
14
26
|
require_dependency file
|
15
27
|
end
|
16
28
|
end
|
17
29
|
end
|
30
|
+
|
31
|
+
def rails_engines
|
32
|
+
[Rails] + Rails::Engine.subclasses.map(&:instance)
|
33
|
+
end
|
18
34
|
end
|
19
35
|
end
|
20
36
|
end
|
@@ -11,14 +11,11 @@ module Coactive
|
|
11
11
|
private
|
12
12
|
|
13
13
|
def load_files
|
14
|
-
Coactive::Loader.call(@
|
14
|
+
Coactive::Loader.call(@config.load_paths)
|
15
15
|
end
|
16
16
|
|
17
17
|
def lookup
|
18
|
-
@
|
19
|
-
coaction = coactor.coactions.detect { |coaction| coaction.name == @coactant }
|
20
|
-
hash[[coaction.priority || 1 << 63, i]] = coactor if coaction
|
21
|
-
end.sort.map { |x| x[1] }
|
18
|
+
@config.base_class.coactions_map[@coactant].to_a.map(&:coactor)
|
22
19
|
end
|
23
20
|
|
24
21
|
class << self
|
@@ -14,13 +14,13 @@ module Coactive
|
|
14
14
|
|
15
15
|
if coactant.name.present? && (coactor = resolve(coactant))
|
16
16
|
coactor
|
17
|
-
elsif @
|
17
|
+
elsif @config.lookup_superclass_for_object && coactant.superclass
|
18
18
|
lookup(coactant.superclass)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def terminate?(coactant)
|
23
|
-
coactant.name.to_s.in?(@
|
23
|
+
coactant.name.to_s.in?(@config.lookup_superclass_until)
|
24
24
|
end
|
25
25
|
|
26
26
|
def resolve(coactant)
|
@@ -30,7 +30,7 @@ module Coactive
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def resolve_name(coactant)
|
33
|
-
suffix = @
|
33
|
+
suffix = @config.class_suffix
|
34
34
|
namespace = @klass.name.to_s.sub(/#{suffix}$/, '').to_s
|
35
35
|
[namespace, "#{coactant.name}#{suffix}"].join('::')
|
36
36
|
end
|
data/lib/coactive/railtie.rb
CHANGED
data/lib/coactive/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coactive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshikazu Kaneta
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -120,13 +120,14 @@ files:
|
|
120
120
|
- gemfiles/rails70.gemfile
|
121
121
|
- lib/coactive.rb
|
122
122
|
- lib/coactive/base.rb
|
123
|
+
- lib/coactive/coactants.rb
|
124
|
+
- lib/coactive/coaction.rb
|
125
|
+
- lib/coactive/coactions.rb
|
123
126
|
- lib/coactive/coactor.rb
|
124
|
-
- lib/coactive/coactors/coactants.rb
|
125
|
-
- lib/coactive/coactors/coaction.rb
|
126
|
-
- lib/coactive/coactors/coactions.rb
|
127
127
|
- lib/coactive/config.rb
|
128
128
|
- lib/coactive/configure.rb
|
129
129
|
- lib/coactive/context.rb
|
130
|
+
- lib/coactive/contexts/inspect.rb
|
130
131
|
- lib/coactive/contextualizer.rb
|
131
132
|
- lib/coactive/errors.rb
|
132
133
|
- lib/coactive/initializer.rb
|
@@ -158,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
159
|
- !ruby/object:Gem::Version
|
159
160
|
version: '0'
|
160
161
|
requirements: []
|
161
|
-
rubygems_version: 3.
|
162
|
+
rubygems_version: 3.3.3
|
162
163
|
signing_key:
|
163
164
|
specification_version: 4
|
164
165
|
summary: Make classes coactive
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Coactive
|
4
|
-
module Coactors
|
5
|
-
module Coactants
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
class_attribute :_coactants
|
10
|
-
self._coactants = []
|
11
|
-
end
|
12
|
-
|
13
|
-
class_methods do
|
14
|
-
def coact(*coactants, **options, &block)
|
15
|
-
if block
|
16
|
-
self._coactants = _coactants + [block]
|
17
|
-
elsif options[:before]
|
18
|
-
index = self._coactants.index { |coactant| coactant == options[:before] }
|
19
|
-
self._coactants = self._coactants.insert(index, *coactants)
|
20
|
-
else
|
21
|
-
self._coactants = _coactants + coactants
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def coactants
|
26
|
-
self._coactants
|
27
|
-
end
|
28
|
-
|
29
|
-
def clear_coactants
|
30
|
-
self._coactants = []
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'coaction'
|
4
|
-
|
5
|
-
module Coactive
|
6
|
-
module Coactors
|
7
|
-
module Coactions
|
8
|
-
extend ActiveSupport::Concern
|
9
|
-
|
10
|
-
included do
|
11
|
-
class_attribute :_coactions
|
12
|
-
self._coactions = []
|
13
|
-
end
|
14
|
-
|
15
|
-
class_methods do
|
16
|
-
def coaction(*names, **options)
|
17
|
-
self._coactions = _coactions + names.map { |name| Coaction.new(name, options) }
|
18
|
-
end
|
19
|
-
|
20
|
-
def coactions
|
21
|
-
self._coactions
|
22
|
-
end
|
23
|
-
|
24
|
-
def clear_coactions
|
25
|
-
self._coactions = []
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|