coactive 0.2.0 → 0.3.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: be01c5f37abbfc9ccf4a885e3eefdaf6416bdf2f04c08e29194acd4253a6a222
4
- data.tar.gz: f65e89cca406a0d1a34ee056f3bbf3e8fb2dc4e12d0710007fd31c5c8d249b03
3
+ metadata.gz: d34754b34f7bf3ed8e44b8f7b1ef42eff9a8c2915c335e5098e119b891c27053
4
+ data.tar.gz: e9194f39d2395961bceb2f88613de90e2f8acb7028af24ffd868c651f78f60c8
5
5
  SHA512:
6
- metadata.gz: a1290b6da95ab7806fa2eabd3bf1bd904bfb7536a7bb7d9b8ffa7d70e66e593ad91f211cb247d37f8a291d21fe98fb890c835b6a2a4a9d09057da8b5ff59f738
7
- data.tar.gz: 6db5aad85ac64b5a398e892fdfe652448cecbf56a30f3c2352929ac7d138348d69afb109621ee7e105058c43d82649e53c32787d224eab8244bdb83e251b4381
6
+ metadata.gz: c78fca95b4d4ffc86a5be1327d2049e9bd8023844aa48ff864185aa5ce6852cd9170fb8080bb412792db11db23b591ca67d79699c8b9ebeecbcc8ce8063247b3
7
+ data.tar.gz: 7c95f6e44e30304170a983db92c41ca446605d1b5abc15ffe92a680b76a0fba376ab5b629abf78c7ea6bf39aef81a174358db16628617ee1fe104f817bd6b5f3
@@ -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]
12
12
  gemfile: ['rails50', 'rails51', 'rails52', 'rails60', 'rails61', 'rails70']
13
13
  exclude:
14
14
  - ruby: 2.3
@@ -33,6 +33,12 @@ 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
36
42
 
37
43
  name: ruby ${{ matrix.ruby }}, ${{ matrix.gemfile }}
38
44
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.3.0
4
+
5
+ * Reduce inspection size for context.
6
+
7
+ ## 0.2.2
8
+
9
+ * Allow overwrite context variables.
10
+
11
+ ## 0.2.1
12
+
13
+ * Truncate string for context.
14
+
3
15
  ## 0.2.0
4
16
 
5
17
  * Add context feature.
data/bin/console CHANGED
@@ -10,5 +10,5 @@ require "coactive"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- # require "irb"
14
- # IRB.start
13
+ require "irb"
14
+ IRB.start
@@ -1,5 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem "rails", "~> 7.0.0"
3
+ gem "rails", "~> 7.0.1"
4
4
 
5
5
  gemspec path: "../"
@@ -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,12 +29,6 @@ module Coactive
25
29
  @_data
26
30
  end
27
31
 
28
- def to_s
29
- attrs = @_data.map { |k, v| "#{k}=#{v.inspect}" }.join(', ')
30
- "#<#{self.class} #{attrs}>"
31
- end
32
- alias :inspect :to_s
33
-
34
32
  def define_accessors!(keys)
35
33
  Array(keys).each do |key|
36
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
@@ -14,7 +14,8 @@ module Coactive
14
14
 
15
15
  class_methods do
16
16
  def context(*names, **options)
17
- self._contexts = self._contexts + names.map { |name| Variable.new(name, options) }
17
+ self._contexts = _contexts.reject { |var| names.include?(var.name) }
18
+ self._contexts += names.map { |name| Variable.new(name, options) }
18
19
  end
19
20
  end
20
21
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Coactive
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.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.2.0
4
+ version: 0.3.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: 2022-01-03 00:00:00.000000000 Z
11
+ date: 2022-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -127,6 +127,7 @@ files:
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