coactive 0.4.1 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b15dae4695420734d0486669dd7f88d7eeceb8815932dc5f47d37cedf0dd4c61
4
- data.tar.gz: cd7f7aae30957f69c76230b8cb97ca846ad4d4c99f6c02045f54b9c866d2ec68
3
+ metadata.gz: e7c25e57f4b9e1c2519945529c1026470f77faa37a59753789e6c821270a3bfd
4
+ data.tar.gz: 447682aaf62af161dbdc3ac8d2a7bebdf5a39ae78a106e6163b86b916e0f69b9
5
5
  SHA512:
6
- metadata.gz: eebff4ac3fdb067eb44a59ffc634e4fdda567663e6be2c30923828a311f29a52679ea2aaf3295e17412ee492ef3705c1ff200a0065f5bfee03bbf36a045dd007
7
- data.tar.gz: e94206eda575c397edc5686fe012cf7ebd66074fa74b1a4215c733d7462b01099a9e2d537041749a039bcfe079bbf4ade6c71d4c2a249e65fa2849175ed94532
6
+ metadata.gz: 9e4df828d91f088d1b99784bc7456cc160633b66961431e36dcb5fba5994659718cde602b4433b4510517daf29a63b4af733e7218aa5cd27066415c8efe92456
7
+ data.tar.gz: 99aa8892d8a1f6324e5e587d13e44259088badc9ab923cd6969c0b746d7c3a8b1bb834827117569f75782c243de4fe43d5324025eb247cff27f04ff04a8fce05
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.5.0
4
+
5
+ * Simplify inspect of context.
6
+ * Add default priority config.
7
+
3
8
  ## 0.4.1
4
9
 
5
10
  * Clear registry of coactions when reloaded.
@@ -2,5 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem "rails", "~> 5.0.0"
4
4
  gem "sqlite3", "~> 1.3.6"
5
+ gem "loofah", "~> 2.19.1"
5
6
 
6
7
  gemspec path: "../"
@@ -2,5 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem "rails", "~> 5.1.0"
4
4
  gem "sqlite3", "~> 1.3.6"
5
+ gem "loofah", "~> 2.19.1"
5
6
 
6
7
  gemspec path: "../"
@@ -2,5 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem "rails", "~> 5.2.0"
4
4
  gem "sqlite3", "~> 1.3.6"
5
+ gem "loofah", "~> 2.19.1"
5
6
 
6
7
  gemspec path: "../"
@@ -3,7 +3,11 @@
3
3
  module Coactive
4
4
  class Coaction < Struct.new(:coactor, :name, :options)
5
5
  def priority
6
- options[:priority] || 1 << 63
6
+ options[:priority]
7
+ end
8
+
9
+ def priority=(val)
10
+ options[:priority] = val
7
11
  end
8
12
  end
9
13
  end
@@ -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
- coactions = Coactions[base, name].to_a + [Coaction.new(self, name, options)]
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
@@ -9,6 +9,7 @@ module Coactive
9
9
  use_cache: true,
10
10
  lookup_superclass_for_object: true,
11
11
  lookup_superclass_until: ['ActiveRecord::Base', 'ActiveModel::Base'],
12
+ default_priority: 1 << 63
12
13
  }
13
14
 
14
15
  attr_accessor :data
@@ -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::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
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Coactive
4
- VERSION = '0.4.1'
4
+ VERSION = '0.5.0'
5
5
  end
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.1
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-01-12 00:00:00.000000000 Z
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