rggen-core 0.23.0 → 0.23.1

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: 7bb706524df1f6ce830d322807a5fefe011d196b047b6a21305aedd2d139e44f
4
- data.tar.gz: b5e0f96144161ca175d50fca3efa30a87c6a2024eb0a44e2990712a295b258d9
3
+ metadata.gz: d508be683e4b6306f85c0fa2c793e98ba33dc2710dab29c07ae0fb720c0b1e20
4
+ data.tar.gz: a19ac7cea3493c7128672f343dee9833199d9e2c3769fdf0cd4679c3cc464c6d
5
5
  SHA512:
6
- metadata.gz: 7f08a781cf05602cb6d5412f3c6b72789de4b601acf0054458476bd49366757daa7ae4057d89c2d30b87d6efe54be4faf0def357b9ffa8d4a7af513f28b754c3
7
- data.tar.gz: 15952384793891091f3cc415a0770027a47d394867b5a8bef6690424e0ccd7a21ddef9af420ea2e9817f748ff8a764af5695de39e80de823c085546a4232d8b9
6
+ metadata.gz: f173621ce29ca6664d0201b4af80d9851151ab71dbd01f3027793d48402533ee9b8941d7149e5df0039370b4701975c9e926af2b36c94d8253bb6921ef3710b9
7
+ data.tar.gz: 0a7bdf33b0708f3e493b79f932fb4daf1400ea68fef957d040ef6ff5b6e1881b783b06d78d7d43a857034bc98addb3c10bb0238b01e0d7d93921c49a7ec3901b
@@ -11,22 +11,19 @@ module RgGen
11
11
  @enabled_features = {}
12
12
  end
13
13
 
14
- def define_simple_feature(names, context = nil, &body)
15
- Array(names)
16
- .each { |name| create_new_entry(:simple, name, context, body) }
14
+ def define_simple_feature(name, context = nil, &body)
15
+ create_new_entry(:simple, name, context, body)
17
16
  end
18
17
 
19
- def define_list_feature(list_names, context = nil, &body)
20
- Array(list_names)
21
- .each { |name| create_new_entry(:list, name, context, body) }
18
+ def define_list_feature(list_name, context = nil, &body)
19
+ create_new_entry(:list, list_name, context, body)
22
20
  end
23
21
 
24
- def define_list_item_feature(list_name, feature_names, context = nil, &body)
22
+ def define_list_item_feature(list_name, feature_name, context = nil, &body)
25
23
  entry = @feature_entries[list_name]
26
24
  entry&.match_entry_type?(:list) ||
27
25
  (raise BuilderError.new("unknown list feature: #{list_name}"))
28
- Array(feature_names)
29
- .each { |name| entry.define_feature(name, context, &body) }
26
+ entry.define_feature(feature_name, context, &body)
30
27
  end
31
28
 
32
29
  def enable(feature_or_list_names, feature_names = nil)
@@ -11,16 +11,8 @@ module RgGen
11
11
 
12
12
  attr_setter :body
13
13
  attr_setter :method_name
14
- attr_setter :list_names
15
- attr_setter :feature_names
16
-
17
- def shared_context(&body)
18
- if block_given?
19
- @shared_context ||= Object.new
20
- @shared_context.instance_eval(&body)
21
- end
22
- @shared_context
23
- end
14
+ attr_setter :list_name
15
+ attr_setter :feature_name
24
16
 
25
17
  def register_execution(registry, &body)
26
18
  @executions ||= []
@@ -29,15 +21,14 @@ module RgGen
29
21
 
30
22
  def execute(layer)
31
23
  Docile.dsl_eval(layer, &body)
32
- @executions&.each(&method(:call_execution))
24
+ @executions&.each { |execution| call_execution(layer, execution) }
33
25
  end
34
26
 
35
27
  private
36
28
 
