ree 1.0.10 → 1.0.12

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: c1b2264b5461e4f29c6a6a09d71b4f594607777e30b7fd9ee04eb581f8ca4c27
4
- data.tar.gz: f56ccea02c51d34be30d0a53da9cb2a855265510b6167d19986b4ceb708a92f7
3
+ metadata.gz: d37096dd01ecabedafbd59683f3c0f6d867b8a41b82ee60630b9164bd2455d91
4
+ data.tar.gz: c87aac73ee549100e17b233d73b91b4f473b52dca803e9fa47237e3e25a7c9bd
5
5
  SHA512:
6
- metadata.gz: c423007aa3b01f9251f820eb432186ef18d909dbfc06c52d6c6748eddc7ab6d35e1d38c337ad5afcefea302a0b057832ec29eb50dda7dd4ba053bdc9ddee7913
7
- data.tar.gz: f3f0ed83742454c2f4ae91c7eb47be2a1cbce89ee2775ef220c5a73682bed9b051f9c79196b46990ab800783c630e5ef015fd9ab665a727ef9f8b8ef9b04b723
6
+ metadata.gz: cb297cb39724d3b436cda7e327b7b39cc979208abfd50fa4b39b4a0ccf756218af253d412fd9523cef14daffac1601031f37a2e10579637f14a573ef5cb2f22a
7
+ data.tar.gz: 12ae484d56f55e9058c800fffa9030c33fcb6968007eaa3502f3db06b4e3aa98131f1597becf424f177ddcc3e19dfdc366909384601eb9c84154286d65da49a1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree (1.0.10)
4
+ ree (1.0.12)
5
5
  commander (~> 4.6.0)
6
6
 
7
7
  GEM
data/exe/ree CHANGED
@@ -309,6 +309,50 @@ class ReeCliRunner
309
309
  end
310
310
  end
311
311
 
312
+ command :"gen.index_project" do |c|
313
+ c.syntax = 'ree gen.index_project'
314
+ c.description = 'generate index schema of methods'
315
+ c.summary = '> ' + c.description
316
+ c.example 'ree gen.index_project --project_path=/project_dir/', ''
317
+ c.option '--project_path [ROOT_PROJECT_DIR]', String, 'Root project dir path'
318
+ c.action do |args, options|
319
+ options_hash = options.__hash__
320
+
321
+ if options_hash[:project_path]
322
+ options_hash[:project_path] = File.expand_path(options_hash[:project_path])
323
+ end
324
+
325
+ default_options = {
326
+ project_path: options_hash[:project_path] || File.expand_path(Dir.pwd)
327
+ }
328
+
329
+ puts Ree::CLI::IndexProject.run(**default_options)
330
+ end
331
+ end
332
+
333
+ command :"gen.index_file" do |c|
334
+ c.syntax = 'ree gen.index_file FILE_PATH'
335
+ c.description = 'generate index schema of methods'
336
+ c.summary = '> ' + c.description
337
+ c.example 'ree gen.index /app/bc/accounts/commands/create_account_cmd.rb --project_path=/project_dir/', ''
338
+ c.option '--project_path [ROOT_PROJECT_DIR]', String, 'Root project dir path'
339
+ c.action do |args, options|
340
+ file_path = args[0]
341
+ options_hash = options.__hash__
342
+
343
+ if options_hash[:project_path]
344
+ options_hash[:project_path] = File.expand_path(options_hash[:project_path])
345
+ end
346
+
347
+ default_options = {
348
+ file_path: file_path,
349
+ project_path: options_hash[:project_path] || File.expand_path(Dir.pwd)
350
+ }
351
+
352
+ puts Ree::CLI::IndexFile.run(**default_options)
353
+ end
354
+ end
355
+
312
356
  run!
313
357
  end
314
358
  end
