ree 1.0.9 → 1.0.11

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: 754004035abda42c6d92689e63dd8c2b5e58d0aa706097cd6a825decdbad36f3
4
- data.tar.gz: 43c066a73992ff94ce014301d9dea2df68ab804f90ae580d7a3dfca36f9c59e5
3
+ metadata.gz: 4ab958ee043c81bd88eb63c97ae9bb27a93e653e0488f14f46d9ec6d6b1e3e31
4
+ data.tar.gz: 7f41c692cafddc219cbb9a9ba3191b930a59b204d2a20d1ad873291dfdb335f2
5
5
  SHA512:
6
- metadata.gz: f126d959715dbf0c9e2c4bf01824c832a111e78385afe4573c2752c259f7b42ce108995eec25398f3fd3b0b8b32fee9d8edfdd382dd4799dcb6b467dbea2d741
7
- data.tar.gz: b6663db03cca36ba13f6faddb54ae041a40d1e20f36ac426b55a126aae9f207c0d217a03527fd89951f0d91658db436ef5f995d9810205fd907f2562e46100af
6
+ metadata.gz: a6a93a7e5cc610dad542897ca0f35c61650a93b13dd784a1030c7f94d794e24bae48bb3cc3a11c652737e27902418e67c35089064a0ce66547c745f557ba4166
7
+ data.tar.gz: 16b33f81947babead599ac94c95746915a05e858d3b9be38c45761b3425cdf5be868e93279378b37c6af523b6b0928a6f476f701b596b454df21430d933e087a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree (1.0.9)
4
+ ree (1.0.11)
5
5
  commander (~> 4.6.0)
6
6
 
7
7
  GEM
data/exe/ree CHANGED
@@ -251,7 +251,7 @@ class ReeCliRunner
251
251
  package_abs_path = Ree::PathHelper.abs_package_dir(package)
252
252
  exec_abs_path = Pathname.new(package_abs_path).join(Pathname.new(executable_path)).to_s
253
253
 
254
- raise Ree::Error.new("File #{exec_abs_path} not found") unless File.exists?(exec_abs_path)
254
+ raise Ree::Error.new("File #{exec_abs_path} not found") unless File.exist?(exec_abs_path)
255
255
 
256
256
  system("chmod +x #{exec_abs_path}") if run_chmod_x
257
257
  system(exec_abs_path)
@@ -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
@@ -19,7 +19,7 @@ module Ree
19
19
  schema_path = Ree::PathHelper.object_schema_rpath(object_path)
20
20
  abs_schema_path = File.join(dir, schema_path)
21
21
 
22
- if File.exists?(abs_schema_path)
22
+ if File.exist?(abs_schema_path)
23
23
  FileUtils.rm(abs_schema_path)
24
24
 
25
25
  puts(" #{schema_path}: is deleted") if !silence
@@ -29,7 +29,7 @@ module Ree
29
29
  else
30
30
  file_path = File.join(dir, object_path)
31
31
 
32
- if File.exists?(file_path)
32
+ if File.exist?(file_path)
33
33
  facade.load_file(file_path, package_name)
34
34
  facade.dump_package_schema(package_name)
35
35
 
@@ -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,70 @@
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
+
16
+ facade = Ree.container.packages_facade
17
+
18
+ facade.packages_store.packages.each do |package|
19
+ next if package.gem?
20
+ next if package.dir.nil?
21
+
22
+ facade.load_entire_package(package.name)
23
+
24
+ objects_class_names = package.objects.map(&:class_name)
25
+
26
+ files = Dir[
27
+ File.join(
28
+ Ree::PathHelper.abs_package_module_dir(package), '**/*.rb'
29
+ )
30
+ ]
31
+
32
+ files.each do |file_name|
33
+ begin
34
+ file_name_const_string = Ree::StringUtils.camelize(file_name.split('/')[-1].split('.rb')[0])
35
+ const_string_with_module = "#{package.module}::#{file_name_const_string}"
36
+
37
+ next if objects_class_names.include?(const_string_with_module) # skip objects
38
+
39
+ klass = Object.const_get(const_string_with_module)
40
+
41
+ methods = klass
42
+ .public_instance_methods(false)
43
+ .reject { _1.match?(/original/) } # remove aliases defined by contracts
44
+ .map {
45
+ {
46
+ name: _1,
47
+ location: klass.public_instance_method(_1).source_location&.last,
48
+ }
49
+ }
50
+
51
+ hsh = {
52
+ path: file_name,
53
+ package: package.name,
54
+ methods: methods
55
+ }
56
+
57
+ index_hash[:classes][file_name_const_string] ||= []
58
+ index_hash[:classes][file_name_const_string] << hsh
59
+ rescue NameError
60
+ next
61
+ end
62
+ end
63
+ end
64
+
65
+ JSON.pretty_generate(index_hash)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ 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
@@ -6,16 +6,14 @@ require_relative 'engine_proxy'
6
6
 
7
7
  module Ree::Contracts
8
8
  module Contractable
