ree 1.0.27 → 1.0.29

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: 3da420a1cab7745ea5024e4ff768f5dafd9c171d516f2af413ada44ce97bcb7c
4
- data.tar.gz: 1ce4b640ceb2b86065baa948fbff60d9961c9f64780adf19ab0015f1cda518b8
3
+ metadata.gz: 8a9bafffedbc153f633b682e9a7ecbce4ad38a75dbbb9a7436798a3766d57735
4
+ data.tar.gz: 4b2562f2fb06c0afc492cce67abf5044b160c900057b5c24e14eb76104bf9049
5
5
  SHA512:
6
- metadata.gz: 950ec9370962072c1b0734f9c5954739eb3b17987bec12e009309839fb44cd185e9bbe08c2655a49bad8309989e1059f9b2c99ccea31e63ae57ecc82de069b39
7
- data.tar.gz: 5bba4ef1e49e50857c6b8b043795c19af0c579832843a7a33a451acd31f0772cddbf00d2aa32aeb764da127e03331e69bc70a120b136c115fa46a310fbf8b103
6
+ metadata.gz: ad6eddfb2656ed64223758a2b3f9a720597ba9bbca3edddbccb7ca4b284770db9fa03e3b5c81cdd5d771858bfff3e2b39566820a993eaa4f02baf3e821e3f116
7
+ data.tar.gz: 14ecf3e59cdc5d0b3a78f9fcddc74ea39cc6fb7ff77bbe2a23d6a693cf4d98f47141cfb750b4d60f9a8e09c3971e070f25d70ccff11e76121187b80e603e1666
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree (1.0.27)
4
+ ree (1.0.29)
5
5
  commander (~> 4.6.0)
6
6
 
7
7
  GEM
data/exe/ree CHANGED
@@ -326,7 +326,7 @@ class ReeCliRunner
326
326
  project_path: options_hash[:project_path] || File.expand_path(Dir.pwd)
327
327
  }
328
328
 
329
- puts Ree::CLI::IndexProject.run(**default_options)
329
+ puts Ree::CLI::Indexing::IndexProject.run(**default_options)
330
330
  end
331
331
  end
332
332
 
@@ -349,7 +349,7 @@ class ReeCliRunner
349
349
  project_path: options_hash[:project_path] || File.expand_path(Dir.pwd)
350
350
  }
351
351
 
352
- puts Ree::CLI::IndexFile.run(**default_options)
352
+ puts Ree::CLI::Indexing::IndexFile.run(**default_options)
353
353
  end
354
354
  end
355
355
 
@@ -372,7 +372,7 @@ class ReeCliRunner
372
372
  project_path: options_hash[:project_path] || File.expand_path(Dir.pwd)
373
373
  }
374
374
 
375
- puts Ree::CLI::IndexPackage.run(**default_options)
375
+ puts Ree::CLI::Indexing::IndexPackage.run(**default_options)
376
376
  end
377
377
  end
378
378
 
@@ -2,77 +2,81 @@ require 'json'
2
2
 
3
3
  module Ree
4
4
  module CLI
