zapata 0.1.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +7 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +35 -0
  5. data/.travis.yml +13 -19
  6. data/Appraisals +11 -0
  7. data/Gemfile +2 -0
  8. data/README.md +1 -2
  9. data/Rakefile +2 -1
  10. data/bin/zapata +6 -29
  11. data/gemfiles/5.2.gemfile +14 -0
  12. data/gemfiles/6.0.gemfile +14 -0
  13. data/lib/zapata.rb +22 -22
  14. data/lib/zapata/analyst.rb +2 -0
  15. data/lib/zapata/cli.rb +23 -0
  16. data/lib/zapata/core.rb +11 -0
  17. data/lib/zapata/core/collector.rb +2 -0
  18. data/lib/zapata/core/loader.rb +6 -4
  19. data/lib/zapata/core/reader.rb +2 -0
  20. data/lib/zapata/core/writer.rb +2 -0
  21. data/lib/zapata/db.rb +2 -0
  22. data/lib/zapata/diver.rb +32 -28
  23. data/lib/zapata/predictor.rb +10 -0
  24. data/lib/zapata/predictor/args.rb +2 -0
  25. data/lib/zapata/predictor/chooser.rb +2 -0
  26. data/lib/zapata/predictor/value.rb +7 -3
  27. data/lib/zapata/primitive.rb +28 -0
  28. data/lib/zapata/primitive/arg.rb +2 -0
  29. data/lib/zapata/primitive/array.rb +2 -0
  30. data/lib/zapata/primitive/base.rb +6 -4
  31. data/lib/zapata/primitive/basic.rb +2 -0
  32. data/lib/zapata/primitive/casgn.rb +2 -0
  33. data/lib/zapata/primitive/const.rb +2 -0
  34. data/lib/zapata/primitive/const_send.rb +2 -0
  35. data/lib/zapata/primitive/def.rb +2 -0
  36. data/lib/zapata/primitive/defs.rb +3 -1
  37. data/lib/zapata/primitive/hash.rb +2 -0
  38. data/lib/zapata/primitive/ivar.rb +2 -0
  39. data/lib/zapata/primitive/klass.rb +4 -2
  40. data/lib/zapata/primitive/lvar.rb +2 -0
  41. data/lib/zapata/primitive/missing.rb +2 -0
  42. data/lib/zapata/primitive/modul.rb +2 -0
  43. data/lib/zapata/primitive/nil.rb +2 -0
  44. data/lib/zapata/primitive/optarg.rb +2 -0
  45. data/lib/zapata/primitive/raw.rb +2 -0
  46. data/lib/zapata/primitive/send.rb +4 -1
  47. data/lib/zapata/primitive/sklass.rb +3 -1
  48. data/lib/zapata/primitive/var.rb +2 -0
  49. data/lib/zapata/printer.rb +2 -1
  50. data/lib/zapata/rzpec/runner.rb +3 -1
  51. data/lib/zapata/rzpec/writer.rb +5 -3
  52. data/lib/zapata/version.rb +3 -1
  53. data/spec/array_spec.rb +6 -6
  54. data/spec/definition_spec.rb +5 -5
  55. data/spec/generation_spec.rb +2 -36
  56. data/spec/hash_spec.rb +8 -8
  57. data/spec/klass_types_spec.rb +6 -6
  58. data/spec/send_spec.rb +6 -6
  59. data/spec/simple_types_spec.rb +6 -6
  60. data/spec/spec_helper.rb +18 -76
  61. data/spec/support/rails_test_app/app/assets/config/manifest.js +3 -0
  62. data/spec/support/rails_test_app/app/models/robot_to_test.rb +4 -4
  63. data/spec/support/rails_test_app/app/models/test_send.rb +1 -1
  64. data/spec/support/rails_test_app/config.ru +1 -1
  65. data/spec/support/rails_test_app/config/initializers/cookies_serializer.rb +1 -1
  66. data/spec/support/rails_test_app/spec/models/robot_to_test_spec.rb +2 -2
  67. data/spec/support/rails_test_app/spec/models/test_hash_spec.rb +1 -1
  68. data/spec/support/rails_test_app/spec/rails_helper.rb +3 -3
  69. data/spec/support/rails_test_app/spec/spec_helper.rb +58 -60
  70. data/zapata.gemspec +18 -18
  71. metadata +58 -101
  72. data/spec/support/rails_test_app/.gitignore +0 -16
  73. data/spec/support/rails_test_app/.rspec +0 -3
  74. data/spec/support/rails_test_app/Gemfile +0 -49
  75. data/spec/support/rails_test_app/test/controllers/.keep +0 -0
  76. data/spec/support/rails_test_app/test/fixtures/.keep +0 -0
  77. data/spec/support/rails_test_app/test/helpers/.keep +0 -0
  78. data/spec/support/rails_test_app/test/integration/.keep +0 -0
  79. data/spec/support/rails_test_app/test/mailers/.keep +0 -0
  80. data/spec/support/rails_test_app/test/models/.keep +0 -0
  81. data/spec/support/rails_test_app/test/test_helper.rb +0 -13
  82. data/spec/support/rails_test_app/vendor/assets/javascripts/.keep +0 -0
  83. data/spec/support/rails_test_app/vendor/assets/stylesheets/.keep +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c3475c7d502d650c69c037d6562e5d1338bfb9ce