9
- if !Ree::Contracts.no_contracts?
10
- def method_added(name)
11
- MethodDecorator.new(name, false, self).call
12
- super
13
- end
9
+ def method_added(name)
10
+ MethodDecorator.new(name, false, self).call
11
+ super
12
+ end
14
13
 
15
- def singleton_method_added(name)
16
- MethodDecorator.new(name, true, self).call
17
- super
18
- end
14
+ def singleton_method_added(name)
15
+ MethodDecorator.new(name, true, self).call
16
+ super
19
17
  end
20
18
 
21
19
  def doc(str)
@@ -38,11 +38,6 @@ class Ree::PackageLoader
38
38
  @loaded_packages[name] = true
39
39
  package = @packages_store.get(name)
40
40
 
41
- if package.dir.nil?
42
- package.set_schema_loaded
43
- return package
44
- end
45
-
46
41
  if !package
47
42
  raise Ree::Error.new(
48
43
  "Package :#{name} was not found. Did you mistype the name? Run `ree gen.packages_json` to update Packages.schema.json",
@@ -50,6 +45,11 @@ class Ree::PackageLoader
50
45
  )
51
46
  end
52
47
 
48
+ if package.dir.nil?
49
+ package.set_schema_loaded
50
+ return package
51
+ end
52
+
53
53
  not_loaded = Set.new(
54
54
  [name, package.deps.map(&:name)]
55
55
  .uniq
@@ -46,7 +46,7 @@ class Ree::PackageSchemaLoader
46
46
  # @param [Nilor[Ree::Package]] existing_package Loaded package
47
47
  # @return [Ree::Package]
48
48
  def call(abs_schema_path, existing_package = nil)
49
- if !File.exists?(abs_schema_path)
49
+ if !File.exist?(abs_schema_path)
50
50
  raise Ree::Error.new("File not found: #{abs_schema_path}", :invalid_package_schema)
51
51
  end
52
52
 
@@ -6,7 +6,7 @@ class Ree::PackagesDetector
6
6
  # @param [String] dir Packages root dir
7
7
  # @return [ArrayOf[{name: String, entry_path: String, package_schema_path: String, gem_name: Nilor[String]}]]
8
8
  def call(dir, gem_name = nil)
9
- if !Dir.exists?(dir)
9
+ if !Dir.exist?(dir)
10
10
  raise Ree::Error.new("dir does not exist: #{dir}", :invalid_dir)
11
11
  end
12
12
 
@@ -22,7 +22,7 @@ class Ree::PackagesDetector
22
22
  name = package_schema_path.split('/')[-2]
23
23
  entry_path = Ree::PathHelper.package_entry_path(package_schema_path)
24
24
 
25
- if !File.exists?(File.join(dir, entry_path))
25
+ if !File.exist?(File.join(dir, entry_path))
26
26
  Ree.logger.error("Entry file does not exist for '#{name}' package: #{entry_path}")
27
27
  end
28
28
 
@@ -25,7 +25,7 @@ class Ree::PackagesSchemaLoader
25
25
  # @param Nilor[Ree::PackagesStore] packages_store Existing packages store
26
26
  # @return [Ree::PackagesStore]
27
27
  def call(abs_schema_path, packages_store = nil, gem_name = nil)
28
- if !File.exists?(abs_schema_path)
28
+ if !File.exist?(abs_schema_path)
29
29
  raise Ree::Error.new("File not found: #{abs_schema_path}", :invalid_packages_schema)
30
30
  end
31
31
 
@@ -165,10 +165,10 @@ class Ree::ObjectDsl
165
165
  Ree::PACKAGE, path
166
166
  )
167
167
 
168
- if !File.exists?(file_path)
168
+ if !File.exist?(file_path)
169
169
  file_path = "#{file_path}.rb"
170
170
 
171
- if !File.exists?(file_path)
171
+ if !File.exist?(file_path)
172
172
  raise_error("Unable to link '#{path}'. File not found #{file_path}")
173
173
  end
174
174
  end
@@ -223,7 +223,7 @@ class Ree::ObjectDsl
223
223
  raise Ree::Error.new("Mount as should be one of #{MOUNT_AS.inspect}", :invalid_dsl_usage)
224
224
  end
225
225
 
226
- object_name_from_path = if File.exists?(path) && !Ree.irb_mode?
226
+ object_name_from_path = if File.exist?(path) && !Ree.irb_mode?
227
227
  File.basename(path, ".*").to_sym
228
228
  end
229
229
 
@@ -12,11 +12,11 @@ def package_require(path)
12
12
  Ree::PathHelper.abs_package_module_dir(package), list.join('/')
13
13
  )
14
14
 
15
- if !File.exists?(path)
15
+ if !File.exist?(path)
16
16
  path = path + '.rb'
17
17
  end
18
18
 
19
- if !File.exists?(path)
19
+ if !File.exist?(path)
20
20
  raise Ree::Error.new("file not found: #{path}")
21
21
  end
22
22
 
@@ -37,8 +37,8 @@ def package_file_exists?(path)
37
37
  Ree::PathHelper.abs_package_module_dir(package), list.join('/')