5
- class IndexFile
6
- class << self
7
- def run(file_path:, project_path:)
8
- ENV['REE_SKIP_ENV_VARS_CHECK'] = 'true'
9
-
10
- path = Ree.locate_packages_schema(project_path)
11
- dir = Pathname.new(path).dirname.to_s
12
-
13
- Ree.init(dir)
14
-
15
- file_path = File.join(dir, file_path)
16
-
17
- current_package_schema = self.find_package(File.dirname(file_path))
18
-
19
- return {} unless current_package_schema
20
-
21
- package_schema = JSON.load_file(current_package_schema)
22
- current_package_name = package_schema["name"].to_sym
23
-
24
- facade = Ree.container.packages_facade
25
- Ree.load_package(current_package_name)
26
-
27
- package = facade.get_package(current_package_name)
28
-
29
- files = Dir[
30
- File.join(
31
- Ree::PathHelper.abs_package_module_dir(package), '**/*.rb'
32
- )
33
- ]
34
-
35
- return {} if !files.include?(file_path)
36
-
37
- objects_class_names = package.objects.map(&:class_name)
38
- file_name_const_string = Ree::StringUtils.camelize(file_path.split('/')[-1].split('.rb')[0])
39
- const_string_with_module = "#{package.module}::#{file_name_const_string}"
40
-
41
- return {} if objects_class_names.include?(const_string_with_module) # skip objects
42
-
43
- klass = Object.const_get(const_string_with_module)
44
-
45
- methods = klass
46
- .public_instance_methods(false)
47
- .reject { _1.match?(/original/) } # remove aliases defined by contracts
48
- .map {
49
- {
50
- name: _1,
51
- location: klass.public_instance_method(_1).source_location&.last,
5
+ module Indexing
6
+ class IndexFile
7
+ include Indexing
8
+
9
+ class << self
10
+ def run(file_path:, project_path:)
11
+ ENV['REE_SKIP_ENV_VARS_CHECK'] = 'true'
12
+
13
+ path = Ree.locate_packages_schema(project_path)
14
+ dir = Pathname.new(path).dirname.to_s
15
+
16
+ Ree.init(dir)
17
+
18
+ file_path = File.join(dir, file_path)
19
+
20
+ current_package_schema = self.find_package(File.dirname(file_path))
21
+
22
+ return {} unless current_package_schema
23
+
24
+ package_schema = JSON.load_file(current_package_schema)
25
+ current_package_name = package_schema["name"].to_sym
26
+
27
+ facade = Ree.container.packages_facade
28
+ Ree.load_package(current_package_name)
29
+
30
+ package = facade.get_package(current_package_name)
31
+
32
+ files = Dir[
33
+ File.join(
34
+ Ree::PathHelper.abs_package_module_dir(package), '**/*.rb'
35
+ )
36
+ ]
37
+
38
+ return {} if !files.include?(file_path)
39
+
40
+ objects_class_names = package.objects.map(&:class_name)
41
+ file_name_const_string = Ree::StringUtils.camelize(file_path.split('/')[-1].split('.rb')[0])
42
+ const_string_with_module = "#{package.module}::#{file_name_const_string}"
43
+
44
+ return {} if objects_class_names.include?(const_string_with_module) # skip objects
45
+
46
+ klass = Object.const_get(const_string_with_module)
47
+
48
+ methods = klass
49
+ .public_instance_methods(false)
50
+ .reject { _1.match?(/original/) } # remove aliases defined by contracts
51
+ .map {
52
+ {
53
+ name: _1,
54
+ location: klass.public_instance_method(_1).source_location&.last,
55
+ }
52
56
  }
57
+
58
+ hsh = {
59
+ path: file_path,
60
+ package: current_package_name,
61
+ methods: methods
53
62
  }
54
-
55
- hsh = {
56
- path: file_path,
57
- package: current_package_name,
58
- methods: methods
59
- }
60
-
61
- JSON.pretty_generate({ file_name_const_string => hsh })
62
- end
63
-
64
- def find_package(dir)
65
- package_schema = File.join(dir, Ree::PACKAGE_SCHEMA_FILE)
66
-
67
- if File.exist?(package_schema)
68
- return package_schema
63
+
64
+ JSON.pretty_generate({ file_name_const_string => hsh })
69
65
  end
70
-
71
- if dir == '/'
72
- return nil
66
+
67
+ def find_package(dir)
68
+ package_schema = File.join(dir, Ree::PACKAGE_SCHEMA_FILE)
69
+
70
+ if File.exist?(package_schema)
71
+ return package_schema
72
+ end
73
+
74
+ if dir == '/'
75
+ return nil
76
+ end
77
+
78
+ find_package(File.expand_path('..', dir))
73
79
  end
74
-
75
- find_package(File.expand_path('..', dir))
76
80
  end
77
81
  end
78
82
  end
@@ -2,127 +2,36 @@ require 'json'
2
2
 
3
3
  module Ree
4
4
  module CLI
5
- class IndexPackage
6
- class << self
7
- def run(package_name:, project_path:)
8
- ENV['REE_SKIP_ENV_VARS_CHECK'] = 'true'
5
+ module Indexing
6
+ class IndexPackage
7
+ include Indexing
9
8
 
10
- path = Ree.locate_packages_schema(project_path)
11
- dir = Pathname.new(path).dirname.to_s
12
-
13
- Ree.init(dir)
14
-
15
- facade = Ree.container.packages_facade
16
-
17
- hsh = {}
18
- hsh[:package_schema] = {}
19
- hsh[:classes] = {}
20
- hsh[:objects] = {}
21
-
22
- package_name = package_name.to_sym
23
- facade.load_entire_package(package_name)
24
- package = facade.get_loaded_package(package_name)
25
- package_hsh = index_package_entry(package)
26
-
27
- hsh[:package_schema] = package_hsh
28
- hsh = index_public_methods_for_package_classes(package, dir, hsh)
29
-
30
- JSON.pretty_generate(hsh)
31
- end
32
-
33
- private
34
-
35
- def index_package_entry(package)
36
- package_hsh = {}
37
- package_hsh[:name] = package.name
38
- package_hsh[:schema_rpath] = package.schema_rpath
39
- package_hsh[:entry_rpath] = package.entry_rpath
40
- package_hsh[:tags] = package.tags
41
- package_hsh[:objects] = package.objects.map {
42
- {
43
- name: _1.name,
44
- schema_rpath: _1.schema_rpath,
45
- file_rpath: _1.rpath,
46
- mount_as: _1.mount_as,
47
- methods: map_fn_methods(_1),
48
- links: _1.links.sort_by(&:object_name).map { |link|
49
- {
50
- Ree::ObjectSchema::Links::TARGET => link.object_name,
51
- Ree::ObjectSchema::Links::PACKAGE_NAME => link.package_name,
52
- Ree::ObjectSchema::Links::AS => link.as,
53
- Ree::ObjectSchema::Links::IMPORTS => link.constants
54
- }
55
- }
56
- }
57
- }
58
-
59
- package_hsh
60
- end
61
-
62
- def map_fn_methods(object)
63
- if !object.fn?
64
- return []
65
- end
9
+ class << self
10
+ def run(package_name:, project_path:)
11
+ ENV['REE_SKIP_ENV_VARS_CHECK'] = 'true'
66
12
 
67
- klass = object.klass
68
-
69
- method_decorator = Ree::Contracts.get_method_decorator(
70
- klass, :call, scope: :instance
71
- )
72
-
73
- begin
74
- if method_decorator.nil?
75
- parameters = klass.instance_method(:call).parameters
76
-
77
- args = parameters.inject({}) do |res, param|
78
- res[param.last] = Ree::Contracts::CalledArgsValidator::Arg.new(
79
- param.last, param.first, nil, nil
80
- )
81
-
82
- res
83
- end
84
- else
85
- parameters = method_decorator.args.params
86
- args = method_decorator.args.get_args
87
- end
88
- rescue NameError
89
- raise Ree::Error.new("method call is not defined for #{klass}")
90
- end
91
-
92
- arg_list = parameters.map do |param|
93
- arg = args[param.last]
94
- validator = arg.validator
95
- arg_type = arg.type
96
-
97
- type = if validator
98
- validator.to_s
99
- else
100
- if arg_type == :block
101
- "Block"
102
- else
103
- "Any"
104
- end
105
- end
106
-
107
- {
108
- Ree::ObjectSchema::Methods::Args::ARG => arg.name,
109
- Ree::ObjectSchema::Methods::Args::ARG_TYPE => arg.type,
110
- Ree::ObjectSchema::Methods::Args::TYPE => type
111
- }
13
+ path = Ree.locate_packages_schema(project_path)
14
+ dir = Pathname.new(path).dirname.to_s
15
+
16
+ Ree.init(dir)
17
+
18
+ facade = Ree.container.packages_facade
19
+
20
+ hsh = {}
21
+ hsh[:package_schema] = {}
22
+ hsh[:classes] = {}
23
+ hsh[:objects] = {}
24
+
25
+ package_name = package_name.to_sym
26
+ facade.load_entire_package(package_name)
27
+ package = facade.get_loaded_package(package_name)
28
+ package_hsh = index_package_entry(package)
29
+
30
+ hsh[:package_schema] = package_hsh
31
+ hsh = index_public_methods_for_package_classes(package, hsh)
32
+
33
+ JSON.pretty_generate(hsh)
112
34
  end
113
-
114
- [
115
- {
116
- Ree::ObjectSchema::Methods::DOC => method_decorator&.doc || "",
117
- Ree::ObjectSchema::Methods::THROWS => method_decorator&.errors&.map { _1.name } || [],
118
- Ree::ObjectSchema::Methods::RETURN => method_decorator&.contract_definition&.return_contract || "Any",
119
- Ree::ObjectSchema::Methods::ARGS => arg_list
120
- }
121
- ]
122
- end
123
-
124
- def index_public_methods_for_package_classes(package, dir, index_hash)
125
- Ree::CLI::IndexProject.send(:index_public_methods_for_package_classes, package, index_hash)
126
35
  end
127
36
  end
128
37
  end
@@ -1,197 +1,77 @@
1
1
  module Ree
2
2
  module CLI
3
- class IndexProject
4
- class << self
5
- def run(project_path:)
6
- ENV['REE_SKIP_ENV_VARS_CHECK'] = 'true'
7
-
8
- path = Ree.locate_packages_schema(project_path)
9
- dir = Pathname.new(path).dirname.to_s
10
-
11
- Ree.init(dir)
12
-
13
- index_hash = {}
14
- # completion/etc data
15
- index_hash[:classes] = {}
16
- index_hash[:objects] = {}
17
-
18
- # schema data
19
- index_hash[:packages_schema] = {}
20
- index_hash[:packages_schema][:packages] = []
21
- index_hash[:packages_schema][:gem_packages] = []
22
-
23
- facade = Ree.container.packages_facade
24
-
25
- facade.packages_store.packages.each do |package|
26
- if package.gem?
27
- gem_package_hsh = {}
28
- gem_package_hsh[:name] = package.name
29
- gem_package_hsh[:gem] = package.gem_name
30
- gem_package_hsh[:schema_rpath] = package.schema_rpath
31
- gem_package_hsh[:entry_rpath] = package.entry_rpath
32
- gem_package_hsh[:objects] = package.objects.map {
33
- {
34
- name: _1.name,
35
- schema_rpath: _1.schema_rpath,
36
- file_rpath: _1.rpath,
37
- mount_as: _1.mount_as,
38
- methods: Ree::CLI::IndexPackage.send(:map_fn_methods, _1),
39
- links: _1.links.sort_by(&:object_name).map { |link|
40
- {
41
- Ree::ObjectSchema::Links::TARGET => link.object_name,
42
- Ree::ObjectSchema::Links::PACKAGE_NAME => link.package_name,
43
- Ree::ObjectSchema::Links::AS => link.as,
44
- Ree::ObjectSchema::Links::IMPORTS => link.constants
3
+ module Indexing
4
+ class IndexProject
5
+ include Indexing
6
+
7
+ class << self
8
+ def run(project_path:)
9
+ ENV['REE_SKIP_ENV_VARS_CHECK'] = 'true'
10
+
11
+ path = Ree.locate_packages_schema(project_path)
12
+ dir = Pathname.new(path).dirname.to_s
13
+
14
+ Ree.init(dir)
15
+
16
+ index_hash = {}
17
+ # completion/etc data
18
+ index_hash[:classes] = {}
19
+ index_hash[:objects] = {}
20
+
21
+ # schema data
22
+ index_hash[:packages_schema] = {}
23
+ index_hash[:packages_schema][:packages] = []
24
+ index_hash[:packages_schema][:gem_packages] = []
25
+
26
+ facade = Ree.container.packages_facade
27
+
28
+ facade.packages_store.packages.each do |package|
29
+ if package.gem?
30
+ gem_package_hsh = {}
31
+ gem_package_hsh[:name] = package.name
32
+ gem_package_hsh[:gem] = package.gem_name
33
+ gem_package_hsh[:schema_rpath] = package.schema_rpath
34
+ gem_package_hsh[:entry_rpath] = package.entry_rpath
35
+ gem_package_hsh[:objects] = package.objects.map {
36
+ {
37
+ name: _1.name,
38
+ schema_rpath: _1.schema_rpath,
39
+ file_rpath: _1.rpath,
40
+ mount_as: _1.mount_as,
41
+ methods: map_fn_methods(_1),
42
+ links: _1.links.sort_by(&:object_name).map { |link|
43
+ {
44
+ Ree::ObjectSchema::Links::TARGET => link.object_name,
45
+ Ree::ObjectSchema::Links::PACKAGE_NAME => link.package_name,
46
+ Ree::ObjectSchema::Links::AS => link.as,
47
+ Ree::ObjectSchema::Links::IMPORTS => link.constants
48
+ }
45
49
  }
46
50
  }
47
51
  }
48
- }
49
-
50
- index_hash[:packages_schema][:gem_packages] << gem_package_hsh
51
-
52
- next
52
+
53
+ index_hash[:packages_schema][:gem_packages] << gem_package_hsh
54
+
55
+ next
56
+ end
57
+
58
+ next if package.dir.nil?
59
+
60
+ facade.load_entire_package(package.name)
61
+
62
+ package_hsh = index_package_entry(package)
63
+
64
+ index_hash[:packages_schema][:packages] << package_hsh
65
+
66
+ index_hash = index_public_methods_for_package_classes(package, index_hash)
53
67
  end
54
-
55
- next if package.dir.nil?
56
-
57
- facade.load_entire_package(package.name)
58
-
59
- package_hsh = Ree::CLI::IndexPackage.send(:index_package_entry, package)
60
-
61
- index_hash[:packages_schema][:packages] << package_hsh
62
-
63
- index_hash = index_public_methods_for_package_classes(package, index_hash)
64
- end
65
-
66
- if facade.get_package(:ree_errors, false)
67
- index_hash = index_exceptions(facade.get_package(:ree_errors), index_hash)
68
- end
69
-
70
- JSON.pretty_generate(index_hash)
71
- end
72
-
73
- private
74
-
75
- def index_public_methods_for_package_classes(package, index_hash)
76
- package.objects.each do |obj|
77
- klass = obj.klass
78
- klass_name = demodulize(klass.to_s)
79
- obj_name = obj.name.to_s
80
- rpath = obj.rpath
81
-
82
- if obj.tags.include?("enum")
83
- hsh = index_class(klass, rpath, package.name)
84
- index_hash[:classes][klass_name] ||= []
85
- index_hash[:classes][klass_name] << hsh
86
- index_hash[:objects][obj_name] ||= []
87
- index_hash[:objects][obj_name] << hsh
88
- elsif obj.tags.include?("dao")
89
- hsh = index_dao(klass, rpath, package.name)
90
- index_hash[:objects][obj_name] ||= []
91
- index_hash[:objects][obj_name] << hsh
92
- elsif obj.tags.include?("object")
93
- hsh = index_class(klass, rpath, package.name)
94
- index_hash[:objects][obj_name] ||= []
95
- index_hash[:objects][obj_name] << hsh
68
+
69
+ if facade.get_package(:ree_errors, false)
70
+ index_hash = index_exceptions(facade.get_package(:ree_errors), index_hash)
96
71
  end
72
+
73
+ JSON.pretty_generate(index_hash)
97
74
  end
98
-
99
- recursively_index_module(package.module, index_hash, package, {})
100
-
101
- index_hash
102
- end
103
-
104
- def recursively_index_module(mod, index_hsh, package, mod_index)
105
- return if !mod.is_a?(Module)
106
- return if mod_index[mod]
107
-
108
- mod_index[mod] = true
109
-
110
- mod.constants.each do |const_name|
111
- const = mod.const_get(const_name)
112
-
113
- recursively_index_module(const, index_hsh, package, mod_index)
114
-
115
- next if !const.is_a?(Class)
116
- next if package.objects.any? { |o| o.klass == const }
117
- next if index_hsh[:classes].has_key?(demodulize(const.name))
118
-
119
- const_abs_path = mod.const_source_location(const.name)&.first
120
- next if !const_abs_path
121
-
122
- rpath = Pathname.new(const_abs_path).relative_path_from(Ree.root_dir).to_s
123
- hsh = index_class(const, rpath, package.name)
124
- class_name = demodulize(const.name)
125
-
126
- index_hsh[:classes][class_name] ||= []
127
- index_hsh[:classes][class_name] << hsh
128
- end
129
- end
130
-
131
- def index_class(klass, rpath, package_name)
132
- all_methods = klass.public_instance_methods(false)
133
- orig_methods = all_methods.grep(/original/)
134
-
135
- methods = (all_methods - orig_methods) # remove aliases defined by contracts
136
- .map { |m|
137
- orig_method_name = orig_methods.find { |om| om.match(/original_#{Regexp.escape(m.name)}_[0-9a-fA-F]+/) }
138
- orig_method = orig_method_name ? klass.public_instance_method(orig_method_name) : nil
139
-
140
- {
141
- name: m,
142
- parameters: orig_method&.parameters&.map { |param| { name: param.last, required: param.first } },
143
- location: orig_method&.source_location&.last,
144
- }
145
- }
146
-
147
- {
148
- path: rpath,
149
- package: package_name,
150
- methods: methods
151
- }
152
- end
153
-
154
- def index_dao(klass, rpath, package_name)
155
- filters = (klass.instance_variable_get(:@filters) || []).map do
156
- {
157
- name: _1.name,
158
- parameters: _1.proc.parameters.map { |param|
159
- {name: param.last, required: param.first}
160
- },
161
- location: _1.proc&.source_location&.last
162
- }
163
- end
164
-
165
- {
166
- path: rpath,
167
- package: package_name,
168
- methods: filters
169
- }
170
- end
171
-
172
- def index_exceptions(errors_package, index_hash)
173
- errors_package.objects.each do |obj|
174
- const_name = demodulize(obj.class_name)
175
- file_name = File.join(
176
- Ree::PathHelper.abs_package_module_dir(errors_package),
177
- obj.name.to_s + ".rb"
178
- )
179
-
180
- hsh = {
181
- path: file_name,
182
- package: errors_package.name,
183
- methods: []
184
- }
185
-
186
- index_hash[:classes][const_name] ||= []
187
- index_hash[:classes][const_name] << hsh
188
- end
189
-
190
- index_hash
191
- end
192
-
193
- def demodulize(str)
194
- str.split("::").last
195
75
  end
196
76
  end
197
77
  end
@@ -0,0 +1,265 @@
1
+ module Ree
2
+ module CLI
3
+ module Indexing
4
+ autoload :IndexProject, 'ree/cli/indexing/index_project'
5
+ autoload :IndexFile, 'ree/cli/indexing/index_file'
6
+ autoload :IndexPackage, 'ree/cli/indexing/index_package'
7
+
8
+ def self.included(base)
9
+ base.extend(ClassMethods)
10
+ end
11
+ module ClassMethods
12
+ def index_package_entry(package)
13
+ package_hsh = {}
14
+ package_hsh[:name] = package.name
15
+ package_hsh[:schema_rpath] = package.schema_rpath
16
+ package_hsh[:entry_rpath] = package.entry_rpath
17
+ package_hsh[:tags] = package.tags
18
+ package_hsh[:objects] = package.objects.map {
19
+ {
20
+ name: _1.name,
21
+ schema_rpath: _1.schema_rpath,
22
+ file_rpath: _1.rpath,
23
+ mount_as: _1.mount_as,
24
+ methods: map_fn_methods(_1),
25
+ links: _1.links.sort_by(&:object_name).map { |link|
26
+ {
27
+ Ree::ObjectSchema::Links::TARGET => link.object_name,
28
+ Ree::ObjectSchema::Links::PACKAGE_NAME => link.package_name,
29
+ Ree::ObjectSchema::Links::AS => link.as,
30
+ Ree::ObjectSchema::Links::IMPORTS => link.constants
31
+ }
32
+ }
33
+ }
34
+ }
35
+
36
+ package_hsh
37
+ end
38
+
39
+ def map_fn_methods(object)
40
+ if !object.fn?
41
+ return []
42
+ end
43
+
44
+ klass = object.klass
45
+
46
+ object_is_action = object.tags.include?("action")
47
+ action_caster = object.klass.const_get(:ActionCaster) if object.klass.const_defined?(:ActionCaster)
48
+
49
+ method_name = object_is_action ? :__original_call : :call
50
+ method_decorator = Ree::Contracts.get_method_decorator(
51
+ klass, method_name, scope: :instance
52
+ )
53
+
54
+ begin
55
+ if method_decorator.nil?
56
+ parameters = klass.instance_method(:call).parameters
57
+
58
+ args = parameters.inject({}) do |res, param|
59
+ res[param.last] = Ree::Contracts::CalledArgsValidator::Arg.new(
60
+ param.last, param.first, nil, nil
61
+ )
62
+
63
+ res
64
+ end
65
+ else
66
+ parameters = method_decorator.args.params
67
+ args = method_decorator.args.get_args
68
+ end
69
+ rescue NameError
70
+ raise Ree::Error.new("method call is not defined for #{klass}")
71
+ end
72
+
73
+
74
+ arg_list = parameters.map do |param|
75
+ arg = args[param.last]
76
+ validator = arg.validator
77
+ arg_type = arg.type
78
+
79
+ type = if object_is_action && action_caster && arg.name == :attrs
80
+ map_mapper_fields(action_caster.fields).to_s.gsub(/\\*\"/, "").gsub(/\=\>/, ' => ')
81
+ else
82
+ if validator
83
+ validator.to_s
84
+ else
85
+ arg_type == :block ? "Block" : "Any"
86
+ end
87
+ end
88
+
89
+ {
90
+ Ree::ObjectSchema::Methods::Args::ARG => arg.name,
91
+ Ree::ObjectSchema::Methods::Args::ARG_TYPE => arg.type,
92
+ Ree::ObjectSchema::Methods::Args::TYPE => type
93
+ }
94
+ end
95
+
96
+ [
97
+ {
98
+ Ree::ObjectSchema::Methods::DOC => method_decorator&.doc || "",
99
+ Ree::ObjectSchema::Methods::THROWS => method_decorator&.errors&.map { _1.name } || [],
100
+ Ree::ObjectSchema::Methods::RETURN => method_decorator&.contract_definition&.return_contract || "Any",
101
+ Ree::ObjectSchema::Methods::ARGS => arg_list
102
+ }
103
+ ]
104
+ end
105
+
106
+ def index_public_methods_for_package_classes(package, index_hash)
107
+ package.objects.each do |obj|
108
+ klass = obj.klass
109
+ klass_name = demodulize(klass.to_s)
110
+ obj_name = obj.name.to_s
111
+ rpath = obj.rpath
112
+
113
+ if obj.tags.include?("enum")
114
+ hsh = index_class(klass, rpath, package.name)
115
+ index_hash[:classes][klass_name] ||= []
116
+ index_hash[:classes][klass_name] << hsh
117
+ index_hash[:objects][obj_name] ||= []
118
+ index_hash[:objects][obj_name] << hsh
119
+ elsif obj.tags.include?("dao")
120
+ hsh = index_dao(klass, rpath, package.name)
121
+ index_hash[:objects][obj_name] ||= []
122
+ index_hash[:objects][obj_name] << hsh
123
+ elsif obj.tags.include?("object")
124
+ hsh = index_class(klass, rpath, package.name)
125
+ index_hash[:objects][obj_name] ||= []
126
+ index_hash[:objects][obj_name] << hsh
127
+ end
128
+ end
129
+
130
+ recursively_index_module(package.module, index_hash, package, {})
131
+
132
+ index_hash
133
+ end
134
+
135
+ private
136
+
137
+ def recursively_index_module(mod, index_hsh, package, mod_index)
138
+ return if !mod.is_a?(Module)
139
+ return if mod_index[mod]
140
+
141
+ mod_index[mod] = true
142
+
143
+ mod.constants.each do |const_name|
144
+ const = mod.const_get(const_name)
145
+
146
+ recursively_index_module(const, index_hsh, package, mod_index)
147
+
148
+ next if !const.is_a?(Class)
149
+ next if package.objects.any? { |o| o.klass == const }
150
+ next if index_hsh[:classes].has_key?(demodulize(const.name))
151
+
152
+ const_abs_path = mod.const_source_location(const.name)&.first
153
+ next if !const_abs_path
154
+
155
+ rpath = Pathname.new(const_abs_path).relative_path_from(Ree.root_dir).to_s
156
+ hsh = index_class(const, rpath, package.name)
157
+ class_name = demodulize(const.name)
158
+
159
+ index_hsh[:classes][class_name] ||= []
160
+ index_hsh[:classes][class_name] << hsh
161
+ end
162
+ end
163
+
164
+ def index_class(klass, rpath, package_name)
165
+ all_methods = klass.public_instance_methods(false)
166
+ orig_methods = all_methods.grep(/original/)
167
+
168
+ methods = (all_methods - orig_methods) # remove aliases defined by contracts
169
+ .map { |m|
170
+ orig_method_name = orig_methods.find { |om| om.match(/original_#{Regexp.escape(m.name)}_[0-9a-fA-F]+/) }
171
+ orig_method = orig_method_name ? klass.public_instance_method(orig_method_name) : nil
172
+
173
+ {
174
+ name: m,
175
+ parameters: orig_method&.parameters&.map { |param| { name: param.last, required: param.first } },
176
+ location: orig_method&.source_location&.last,
177
+ }
178
+ }
179
+
180
+ {
181
+ path: rpath,
182
+ package: package_name,
183
+ methods: methods
184
+ }
185
+ end
186
+
187
+ def index_dao(klass, rpath, package_name)
188
+ filters = (klass.instance_variable_get(:@filters) || []).map do
189
+ {
190
+ name: _1.name,
191
+ parameters: _1.proc.parameters.map { |param|
192
+ {name: param.last, required: param.first}
193
+ },
194
+ location: _1.proc&.source_location&.last
195
+ }
196
+ end
197
+
198
+ {
199
+ path: rpath,
200
+ package: package_name,
201
+ methods: filters
202
+ }
203
+ end
204
+
205
+ def index_exceptions(errors_package, index_hash)
206
+ errors_package.objects.each do |obj|
207
+ const_name = demodulize(obj.class_name)
208
+ file_name = File.join(
209
+ Ree::PathHelper.abs_package_module_dir(errors_package),
210
+ obj.name.to_s + ".rb"
211
+ )
212
+
213
+ hsh = {
214
+ path: file_name,
215
+ package: errors_package.name,
216
+ methods: []
217
+ }
218
+
219
+ index_hash[:classes][const_name] ||= []
220
+ index_hash[:classes][const_name] << hsh
221
+ end
222
+
223
+ index_hash
224
+ end
225
+
226
+ def map_mapper_fields(fields, acc = {})
227
+ fields.keys.each do |key|
228
+ acc_key = fields[key].optional ? "#{key}?".to_sym : key
229
+ acc[acc_key] = map_field(fields[key], {})
230
+ end
231
+
232
+ acc
233
+ end
234
+
235
+ def map_field(field, acc = {})
236
+ if field.type.fields != {}
237
+ map_mapper_fields(field.type.fields, acc)
238
+ else
239
+ type_klass = field.type.type.class
240
+ type = demodulize(type_klass)
241
+
242
+ case
243
+ when type == "Array"
244
+ subject_type = field.type.type.subject.type
245
+ if subject_type.fields != {}
246
+ "ArrayOf[#{map_mapper_fields(field.type.type.subject.type.fields)}]"
247
+ else
248
+ "ArrayOf[#{demodulize(field.type.type.subject.type.type.class)}]"
249
+ end
250
+ when %w(Any Bool DateTime Date Float Integer String Time).include?(type)
251
+ field.null ? "Nilor[#{type}]" : type
252
+ else
253
+ field_type = field.type.type
254
+ field_type.instance_variables.length > 0 ? field_type.instance_variable_get(field_type.instance_variables.first)&.to_s : type
255
+ end
256
+ end
257
+ end
258
+
259
+ def demodulize(klass)
260
+ klass.to_s.split("::").last
261
+ end
262
+ end
263
+ end
264
+ end
265
+ end
data/lib/ree/cli.rb CHANGED
@@ -9,9 +9,7 @@ module Ree
9
9
  autoload :DeleteObjectSchema, 'ree/cli/delete_object_schema'
10
10
  autoload :GeneratePackage, 'ree/cli/generate_package'
11
11
  autoload :GenerateTemplate, 'ree/cli/generate_template'
12
- autoload :IndexProject, 'ree/cli/indexing/index_project'
13
- autoload :IndexFile, 'ree/cli/indexing/index_file'
14
- autoload :IndexPackage, 'ree/cli/indexing/index_package'
12
+ autoload :Indexing, 'ree/cli/indexing'
15
13
  autoload :SpecRunner, 'ree/cli/spec_runner'
16
14
  end
17
15
  end
@@ -4,12 +4,12 @@ class Ree::ImportDsl
4
4
  def execute(klass, proc)
5
5
  self.class.instance_exec(&proc)
6
6
  rescue Ree::ImportDsl::UnlinkConstError => e
7
- const_removed = remove_const(klass, e.const)
7
+ const_removed = remove_or_assign_const(klass, e.const)
8
8
 
9
9
  retry if const_removed
10
10
  rescue NoMethodError => e
11
11
  if e.name == :&
12
- const_removed = remove_const(klass, e.receiver)
12
+ const_removed = remove_or_assign_const(klass, e.receiver)
13
13
 
14
14
  if const_removed
15
15
  retry
@@ -29,7 +29,7 @@ class Ree::ImportDsl
29
29
 
30
30
  class UnlinkConstError < StandardError
31
31
  attr_reader :const
32
-
32
+
33
33
  def initialize(const)
34
34
  @const = const
35
35
  end
@@ -82,25 +82,63 @@ class Ree::ImportDsl
82
82
 
83
83
  private
84
84
 
85
- def remove_const(klass, constant)
86
- const_removed = false
85
+ def remove_or_assign_const(klass, constant)
86
+ retry_after = false
87
87
 
88
88
  klass.constants.each do |const_sym|
89
89
  const = klass.const_get(const_sym)
90
+ next if const.is_a?(ClassConstant)
90
91
 
91
92
  if constant.is_a?(Class) || constant.is_a?(Module)
92
93
  if (const.is_a?(Class) || const.is_a?(Module)) && const.name == constant.name
93
94
  klass.send(:remove_const, const_sym)
94
- const_removed = true
95
+ retry_after = true
95
96
  break
96
97
  end
97
98
  elsif const == constant
98
99
  klass.send(:remove_const, const_sym)
99
- const_removed = true
100
+ retry_after = true
100
101
  break
101
102
  end
102
103
  end
103
104
 
104
- const_removed
105
+ return true if retry_after
106
+
107
+ const_name = if constant.is_a?(String)
108
+ constant.to_sym
109
+ elsif constant.is_a?(Class) || constant.is_a?(Module)
110
+ constant.name
111
+ else
112
+ raise ArgumentError.new("unknown constant: #{constant.inspect}")
113
+ end
114
+
115
+ if parent_constant?(klass, const_name)
116
+ klass.const_set(const_name, ClassConstant.new(const_name.to_s))
117
+ retry_after = true
118
+ end
119
+
120
+ retry_after
121
+ end
122
+
123
+ private
124
+
125
+ def parent_constant?(klass, const_name)
126
+ modules = klass.to_s.split("::")[0..-2]
127
+
128
+ result = modules.each_with_index.any? do |mod, index|
129
+ mod = Object.const_get(modules[0..index].join("::"))
130
+ mod.constants.include?(const_name)
131
+ end
132
+
133
+ result || acnchestor_constant?(klass, const_name)
134
+ end
135
+
136
+ def acnchestor_constant?(klass, const_name)
137
+ return false if klass.ancestors.include?(klass) && klass.ancestors.size == 1
138
+
139
+ klass.ancestors.any? do |anchestor|
140
+ next if anchestor == klass
141
+ anchestor.constants.include?(const_name) || acnchestor_constant?(anchestor, const_name)
142
+ end
105
143
  end
106
144
  end
data/lib/ree/link_dsl.rb CHANGED
@@ -167,7 +167,7 @@ module Ree::LinkDSL
167
167
 
168
168
  if dep_package.nil?
169
169
  raise Ree::Error.new(
170
- "Package :#{package_name} is not added as dependency for :#{current_package_name} package\npackage path: #{File.join(Ree.root_dir, current_package.entry_rpath)}\nclass:#{self.name}",
170
+ "Package :#{package_name} is not added as dependency for :#{current_package_name} package\npackage path: #{File.join(Ree.root_dir, current_package.entry_rpath || "")}\nclass:#{self.name}",
171
171
  :invalid_dsl_usage
172
172
  )
173
173
  end
data/lib/ree/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ree
4
- VERSION = "1.0.27"
4
+ VERSION = "1.0.29"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ree
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.27
4
+ version: 1.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-10 00:00:00.000000000 Z
11
+ date: 2023-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -69,6 +69,7 @@ files:
69
69
  - lib/ree/cli/generate_package_schema.rb
70
70
  - lib/ree/cli/generate_packages_schema.rb
71
71
  - lib/ree/cli/generate_template.rb
72
+ - lib/ree/cli/indexing.rb
72
73
  - lib/ree/cli/indexing/index_file.rb
73
74
  - lib/ree/cli/indexing/index_package.rb
74
75
  - lib/ree/cli/indexing/index_project.rb