4
- data.tar.gz: 0984b1da3314fa05a9121bc2968125434ed965fd
2
+ SHA256:
3
+ metadata.gz: 0b1ea03ef4de0c3815e64a5cde304b8659c8e1a2663e7c9704700429fa2810c9
4
+ data.tar.gz: b8eedb3037467a77a401db9479b26c999147534d7650111184093e5a35957208
5
5
  SHA512:
6
- metadata.gz: fac18c00c0f6b27eabe027d7fc4c54559e3d6534ee2d4f6c9d7a5ad1ec7167e1076ee8035420325e4951bcf0fcf33402572567b1453541526837a0c19432c880
7
- data.tar.gz: 1b377f33bd276784085e940f86da246213eea2f52b0e33ea46f947de838887dd7edb7c2a6da22e9e3d872a8457a08320b988c81e19a5bce1fee5688b46bbac0f
6
+ metadata.gz: fb60553b3987fe0b49b80414f8723b2c4dbac31c1b5c67c44361b07fe9ffebfce066fa3ee47a76f98ab1ef7b8559c2fb6763d60888048ed053b729d14949528a
7
+ data.tar.gz: 6224d6f4fd414d2a7e6bf0088b1fde660648d8b2fcc146c78d00ddce5629d6ae89953a071f6ee457f6c57e5e09fc8cfe4f1f1adfbe0b79b850f70f48672fa4f9
data/.gitignore CHANGED
@@ -13,3 +13,10 @@
13
13
  *.o
14
14
  *.a
15
15
  mkmf.log