38
38
  )
39
39
 
40
- return true if File.exists?(path)
40
+ return true if File.exist?(path)
41
41
 
42
42
  path = path + '.rb'
43
- File.exists?(path)
43
+ File.exist?(path)
44
44
  end
@@ -78,7 +78,7 @@ class Ree::PackagesFacade
78
78
  if package.dir
79
79
  schema_path = Ree::PathHelper.abs_package_schema_path(package)
80
80
 
81
- if !File.exists?(schema_path)
81
+ if !File.exist?(schema_path)
82
82
  raise Ree::Error.new("File does not exist: #{schema_path}", :invalid_path)
83
83
  end
84
84
 
@@ -101,7 +101,7 @@ class Ree::PackagesFacade
101
101
  if package.dir
102
102
  schema_path = Ree::PathHelper.abs_package_schema_path(package)
103
103
 
104
- if !File.exists?(schema_path)
104
+ if !File.exist?(schema_path)
105
105
  raise Ree::Error.new("File does not exist: #{schema_path}", :invalid_path)
106
106
  end
107
107
 
@@ -126,7 +126,7 @@ class Ree::PackagesFacade
126
126
 
127
127
  schema_path = Ree::PathHelper.abs_object_schema_path(object)
128
128
 
129
- if !File.exists?(schema_path)
129
+ if !File.exist?(schema_path)
130
130
  only_dir_path = schema_path.split('/')[0..-2]
131
131
  FileUtils.mkdir_p(File.join(only_dir_path))
132
132
  end
@@ -80,7 +80,7 @@ class Ree::TemplateHandler
80
80
  rendered_abs_path = Ree::TemplateRenderer.handle(get_destination_path(path), @locals)
81
81
  rendered_rel_path = Pathname.new(rendered_abs_path).relative_path_from Pathname.new(project_path)
82
82
 
83
- if File.file?(rendered_abs_path) && File.exists?(rendered_abs_path)
83
+ if File.file?(rendered_abs_path) && File.exist?(rendered_abs_path)
84
84
  @stdout.puts "Warning! #{rendered_rel_path} already exists. Skipping file creation..."
85
85
  next
86
86
  end
data/lib/ree/link_dsl.rb CHANGED
@@ -107,10 +107,10 @@ module Ree::LinkDSL
107
107
  Ree::PACKAGE, path
108
108
  )
109
109
 
110
- if !File.exists?(file_path)
110
+ if !File.exist?(file_path)
111
111
  file_path = "#{file_path}.rb"
112
112
 
113
- if !File.exists?(file_path)
113
+ if !File.exist?(file_path)
114
114
  _raise_error("Unable to link '#{path}'. File not found #{file_path}")
115
115
  end
116
116
  end
@@ -26,7 +26,7 @@ class Ree::TemplateDetector
26
26
  def template_file_path(template_name, relative_path)
27
27
  file_path = [detect_template_folder(template_name), DEFAULT_TEMPLATES_DIRECTORY]
28
28
  .map {|folder| File.join(folder, relative_path)}
29
- .detect {|file| File.exists?(file)}
29
+ .detect {|file| File.exist?(file)}
30
30
 
31
31
  raise Ree::Error.new('Template does not exist') if file_path.nil?
32
32
 
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.9"
4
+ VERSION = "1.0.11"
5
5
  end
data/lib/ree.rb CHANGED
@@ -144,7 +144,7 @@ module Ree
144
144
  def init(dir, irb: false)
145
145
  check_arg(dir, :dir, String)
146
146
 
147
- if !Dir.exists?(dir)
147
+ if !Dir.exist?(dir)
148
148
  raise Ree::Error.new("Dir does not exist: #{dir}", :invalid_root_dir)
149
149
  end
150
150
 
@@ -153,7 +153,7 @@ module Ree
153
153
 
154
154
  ree_setup_path = File.join(@root_dir, REE_SETUP)
155
155
 
156
- if File.exists?(ree_setup_path)
156
+ if File.exist?(ree_setup_path)
157
157
  require(ree_setup_path)
158
158
  end
159
159
 
@@ -192,7 +192,7 @@ module Ree
192
192
  raise Ree::Error.new("Ree already registered gem `#{name}`", :duplicate_gem)
193
193
  end
194
194
 
195
- if !Dir.exists?(dir)
195
+ if !Dir.exist?(dir)
196
196
  raise Ree::Error.new("Dir does not exist: #{dir}", :invalid_gem_dir)
197
197
  end
198
198
 
@@ -201,7 +201,7 @@ module Ree
201
201
  gem_dir = Pathname.new(packages_schema_path).dirname.to_s
202
202
  ree_setup_path = File.join(gem_dir, REE_SETUP)
203
203
 
204
- if File.exists?(ree_setup_path)
204
+ if File.exist?(ree_setup_path)
205
205
  require(ree_setup_path)
206
206
  end
207
207
 
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.9
4
+ version: 1.0.11
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-10-30 00:00:00.000000000 Z
11
+ date: 2022-11-23 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