ree 1.0.27 → 1.0.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/exe/ree +3 -3
- data/lib/ree/cli/indexing/index_file.rb +71 -67
- data/lib/ree/cli/indexing/index_package.rb +27 -118
- data/lib/ree/cli/indexing/index_project.rb +66 -186
- data/lib/ree/cli/indexing.rb +265 -0
- data/lib/ree/cli.rb +1 -3
- data/lib/ree/link_dsl.rb +1 -1
- data/lib/ree/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: e9d6451014359adf3959bb738c0af6d7b8409731861230587d9053ff12680a6c
|
4
|
+
data.tar.gz: 58d5795a1a4053195b62cc8811528f05674f8d1f292d34b59ad50a0b6ac8599a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '05780d456c3cada1a08ce6c5d9775054215121eb265305ab30a2b7a8b08b08528cbefc9912ea7ad6b4f46265832d5f266432f50788fdbb4fcd923d8e0025ef1d'
|
7
|
+
data.tar.gz: bade40ae6f6123b55a04d0eaecb9af2c9ece3a3e7b05a0ecde0e9c5bb06344a6616033ce3e236a6fa2c7da4ef3f3c0514b4c53fce84ea19bb58f0e763a67b06d
|
data/Gemfile.lock
CHANGED
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
|
-
|
6
|
-
class
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
.
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
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
|
-
|
72
|
-
|
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
|
-
|
6
|
-
class
|
7
|
-
|
8
|
-
ENV['REE_SKIP_ENV_VARS_CHECK'] = 'true'
|
5
|
+
module Indexing
|
6
|
+
class IndexPackage
|
7
|
+
include Indexing
|
9
8
|
|
10
|
-
|
11
|
-
|
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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
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 :
|
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
|
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
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.
|
4
|
+
version: 1.0.28
|
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-
|
11
|
+
date: 2023-04-05 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
|