ree 1.0.14 → 1.0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c850629eb37529ff5081fa234a60811a34ba53c4611afa24574e176e74b11f4
4
- data.tar.gz: a5f193108e82c4bdda43e6687aa5083c504bc441a0f38f77dfe8b3cb142b8d33
3
+ metadata.gz: 425a0b09dd810ba911269010acf562bed66e26b8230f295f11d161319b3456d6
4
+ data.tar.gz: f1ccd0e6983eddc7a982d1c225c4d77f6479e1a334d20ba30172d94168924ffd
5
5
  SHA512:
6
- metadata.gz: 18c39d27e8e964b8c3601255e77a6aba3f82c5eedaea7e3bfc1ca89cc6282b5268e5a50f29f60139fa572d45b0ba1d6d34b8f3589704160db9a090c1597523d9
7
- data.tar.gz: e0d8991e32a32d2f5cb186c09943152bbd2766fd5975d54bbc1d4065bf936c316b26e355a55ddeb709b985eb9faa8626711ff6cb18777b1da2da592488ba944e
6
+ metadata.gz: ff8541ebcf7beda4437eb1f937ff50138cfaf2201e08b166085018eed89e787e21174f2025cb198c15f3ab008b3af1fe788dc5384772536287935a1b87d9d000
7
+ data.tar.gz: 167436bc7d4b1bdcf6f969b2a46f39ab4b6f4cf24fac13e66ea074ffdee27a95a23f93073ea32a184f3470f1d56a7d2ac7d45f01a882228b612eea9450a2caaa
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree (1.0.14)
4
+ ree (1.0.15)
5
5
  commander (~> 4.6.0)
6
6
 
7
7
  GEM
data/exe/ree CHANGED
@@ -334,7 +334,7 @@ class ReeCliRunner
334
334
  c.syntax = 'ree gen.index_file FILE_PATH'
335
335
  c.description = 'generate index schema of methods'
336
336
  c.summary = '> ' + c.description
337
- c.example 'ree gen.index /app/bc/accounts/commands/create_account_cmd.rb --project_path=/project_dir/', ''
337
+ c.example 'ree gen.index_file /app/bc/accounts/commands/create_account_cmd.rb --project_path=/project_dir/', ''
338
338
  c.option '--project_path [ROOT_PROJECT_DIR]', String, 'Root project dir path'
339
339
  c.action do |args, options|
340
340
  file_path = args[0]
@@ -353,6 +353,29 @@ class ReeCliRunner
353
353
  end
354
354
  end
355
355
 
356
+ command :"gen.index_package" do |c|
357
+ c.syntax = 'ree gen.index_package PACKAGE_NAME'
358
+ c.description = 'generate index for package'
359
+ c.summary = '> ' + c.description
360
+ c.example 'ree gen.index_package /app/bc/accounts/commands/create_account_cmd.rb --project_path=/project_dir/', ''
361
+ c.option '--project_path [ROOT_PROJECT_DIR]', String, 'Root project dir path'
362
+ c.action do |args, options|
363
+ package_name = args[0]&.to_sym || (raise Ree::Error.new("package name should be provided"))
364
+ options_hash = options.__hash__
365
+
366
+ if options_hash[:project_path]
367
+ options_hash[:project_path] = File.expand_path(options_hash[:project_path])
368
+ end
369
+
370
+ default_options = {
371
+ package_name: package_name,
372
+ project_path: options_hash[:project_path] || File.expand_path(Dir.pwd)
373
+ }
374
+
375
+ puts Ree::CLI::IndexPackage.run(**default_options)
376
+ end
377
+ end
378
+
356
379
  run!
357
380
  end
358
381
  end