16
+
17
+ .rspec_status
18
+ gemfiles/*.lock
19
+ spec/support/rails_test_app/db/*.sqlite3
20
+ spec/support/rails_test_app/db/*.sqlite3-journal
21
+ spec/support/rails_test_app/log/*.log
22
+ spec/support/rails_test_app/tmp/
data/.rspec CHANGED
@@ -1,3 +1,4 @@
1
1
  --color
2
2
  --warnings
3
3
  --require spec_helper
4
+ --pattern "spec/*_spec.rb"
@@ -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'
@@ -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.0.0
10
- - 2.1.0
11
- - ruby-head
12
- - jruby-head
13
- - rbx
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
- allow_failures:
17
- - rvm: ruby-head
18
- - rvm: jruby-head
19
- - rvm: rbx
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
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise '5.2' do
4
+ gem 'rails', '~> 5.2.0'
5
+ gem 'sqlite3'
6
+ end
7
+
8
+ appraise '6.0' do
9
+ gem 'rails', '~> 6.0.0'
10
+ gem 'sqlite3'
11
+ end
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in zapata.gemspec
data/README.md CHANGED
@@ -7,7 +7,6 @@ themselves.
7
7
  [![Build Status](http://img.shields.io/travis/Nedomas/zapata.svg?style=flat)][travis]
8
8
  [![Dependency Status](http://img.shields.io/gemnasium/Nedomas/zapata.svg?style=flat)][gemnasium]
9
9
  [![Coverage Status](http://img.shields.io/coveralls/Nedomas/zapata/master.svg?style=flat)][coveralls]
10
- [![Code Climate](http://img.shields.io/codeclimate/github/Nedomas/zapata.svg?style=flat)][codeclimate]
11
10
 
12
11
  ![Emiliano Zapata](https://cloud.githubusercontent.com/assets/1877286/3753719/af3bfec2-1814-11e4-8790-242c2b26a8e9.jpg)
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-2016 Justas, Andrew, Ed, Dmitry, Domas.
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
@@ -1,2 +1,3 @@
1
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
2
 
3
+ require 'bundler/gem_tasks'
data/bin/zapata CHANGED
@@ -1,32 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
2
+ # frozen_string_literal: true
4
3
 
5
- require_relative '../lib/zapata'
4
+ require 'rubygems'
5
+ require 'bundler/setup'
6
+ require 'zapata'
7
+ require 'zapata/cli'
6
8
 
7
- description_of_generate = "'zapata generate <filename>'
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)
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file was generated by Appraisal
4
+
5
+ source 'https://rubygems.org'
6
+
7
+ gem 'rails', '~> 5.2.0'
8
+ gem 'sqlite3'
9
+
10
+ group :test do
11
+ gem 'coveralls', require: false
12
+ end
13
+
14
+ gemspec path: '../'
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file was generated by Appraisal
4
+
5
+ source 'https://rubygems.org'
6
+
7
+ gem 'rails', '~> 6.0.0'
8
+ gem 'sqlite3'
9
+
10
+ group :test do
11
+ gem 'coveralls', require: false
12
+ end
13
+
14
+ gemspec path: '../'
@@ -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
- require_rel 'zapata/core'
12
- require_rel 'zapata/predictor'
13
- require_rel 'zapata/primitive'
14
- require_rel 'zapata/rzpec'
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(args, opts)
27
- file = args.shift
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, single: false)
34
- dirs = single ? [] : %w(app/models)
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(i, total)
69
- "#{i + 1}".rjust(total.size)
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
- tmp_spec_filename = File::Temp.new(false).path
84
- RZpec::Writer.new(tmp_spec_filename, code, self.class.analysis[filename], global_analysis)
82
+ Tempfile.open('spec') do |tempfile|
83
+ RZpec::Writer.new(tempfile.path, code, self.class.analysis[filename], global_analysis)
85
84
 
86
- save_spec_file(tmp_spec_filename, spec_filename)
87
- spec_analysis = RZpec::Runner.new(spec_filename)
85
+ save_spec_file(tempfile.path, spec_filename)
86
+ spec_analysis = RZpec::Runner.new(spec_filename)
88
87
 
89
- # second run with RSpec results
90
- RZpec::Writer.new(tmp_spec_filename, code, self.class.analysis[filename], global_analysis, spec_analysis)
91
- save_spec_file(tmp_spec_filename, spec_filename)
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)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  class Analyst
3
5
  attr_reader :result
@@ -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
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'core/collector'
4
+ require_relative 'core/loader'
5
+ require_relative 'core/reader'
6
+ require_relative 'core/writer'
7
+
8
+ module Zapata
9
+ module Core
10
+ end
11
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Core
3
5
  class Collector
@@ -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", __FILE__)
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", __FILE__)
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 "#{helper_name}"
40
+ require helper_name.to_s
39
41
  end
40
42
  end
41
43
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Core
3
5
  class Reader
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  module Core
3
5
  class Writer
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
4
  class DB
3
5
  @records = []
@@ -1,37 +1,39 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zapata
2
- RETURN_TYPES = %i(missing raw const_send sym float str int ivar true false const nil)
3
- FINAL_TYPES = Zapata::RETURN_TYPES + %i(array hash)
4
- DIVE_TYPES = %i(args begin block defined? nth_ref splat kwsplat class
5
- block_pass sclass masgn or and irange erange when and
6
- return array kwbegin yield while dstr ensure pair)
7
- ASSIGN_TYPES = %i(ivasgn lvasgn or_asgn casgn optarg)
8
- DEF_TYPES = %i(def defs)
9
- HARD_TYPES = %i(if dsym resbody mlhs next self break zsuper
10
- super retry rescue match_with_lvasgn case op_asgn regopt regexp)
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(class),
14
+ klass: %i[class],
13
15
  var: ASSIGN_TYPES,
14
16
  def: DEF_TYPES,
15
- send: %i(send),
16
- }
17
+ send: %i[send]
18
+ }.freeze
17
19
 
18
20
  PRIMITIVE_TYPES = {
19
- Def: %i(def),
20
- Defs: %i(defs),
21
- Send: %i(send),
22
- Array: %i(args array),
23
- Hash: %i(hash),
24
- Ivar: %i(ivar),
25
- Lvar: %i(lvar),
26
- Klass: %i(class),
27
- Sklass: %i(sclass),
28
- Modul: %i(module),
29
- Const: %i(const),
30
- Optarg: %i(optarg),
31
- Arg: %i(arg),
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(casgn),
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
- return Primitive::Raw.new(:missing, :hard_type) if HARD_TYPES.include?(code.type)
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)