37
- def call_execution(execution)
38
- args = [list_names, feature_names, shared_context].compact
39
- execution[:registry]
40
- .__send__(method_name, *args, &execution[:body])
29
+ def call_execution(layer, execution)
30
+ args = [list_name, feature_name, layer.shared_context].compact
31
+ execution[:registry].__send__(method_name, *args, &execution[:body])
41
32
  end
42
33
  end
43
34
 
@@ -52,31 +43,44 @@ module RgGen
52
43
  end
53
44
 
54
45
  def shared_context(&body)
55
- block_given? && @proxy&.shared_context(&body)
46
+ return unless @proxy
47
+
48
+ if block_given?
49
+ context = current_shared_context(true)
50
+ context.singleton_exec(&body)
51
+ end
52
+
53
+ current_shared_context(false)
56
54
  end
57
55
 
58
56
  def define_simple_feature(feature_names, &body)
59
- do_proxy_call do |proxy|
60
- proxy.body(body)
61
- proxy.method_name(__method__)
62
- proxy.feature_names(feature_names)
57
+ Array(feature_names).each do |feature_name|
58
+ do_proxy_call do |proxy|
59
+ proxy.body(body)
60
+ proxy.method_name(__method__)
61
+ proxy.feature_name(feature_name)
62
+ end
63
63
  end
64
64
  end
65
65
 
66
66
  def define_list_feature(list_names, &body)
67
- do_proxy_call do |proxy|
68
- proxy.body(body)
69
- proxy.method_name(__method__)
70
- proxy.list_names(list_names)
67
+ Array(list_names).each do |list_name|
68
+ do_proxy_call do |proxy|
69
+ proxy.body(body)
70
+ proxy.method_name(__method__)
71
+ proxy.list_name(list_name)
72
+ end
71
73
  end
72
74
  end
73
75
 
74
76
  def define_list_item_feature(list_name, feature_names, &body)
75
- do_proxy_call do |proxy|
76
- proxy.body(body)
77
- proxy.method_name(__method__)
78
- proxy.list_names(list_name)
79
- proxy.feature_names(feature_names)
77
+ Array(feature_names).each do |feature_name|
78
+ do_proxy_call do |proxy|
79
+ proxy.body(body)
80
+ proxy.method_name(__method__)
81
+ proxy.list_name(list_name)
82
+ proxy.feature_name(feature_name)
83
+ end
80
84
  end
81
85
  end
82
86
 
@@ -111,6 +115,17 @@ module RgGen
111
115
  @proxy.execute(self)
112
116
  remove_instance_variable(:@proxy)
113
117
  end
118
+
119
+ def current_shared_context(allocate)
120
+ list_name = @proxy.list_name || @proxy.feature_name
121
+ feature_name = @proxy.feature_name
122
+ allocate && (shared_contexts[list_name][feature_name] ||= Object.new)
123
+ shared_contexts[list_name][feature_name]
124
+ end
125
+
126
+ def shared_contexts
127
+ @shared_contexts ||= Hash.new { |h, k| h[k] = {} }
128
+ end
114
129
  end
115
130
  end
116
131
  end
@@ -24,6 +24,10 @@ module RgGen
24
24
  end
25
25
  end
26
26
  end
27
+
28
+ def inherited(subclass)
29
+ export_instance_variable(:@attributes, subclass, &:dup)
30
+ end
27
31
  end
28
32
 
29
33
  def self.included(class_or_module)
@@ -4,7 +4,7 @@ module RgGen
4
4
  module Core
5
5
  MAJOR = 0
6
6
  MINOR = 23
7
- PATCH = 0
7
+ PATCH = 1
8
8
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rggen-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.0
4
+ version: 0.23.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taichi Ishitani
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-25 00:00:00.000000000 Z
11
+ date: 2020-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docile
@@ -189,5 +189,5 @@ requirements: []
189
189
  rubygems_version: 3.1.2
190
190
  signing_key:
191
191
  specification_version: 4
192
- summary: rggen-core-0.23.0
192
+ summary: rggen-core-0.23.1
193
193
  test_files: []