@@ -0,0 +1,116 @@
1
+ require 'json'
2
+
3
+ module Ree
4
+ module CLI
5
+ class IndexPackage
6
+ class << self
7
+ def run(package_name:, 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
+ facade = Ree.container.packages_facade
16
+
17
+ package_name = package_name.to_sym
18
+ package = facade.get_loaded_package(package_name)
19
+ package_hsh = map_package_entry(package)
20
+
21
+ JSON.pretty_generate(package_hsh)
22
+ end
23
+
24
+ private
25
+
26
+ def map_package_entry(package)
27
+ package_hsh = {}
28
+ package_hsh[:name] = package.name
29
+ package_hsh[:schema_rpath] = package.schema_rpath
30
+ package_hsh[:entry_rpath] = package.entry_rpath
31
+ package_hsh[:tags] = package.tags
32
+ 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: 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
45
+ }
46
+ }
47
+ }
48
+ }
49
+
50
+ package_hsh
51
+ end
52
+
53
+ def map_fn_methods(object)
54
+ if !object.fn?
55
+ return []
56
+ end
57
+
58
+ klass = object.klass
59
+
60
+ method_decorator = Ree::Contracts.get_method_decorator(
61
+ klass, :call, scope: :instance
62
+ )
63
+
64
+ begin
65
+ if method_decorator.nil?
66
+ parameters = klass.instance_method(:call).parameters
67
+
68
+ args = parameters.inject({}) do |res, param|
69
+ res[param.last] = Ree::Contracts::CalledArgsValidator::Arg.new(
70
+ param.last, param.first, nil, nil
71
+ )
72
+
73
+ res
74
+ end
75
+ else
76
+ parameters = method_decorator.args.params
77
+ args = method_decorator.args.get_args
78
+ end
79
+ rescue NameError
80
+ raise Ree::Error.new("method call is not defined for #{klass}")
81
+ end
82
+
83
+ arg_list = parameters.map do |param|
84
+ arg = args[param.last]
85
+ validator = arg.validator
86
+ arg_type = arg.type
87
+
88
+ type = if validator
89
+ validator.to_s
90
+ else
91
+ if arg_type == :block
92
+ "Block"
93
+ else
94
+ "Any"
95
+ end
96
+ end
97
+
98
+ {
99
+ Ree::ObjectSchema::Methods::Args::ARG => arg.name,
100
+ Ree::ObjectSchema::Methods::Args::TYPE => type
101
+ }
102
+ end
103
+
104
+ [
105
+ {
106
+ Ree::ObjectSchema::Methods::DOC => method_decorator&.doc || "",
107
+ Ree::ObjectSchema::Methods::THROWS => method_decorator&.errors&.map { _1.name } || [],
108
+ Ree::ObjectSchema::Methods::RETURN => method_decorator&.contract_definition&.return_contract || "Any",
109
+ Ree::ObjectSchema::Methods::ARGS => arg_list
110
+ }
111
+ ]
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -11,17 +11,56 @@ module Ree
11
11
  Ree.init(dir)
12
12
 
13
13
  @index_hash = {}
14
+ # completion/etc data
14
15
  @index_hash[:classes] = {}
15
16
  @index_hash[:objects] = {}
16
17
 
18
+ # schema data
19
+ @index_hash[:gem_paths] = {}
20
+ @index_hash[:packages_schema] = {}
21
+ @index_hash[:packages_schema][:packages] = []
22
+ @index_hash[:packages_schema][:gem_packages] = []
23
+
17
24
  facade = Ree.container.packages_facade
18
25
 
19
26
  facade.packages_store.packages.each do |package|
20
- next if package.gem?
21
- next if package.dir.nil?
27
+ if package.gem?
28
+ gem_package_hsh = {}
29
+ gem_package_hsh[:name] = package.name
30
+ gem_package_hsh[:gem] = package.gem_name
31
+ gem_package_hsh[:schema_rpath] = package.schema_rpath
32
+ gem_package_hsh[:entry_rpath] = package.entry_rpath
33
+ gem_package_hsh[:objects] = package.objects.map {
34
+ {
35
+ name: _1.name,
36
+ schema_rpath: _1.schema_rpath,
37
+ file_rpath: _1.rpath,
38
+ mount_as: _1.mount_as,
39
+ methods: Ree::CLI::IndexPackage.send(:map_fn_methods, _1),
40
+ links: _1.links.sort_by(&:object_name).map { |link|
41
+ {
42
+ Ree::ObjectSchema::Links::TARGET => link.object_name,
43
+ Ree::ObjectSchema::Links::PACKAGE_NAME => link.package_name,
44
+ Ree::ObjectSchema::Links::AS => link.as,
45
+ Ree::ObjectSchema::Links::IMPORTS => link.constants
46
+ }
47
+ }
48
+ }
49
+ }
22
50
 
51
+ @index_hash[:packages_schema][:gem_packages] << gem_package_hsh
52
+
53
+ next
54
+ end
55
+
56
+ next if package.dir.nil?
57
+
23
58
  facade.load_entire_package(package.name)
24
59
 
60
+ package_hsh = Ree::CLI::IndexPackage.send(:map_package_entry, package)
61
+
62
+ @index_hash[:packages_schema][:packages] << package_hsh
63
+
25
64
  objects_class_names = package.objects.map(&:class_name)
26
65
 
27
66
  files = Dir[
data/lib/ree/cli.rb CHANGED
@@ -11,6 +11,7 @@ module Ree
11
11
  autoload :GenerateTemplate, 'ree/cli/generate_template'
12
12
  autoload :IndexProject, 'ree/cli/index_project'
13
13
  autoload :IndexFile, 'ree/cli/index_file'
14
+ autoload :IndexPackage, 'ree/cli/index_package'
14
15
  autoload :SpecRunner, 'ree/cli/spec_runner'
15
16
  end
16
17
  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.14"
4
+ VERSION = "1.0.15"
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.14
4
+ version: 1.0.15
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-01-08 00:00:00.000000000 Z
11
+ date: 2023-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -70,6 +70,7 @@ files:
70
70
  - lib/ree/cli/generate_packages_schema.rb
71
71
  - lib/ree/cli/generate_template.rb
72
72
  - lib/ree/cli/index_file.rb
73
+ - lib/ree/cli/index_package.rb
73
74
  - lib/ree/cli/index_project.rb
74
75
  - lib/ree/cli/init.rb
75
76
  - lib/ree/cli/spec_runner.rb