zapata 0.1.6 → 1.0.0
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 +5 -5
- data/.gitignore +7 -0
- data/.rspec +1 -0
- data/.rubocop.yml +35 -0
- data/.travis.yml +13 -19
- data/Appraisals +11 -0
- data/Gemfile +2 -0
- data/README.md +1 -2
- data/Rakefile +2 -1
- data/bin/zapata +6 -29
- data/gemfiles/5.2.gemfile +14 -0
- data/gemfiles/6.0.gemfile +14 -0
- data/lib/zapata.rb +22 -22
- data/lib/zapata/analyst.rb +2 -0
- data/lib/zapata/cli.rb +23 -0
- data/lib/zapata/core.rb +11 -0
- data/lib/zapata/core/collector.rb +2 -0
- data/lib/zapata/core/loader.rb +6 -4
- data/lib/zapata/core/reader.rb +2 -0
- data/lib/zapata/core/writer.rb +2 -0
- data/lib/zapata/db.rb +2 -0
- data/lib/zapata/diver.rb +32 -28
- data/lib/zapata/predictor.rb +10 -0
- data/lib/zapata/predictor/args.rb +2 -0
- data/lib/zapata/predictor/chooser.rb +2 -0
- data/lib/zapata/predictor/value.rb +7 -3
- data/lib/zapata/primitive.rb +28 -0
- data/lib/zapata/primitive/arg.rb +2 -0
- data/lib/zapata/primitive/array.rb +2 -0
- data/lib/zapata/primitive/base.rb +6 -4
- data/lib/zapata/primitive/basic.rb +2 -0
- data/lib/zapata/primitive/casgn.rb +2 -0
- data/lib/zapata/primitive/const.rb +2 -0
- data/lib/zapata/primitive/const_send.rb +2 -0
- data/lib/zapata/primitive/def.rb +2 -0
- data/lib/zapata/primitive/defs.rb +3 -1
- data/lib/zapata/primitive/hash.rb +2 -0
- data/lib/zapata/primitive/ivar.rb +2 -0
- data/lib/zapata/primitive/klass.rb +4 -2
- data/lib/zapata/primitive/lvar.rb +2 -0
- data/lib/zapata/primitive/missing.rb +2 -0
- data/lib/zapata/primitive/modul.rb +2 -0
- data/lib/zapata/primitive/nil.rb +2 -0
- data/lib/zapata/primitive/optarg.rb +2 -0
- data/lib/zapata/primitive/raw.rb +2 -0
- data/lib/zapata/primitive/send.rb +4 -1
- data/lib/zapata/primitive/sklass.rb +3 -1
- data/lib/zapata/primitive/var.rb +2 -0
- data/lib/zapata/printer.rb +2 -1
- data/lib/zapata/rzpec/runner.rb +3 -1
- data/lib/zapata/rzpec/writer.rb +5 -3
- data/lib/zapata/version.rb +3 -1
- data/spec/array_spec.rb +6 -6
- data/spec/definition_spec.rb +5 -5
- data/spec/generation_spec.rb +2 -36
- data/spec/hash_spec.rb +8 -8
- data/spec/klass_types_spec.rb +6 -6
- data/spec/send_spec.rb +6 -6
- data/spec/simple_types_spec.rb +6 -6
- data/spec/spec_helper.rb +18 -76
- data/spec/support/rails_test_app/app/assets/config/manifest.js +3 -0
- data/spec/support/rails_test_app/app/models/robot_to_test.rb +4 -4
- data/spec/support/rails_test_app/app/models/test_send.rb +1 -1
- data/spec/support/rails_test_app/config.ru +1 -1
- data/spec/support/rails_test_app/config/initializers/cookies_serializer.rb +1 -1
- data/spec/support/rails_test_app/spec/models/robot_to_test_spec.rb +2 -2
- data/spec/support/rails_test_app/spec/models/test_hash_spec.rb +1 -1
- data/spec/support/rails_test_app/spec/rails_helper.rb +3 -3
- data/spec/support/rails_test_app/spec/spec_helper.rb +58 -60
- data/zapata.gemspec +18 -18
- metadata +58 -101
- data/spec/support/rails_test_app/.gitignore +0 -16
- data/spec/support/rails_test_app/.rspec +0 -3
- data/spec/support/rails_test_app/Gemfile +0 -49
- data/spec/support/rails_test_app/test/controllers/.keep +0 -0
- data/spec/support/rails_test_app/test/fixtures/.keep +0 -0
- data/spec/support/rails_test_app/test/helpers/.keep +0 -0
- data/spec/support/rails_test_app/test/integration/.keep +0 -0
- data/spec/support/rails_test_app/test/mailers/.keep +0 -0
- data/spec/support/rails_test_app/test/models/.keep +0 -0
- data/spec/support/rails_test_app/test/test_helper.rb +0 -13
- data/spec/support/rails_test_app/vendor/assets/javascripts/.keep +0 -0
- data/spec/support/rails_test_app/vendor/assets/stylesheets/.keep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0b1ea03ef4de0c3815e64a5cde304b8659c8e1a2663e7c9704700429fa2810c9
|
4
|
+
data.tar.gz: b8eedb3037467a77a401db9479b26c999147534d7650111184093e5a35957208
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb60553b3987fe0b49b80414f8723b2c4dbac31c1b5c67c44361b07fe9ffebfce066fa3ee47a76f98ab1ef7b8559c2fb6763d60888048ed053b729d14949528a
|
7
|
+
data.tar.gz: 6224d6f4fd414d2a7e6bf0088b1fde660648d8b2fcc146c78d00ddce5629d6ae89953a071f6ee457f6c57e5e09fc8cfe4f1f1adfbe0b79b850f70f48672fa4f9
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
Exclude:
|
4
|
+
- 'spec/support/rails_test_app/**/*'
|
5
|
+
|
6
|
+
Style/Documentation:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Layout/ParameterAlignment:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: with_fixed_indentation
|
12
|
+
|
13
|
+
Layout/MultilineOperationIndentation:
|
14
|
+
Enabled: true
|
15
|
+
EnforcedStyle: indented
|
16
|
+
|
17
|
+
Layout/MultilineMethodCallIndentation:
|
18
|
+
Enabled: true
|
19
|
+
EnforcedStyle: indented
|
20
|
+
|
21
|
+
Layout/CaseIndentation:
|
22
|
+
Enabled: true
|
23
|
+
EnforcedStyle: end
|
24
|
+
|
25
|
+
Layout/EndAlignment:
|
26
|
+
Enabled: true
|
27
|
+
EnforcedStyleAlignWith: variable
|
28
|
+
|
29
|
+
Style/EmptyMethod:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Metrics/BlockLength:
|
33
|
+
Exclude:
|
34
|
+
- 'spec/**/*_spec.rb'
|
35
|
+
- 'zapata.gemspec'
|
data/.travis.yml
CHANGED
@@ -1,23 +1,17 @@
|
|
1
1
|
language: ruby
|
2
|
-
|
3
|
-
bundler_args: --without development
|
4
|
-
|
5
2
|
script: script/test
|
6
|
-
gemfile: spec/support/rails_test_app/Gemfile
|
7
|
-
|
8
3
|
rvm:
|
9
|
-
- 2.
|
10
|
-
- 2.
|
11
|
-
-
|
12
|
-
-
|
13
|
-
-
|
14
|
-
|
4
|
+
- 2.3.8
|
5
|
+
- 2.4.8
|
6
|
+
- 2.5.7
|
7
|
+
- 2.6.5
|
8
|
+
- 2.7.0
|
9
|
+
gemfile:
|
10
|
+
- gemfiles/5.2.gemfile
|
11
|
+
- gemfiles/6.0.gemfile
|
15
12
|
matrix:
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
branches:
|
22
|
-
only:
|
23
|
-
- master
|
13
|
+
exclude:
|
14
|
+
- rvm: 2.3.8
|
15
|
+
gemfile: gemfiles/6.0.gemfile
|
16
|
+
- rvm: 2.4.8
|
17
|
+
gemfile: gemfiles/6.0.gemfile
|
data/Appraisals
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,6 @@ themselves.
|
|
7
7
|
[][travis]
|
8
8
|
[][gemnasium]
|
9
9
|
[][coveralls]
|
10
|
-
[][codeclimate]
|
11
10
|
|
12
11
|

