coactive 0.4.1 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/gemfiles/rails50.gemfile +1 -0
- data/gemfiles/rails51.gemfile +1 -0
- data/gemfiles/rails52.gemfile +1 -0
- data/lib/coactive/coaction.rb +5 -1
- data/lib/coactive/coactions.rb +3 -1
- data/lib/coactive/config.rb +1 -0
- data/lib/coactive/contexts/inspect.rb +3 -21
- data/lib/coactive/contexts/inspector.rb +59 -0
- data/lib/coactive/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81adac1b8a25c283b42061c7cea9d08bc4ee06987fe2de6aba8ccee17a40e12d
|
4
|
+
data.tar.gz: ae0509c320a8e32f10dff9820d8c92adc60dee58797c6ba1d6befd206d923781
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c501671b40e84f6bf4951318db3e77e67eaa5ac7fc2120f03b6038402a9f61d4dd9ae95c4859307902f9dc5bfb0d83f193d04b1bbc8c3a9c7544b56f46c567d4
|
7
|
+
data.tar.gz: 91a4346db771c3b0ddb21c07fcf9892e8580243e80916988159b2b5a11813ea39f50b225dc21bdd74faa2430e38fbf4a1fe6ffb91a2a50d264f6744b261fb50b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.5.1
|
4
|
+
|
5
|
+
* Fix max length of inspected string.
|
6
|
+
* Fix inspect of nil.
|
7
|
+
* Fix inspect of objects with id or attributes.
|
8
|
+
|
9
|
+
## 0.5.0
|
10
|
+
|
11
|
+
* Simplify inspect of context.
|
12
|
+
* Add default priority config.
|
13
|
+
|
3
14
|
## 0.4.1
|
4
15
|
|
5
16
|
* Clear registry of coactions when reloaded.
|
data/gemfiles/rails50.gemfile
CHANGED
data/gemfiles/rails51.gemfile
CHANGED
data/gemfiles/rails52.gemfile
CHANGED
data/lib/coactive/coaction.rb
CHANGED
data/lib/coactive/coactions.rb
CHANGED
@@ -24,7 +24,9 @@ module Coactive
|
|
24
24
|
def coaction(*names, **options)
|
25
25
|
base = coactive_config.base_class
|
26
26
|
names.each do |name|
|
27
|
-
|
27
|
+
coaction = Coaction.new(self, name, options)
|
28
|
+
coaction.priority ||= coactive_config.default_priority
|
29
|
+
coactions = (Coactions[base, name].to_a + [coaction])
|
28
30
|
Coactions[base, name] = coactions.sort_by.with_index { |coaction, i| [coaction.priority, i] }
|
29
31
|
end
|
30
32
|
end
|
data/lib/coactive/config.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'inspector'
|
4
|
+
|
3
5
|
module Coactive
|
4
6
|
module Contexts
|
5
7
|
module Inspect
|
@@ -11,27 +13,7 @@ module Coactive
|
|
11
13
|
|
12
14
|
class_methods do
|
13
15
|
def inspect(data)
|
14
|
-
data.map { |k, v| "#{k}=#{Coactive::Contexts::
|
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
|
16
|
+
data.map { |k, v| "#{k}=#{Coactive::Contexts::Inspector.call(v)}" }.join(', ')
|
35
17
|
end
|
36
18
|
end
|
37
19
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Coactive
|
4
|
+
module Contexts
|
5
|
+
module Inspector
|
6
|
+
class << self
|
7
|
+
class_attribute :max_num, :max_length, :basic_classes
|
8
|
+
self.max_num = 3
|
9
|
+
self.max_length = 100
|
10
|
+
self.basic_classes = [Module, Symbol, String, Numeric, TrueClass, FalseClass, NilClass, Regexp]
|
11
|
+
|
12
|
+
def call(data)
|
13
|
+
if data.is_a?(Array)
|
14
|
+
inspect_array(data)
|
15
|
+
elsif data.is_a?(Hash)
|
16
|
+
inspect_hash(data)
|
17
|
+
elsif basic_classes.any? { |klass| data.is_a?(klass) }
|
18
|
+
inspect_basic(data)
|
19
|
+
else
|
20
|
+
inspect_object(data)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def inspect_array(data)
|
27
|
+
str = data.take(max_num).map { |v| call(v) }.join(', ')
|
28
|
+
str += "..." if data.size > max_num
|
29
|
+
"[#{str}]"
|
30
|
+
end
|
31
|
+
|
32
|
+
def inspect_hash(data)
|
33
|
+
str = data.take(max_num).map { |k, v| "#{k}: #{call(v)}" }.join(', ')
|
34
|
+
str += "..." if data.size > max_num
|
35
|
+
"{#{str}}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def inspect_basic(data)
|
39
|
+
inspected = data.inspect
|
40
|
+
if inspected.length > max_length
|
41
|
+
inspected[0..max_length] + '...'
|
42
|
+
else
|
43
|
+
inspected
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def inspect_object(data)
|
48
|
+
if data.respond_to?(:id)
|
49
|
+
"#<#{data.class}/#{data.id}>"
|
50
|
+
elsif data.respond_to?(:attributes) && (attributes = data.attributes).is_a?(Hash)
|
51
|
+
"#<#{data.class} #{inspect_hash(attributes)}>"
|
52
|
+
else
|
53
|
+
"#<#{data.class}:#{data.object_id}>"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
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.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshikazu Kaneta
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- lib/coactive/configure.rb
|
129
129
|
- lib/coactive/context.rb
|
130
130
|
- lib/coactive/contexts/inspect.rb
|
131
|
+
- lib/coactive/contexts/inspector.rb
|
131
132
|
- lib/coactive/contextualizer.rb
|
132
133
|
- lib/coactive/errors.rb
|
133
134
|
- lib/coactive/initializer.rb
|