coactive 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -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 +48 -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: e7c25e57f4b9e1c2519945529c1026470f77faa37a59753789e6c821270a3bfd
|
4
|
+
data.tar.gz: 447682aaf62af161dbdc3ac8d2a7bebdf5a39ae78a106e6163b86b916e0f69b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e4df828d91f088d1b99784bc7456cc160633b66961431e36dcb5fba5994659718cde602b4433b4510517daf29a63b4af733e7218aa5cd27066415c8efe92456
|
7
|
+
data.tar.gz: 99aa8892d8a1f6324e5e587d13e44259088badc9ab923cd6969c0b746d7c3a8b1bb834827117569f75782c243de4fe43d5324025eb247cff27f04ff04a8fce05
|
data/CHANGELOG.md
CHANGED
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,48 @@
|
|
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, 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
|
+
data.inspect
|
40
|
+
end
|
41
|
+
|
42
|
+
def inspect_object(data)
|
43
|
+
"#<#{data.class}:#{data.object_id}>"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
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.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: 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
|