|
13
12
|
|
@@ -208,7 +207,7 @@ Also - thank you [@edgibbs](https://github.com/edgibbs), for being the early con
|
|
208
207
|
[@morron](https://github.com/morron) - for caring.
|
209
208
|
|
210
209
|
## Copyright
|
211
|
-
Copyright (c) 2014-
|
210
|
+
Copyright (c) 2014-2018 Justas, Andrew, Ed, Dmitry, Domas.
|
212
211
|
See [LICENSE](LICENSE) for details.
|
213
212
|
|
214
213
|
[rubygems]: https://rubygems.org/gems/zapata
|
data/Rakefile
CHANGED
data/bin/zapata
CHANGED
@@ -1,32 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
2
|
+
# frozen_string_literal: true
|
4
3
|
|
5
|
-
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'zapata'
|
7
|
+
require 'zapata/cli'
|
6
8
|
|
7
|
-
|
8
|
-
-s, --single option to skip app/models analysis"
|
9
|
-
|
10
|
-
slop = Slop.new(help: true, banner: true) do
|
11
|
-
banner('Usage: zapata [options]')
|
12
|
-
on :v, :version, 'Print version.' do
|
13
|
-
puts "Your version is #{Zapata::VERSION}"
|
14
|
-
end
|
15
|
-
|
16
|
-
command('generate', description: description_of_generate) do
|
17
|
-
on(:s, :single, "Does not analyze 'app/models'", banner: true)
|
18
|
-
|
19
|
-
run do |opts, args|
|
20
|
-
Zapata::Revolutionist.generate_with_friendly_output(args, opts)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
run do |opts, args|
|
25
|
-
if args.present?
|
26
|
-
Zapata::Revolutionist.generate_with_friendly_output(args, opts)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
puts slop.help if ARGV.empty?
|
32
|
-
slop.parse
|
9
|
+
Zapata::CLI.start(ARGV)
|
data/lib/zapata.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'parser/current'
|
2
4
|
require 'unparser'
|
5
|
+
require 'tempfile'
|
3
6
|
require 'rails'
|
4
|
-
require 'require_all'
|
5
|
-
require 'file/temp'
|
6
7
|
require 'open3'
|
7
8
|
require 'rspec'
|
8
9
|
require 'memoist'
|
9
|
-
require 'slop'
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
require_relative 'zapata/core'
|
12
|
+
require_relative 'zapata/predictor'
|
13
|
+
require_relative 'zapata/primitive'
|
14
|
+
require_relative 'zapata/rzpec/runner'
|
15
|
+
require_relative 'zapata/rzpec/writer'
|
15
16
|
require_relative 'zapata/analyst'
|
16
17
|
require_relative 'zapata/diver'
|
17
18
|
require_relative 'zapata/db'
|
@@ -23,15 +24,13 @@ module Zapata
|
|
23
24
|
class << self
|
24
25
|
attr_accessor :analysis, :analysis_as_array
|
25
26
|
|
26
|
-
def generate_with_friendly_output(
|
27
|
-
|
28
|
-
spec_filename = Zapata::Revolutionist.generate(file,
|
29
|
-
single: single?(opts, args))
|
27
|
+
def generate_with_friendly_output(filename:, single: false)
|
28
|
+
spec_filename = Zapata::Revolutionist.generate(filename: filename, single: single)
|
30
29
|
puts "Its done, comrades. File #{spec_filename} was generated."
|
31
30
|
end
|
32
31
|
|
33
|
-
def generate(filename
|
34
|
-
dirs = single ? [] : %w
|
32
|
+
def generate(filename:, single: false)
|
33
|
+
dirs = single ? [] : %w[app/models]
|
35
34
|
file_list = Core::Collector.expand_dirs_to_files(dirs)
|
36
35
|
new(file_list).generate_rspec_for(filename, spec_filename(filename))
|
37
36
|
end
|
@@ -65,8 +64,8 @@ module Zapata
|
|
65
64
|
end
|
66
65
|
end
|
67
66
|
|
68
|
-
def adjusted_current(
|
69
|
-
|
67
|
+
def adjusted_current(index, total)
|
68
|
+
(index + 1).to_s.rjust(total.size)
|
70
69
|
end
|
71
70
|
|
72
71
|
def generate_rspec_for(filename, spec_filename)
|
@@ -80,15 +79,16 @@ module Zapata
|
|
80
79
|
|
81
80
|
global_analysis = Revolutionist.analysis_as_array
|
82
81
|
# first run
|
83
|
-
|
84
|
-
|
82
|
+
Tempfile.open('spec') do |tempfile|
|
83
|
+
RZpec::Writer.new(tempfile.path, code, self.class.analysis[filename], global_analysis)
|
85
84
|
|
86
|
-
|
87
|
-
|
85
|
+
save_spec_file(tempfile.path, spec_filename)
|
86
|
+
spec_analysis = RZpec::Runner.new(spec_filename)
|
88
87
|
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
# second run with RSpec results
|
89
|
+
RZpec::Writer.new(tempfile.path, code, self.class.analysis[filename], global_analysis, spec_analysis)
|
90
|
+
save_spec_file(tempfile.path, spec_filename)
|
91
|
+
end
|
92
92
|
end
|
93
93
|
|
94
94
|
def save_spec_file(tmp_spec_filename, spec_filename)
|
data/lib/zapata/analyst.rb
CHANGED
data/lib/zapata/cli.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require_relative 'version'
|
5
|
+
|
6
|
+
module Zapata
|
7
|
+
class CLI < Thor
|
8
|
+
desc 'generate FILENAME', 'Generate spec file for model'
|
9
|
+
option :single, type: :boolean,
|
10
|
+
desc: 'Skip app/models analysis',
|
11
|
+
aliases: :s
|
12
|
+
def generate(filename)
|
13
|
+
Zapata::Revolutionist.generate_with_friendly_output(
|
14
|
+
filename: filename, single: options[:single]
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'version', 'Shows zapata version'
|
19
|
+
def version
|
20
|
+
puts "v#{Zapata::VERSION}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/zapata/core.rb
ADDED
data/lib/zapata/core/loader.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Zapata
|
2
4
|
module Core
|
3
5
|
class Loader
|
@@ -7,11 +9,11 @@ module Zapata
|
|
7
9
|
end
|
8
10
|
|
9
11
|
def rails_helper_path
|
10
|
-
File.expand_path("#{spec_dir}/rails_helper",
|
12
|
+
File.expand_path("#{spec_dir}/rails_helper", __FILE__)
|
11
13
|
end
|
12
14
|
|
13
15
|
def spec_helper_path
|
14
|
-
File.expand_path("#{spec_dir}/spec_helper",
|
16
|
+
File.expand_path("#{spec_dir}/spec_helper", __FILE__)
|
15
17
|
end
|
16
18
|
|
17
19
|
def helper_name
|
@@ -27,7 +29,7 @@ module Zapata
|
|
27
29
|
def full_helper_path
|
28
30
|
paths = {
|
29
31
|
rails_helper: rails_helper_path,
|
30
|
-
spec_helper: spec_helper_path
|
32
|
+
spec_helper: spec_helper_path
|
31
33
|
}.freeze
|
32
34
|
|
33
35
|
paths[helper_name.to_sym]
|
@@ -35,7 +37,7 @@ module Zapata
|
|
35
37
|
|
36
38
|
def load_spec_helper
|
37
39
|
$LOAD_PATH << spec_dir
|
38
|
-
require
|
40
|
+
require helper_name.to_s
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
data/lib/zapata/core/reader.rb
CHANGED
data/lib/zapata/core/writer.rb
CHANGED
data/lib/zapata/db.rb
CHANGED
data/lib/zapata/diver.rb
CHANGED
@@ -1,37 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Zapata
|
2
|
-
RETURN_TYPES = %i
|
3
|
-
FINAL_TYPES = Zapata::RETURN_TYPES + %i
|
4
|
-
DIVE_TYPES = %i
|
5
|
-
|
6
|
-
|
7
|
-
ASSIGN_TYPES = %i
|
8
|
-
DEF_TYPES = %i
|
9
|
-
HARD_TYPES = %i
|
10
|
-
|
4
|
+
RETURN_TYPES = %i[missing raw const_send sym float str int ivar true false const nil].freeze
|
5
|
+
FINAL_TYPES = Zapata::RETURN_TYPES + %i[array hash]
|
6
|
+
DIVE_TYPES = %i[args begin block defined? nth_ref splat kwsplat class
|
7
|
+
block_pass sclass masgn or and irange erange when and
|
8
|
+
return array kwbegin yield while dstr ensure pair].freeze
|
9
|
+
ASSIGN_TYPES = %i[ivasgn lvasgn or_asgn casgn optarg].freeze
|
10
|
+
DEF_TYPES = %i[def defs].freeze
|
11
|
+
HARD_TYPES = %i[if dsym resbody mlhs next self break zsuper
|
12
|
+
super retry rescue match_with_lvasgn case op_asgn regopt regexp].freeze
|
11
13
|
TYPES_BY_SEARCH_FOR = {
|
12
|
-
klass: %i
|
14
|
+
klass: %i[class],
|
13
15
|
var: ASSIGN_TYPES,
|
14
16
|
def: DEF_TYPES,
|
15
|
-
send: %i
|
16
|
-
}
|
17
|
+
send: %i[send]
|
18
|
+
}.freeze
|
17
19
|
|
18
20
|
PRIMITIVE_TYPES = {
|
19
|
-
Def: %i
|
20
|
-
Defs: %i
|
21
|
-
Send: %i
|
22
|
-
Array: %i
|
23
|
-
Hash: %i
|
24
|
-
Ivar: %i
|
25
|
-
Lvar: %i
|
26
|
-
Klass: %i
|
27
|
-
Sklass: %i
|
28
|
-
Modul: %i
|
29
|
-
Const: %i
|
30
|
-
Optarg: %i
|
31
|
-
Arg: %i
|
21
|
+
Def: %i[def],
|
22
|
+
Defs: %i[defs],
|
23
|
+
Send: %i[send],
|
24
|
+
Array: %i[args array],
|
25
|
+
Hash: %i[hash],
|
26
|
+
Ivar: %i[ivar],
|
27
|
+
Lvar: %i[lvar],
|
28
|
+
Klass: %i[class],
|
29
|
+
Sklass: %i[sclass],
|
30
|
+
Modul: %i[module],
|
31
|
+
Const: %i[const],
|
32
|
+
Optarg: %i[optarg],
|
33
|
+
Arg: %i[arg],
|
32
34
|
Basic: RETURN_TYPES,
|
33
|
-
Casgn: %i
|
34
|
-
Var: ASSIGN_TYPES
|
35
|
+
Casgn: %i[casgn],
|
36
|
+
Var: ASSIGN_TYPES
|
35
37
|
}.freeze
|
36
38
|
|
37
39
|
class Diver
|
@@ -45,7 +47,9 @@ module Zapata
|
|
45
47
|
|
46
48
|
def dive(code)
|
47
49
|
return Primitive::Nil.new unless code
|
48
|
-
|
50
|
+
if HARD_TYPES.include?(code.type)
|
51
|
+
return Primitive::Raw.new(:missing, :hard_type)
|
52
|
+
end
|
49
53
|
|
50
54
|
if (klass = primitive_klass(code))
|
51
55
|
result = klass.new(code)
|