@@ -0,0 +1,71 @@
1
+ require 'json'
2
+
3
+ module Ree
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
+ objects_class_names = package.objects.map(&:class_name)
29
+ file_name_const_string = Ree::StringUtils.camelize(file_path.split('/')[-1].split('.rb')[0])
30
+ const_string_with_module = "#{package.module}::#{file_name_const_string}"
31
+
32
+ return {} if objects_class_names.include?(const_string_with_module) # skip objects
33
+
34
+ klass = Object.const_get(const_string_with_module)
35
+
36
+ methods = klass
37
+ .public_instance_methods(false)
38
+ .reject { _1.match?(/original/) } # remove aliases defined by contracts
39
+ .map {
40
+ {
41
+ name: _1,
42
+ location: klass.public_instance_method(_1).source_location&.last,
43
+ }
44
+ }
45
+
46
+ hsh = {
47
+ path: file_path,
48
+ package: current_package_name,
49
+ methods: methods
50
+ }
51
+
52
+ JSON.pretty_generate({ file_name_const_string => hsh })
53
+ end
54
+
55
+ def find_package(dir)
56
+ package_schema = File.join(dir, Ree::PACKAGE_SCHEMA_FILE)
57
+
58
+ if File.exist?(package_schema)
59
+ return package_schema
60
+ end
61
+
62
+ if dir == '/'
63
+ return nil
64
+ end
65
+
66
+ find_package(File.expand_path('..', dir))
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,147 @@
1
+ module Ree
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
+ @index_hash[:classes] = {}
15
+ @index_hash[:objects] = {}
16
+
17
+ facade = Ree.container.packages_facade
18
+
19
+ facade.packages_store.packages.each do |package|
20
+ next if package.gem?
21
+ next if package.dir.nil?
22
+
23
+ facade.load_entire_package(package.name)
24
+
25
+ objects_class_names = package.objects.map(&:class_name)
26
+
27
+ files = Dir[
28
+ File.join(
29
+ Ree::PathHelper.abs_package_module_dir(package), '**/*.rb'
30
+ )
31
+ ]
32
+
33
+ files.each do |file_name|
34
+ begin
35
+ const_string_from_file_name = Ree::StringUtils.camelize(file_name.split('/')[-1].split('.rb')[0])
36
+ const_string_with_module = "#{package.module}::#{const_string_from_file_name}"
37
+ klass = Object.const_get(const_string_with_module)
38
+
39
+ if klass.include?(ReeEnum::DSL)
40
+ index_enum(klass, file_name, package.name, dir, const_string_from_file_name)
41
+
42
+ next
43
+ end
44
+
45
+ if klass.include?(ReeDao::DSL)
46
+ index_dao(klass, file_name, package.name, dir, const_string_from_file_name)
47
+ next
48
+ end
49
+
50
+ if klass.include?(ReeMapper::DSL)
51
+ # TODO
52
+ next
53
+ end
54
+
55
+ if !objects_class_names.include?(const_string_with_module)
56
+ index_class(klass, file_name, package.name, dir, const_string_from_file_name)
57
+
58
+ next
59
+ end
60
+ rescue NameError
61
+ next
62
+ end
63
+ end
64
+ end
65
+
66
+ if facade.get_package(:ree_errors, false)
67
+ index_exceptions(facade.get_package(:ree_errors))
68
+ end
69
+
70
+
71
+ JSON.pretty_generate(@index_hash)
72
+ end
73
+
74
+ private
75
+
76
+ def index_class(klass, file_name, package_name, root_dir, hash_key)
77
+ methods = klass
78
+ .public_instance_methods(false)
79
+ .reject { _1.match?(/original/) } # remove aliases defined by contracts
80
+ .map {
81
+ {
82
+ name: _1,
83
+ location: klass.public_instance_method(_1).source_location&.last,
84
+ }
85
+ }
86
+
87
+ rpath_from_root_file_path = Pathname.new(file_name).relative_path_from(Pathname.new(root_dir)).to_s
88
+ hsh = {
89
+ path: rpath_from_root_file_path,
90
+ package: package_name,
91
+ methods: methods
92
+ }
93
+
94
+ @index_hash[:classes][hash_key] ||= []
95
+ @index_hash[:classes][hash_key] << hsh
96
+ end
97
+
98
+ def index_enum(klass, file_name, package_name, root_dir, hash_key)
99
+ index_class(klass, file_name, package_name, root_dir, hash_key)
100
+ end
101
+
102
+ def index_dao(klass, file_name, package_name, root_dir, hash_key)
103
+ filters = klass
104
+ .instance_variable_get(:@filters)
105
+ .map {
106
+ {
107
+ name: _1.name,
108
+ parameters: _1.proc.parameters.map { |param| { name: param.last, required: param.first } },
109
+ location: _1.proc&.source_location&.last
110
+ }
111
+ }
112
+
113
+ obj_name_key = Ree::StringUtils.underscore(hash_key)
114
+ rpath_from_root_file_path = Pathname.new(file_name).relative_path_from(Pathname.new(root_dir)).to_s
115
+
116
+ hsh = {
117
+ path: rpath_from_root_file_path,
118
+ package: package_name,
119
+ methods: filters
120
+ }
121
+
122
+ @index_hash[:objects][obj_name_key] ||= []
123
+ @index_hash[:objects][obj_name_key] << hsh
124
+ end
125
+
126
+ def index_exceptions(errors_package)
127
+ errors_package.objects.each do |obj|
128
+ const_name = obj.class_name.split("::")[-1]
129
+ file_name = File.join(
130
+ Ree::PathHelper.abs_package_module_dir(errors_package),
131
+ obj.name.to_s + ".rb"
132
+ )
133
+
134
+ hsh = {
135
+ path: file_name,
136
+ package: errors_package.name,
137
+ methods: []
138
+ }
139
+
140
+ @index_hash[:classes][const_name] ||= []
141
+ @index_hash[:classes][const_name] << hsh
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
data/lib/ree/cli.rb CHANGED
@@ -9,6 +9,8 @@ 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/index_project'
13
+ autoload :IndexFile, 'ree/cli/index_file'
12
14
  autoload :SpecRunner, 'ree/cli/spec_runner'
13
15
  end
14
16
  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.10"
4
+ VERSION = "1.0.12"
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.10
4
+ version: 1.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-03 00:00:00.000000000 Z
11
+ date: 2022-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -69,6 +69,8 @@ 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/index_file.rb
73
+ - lib/ree/cli/index_project.rb
72
74
  - lib/ree/cli/init.rb
73
75
  - lib/ree/cli/spec_runner.rb
74
76
  - lib/ree/container.rb