zapata 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: 02ed505b11c49d0937c21dd672d941ddbed166a7
4
- data.tar.gz: 7d8b7e08e587db3711a7883d3b6401164547bde2
3
+ metadata.gz: a623cb9783f185bae4d4111b99219ce93a83539d
4
+ data.tar.gz: a0222512c8e1ca6c334641245a0bf82cab4adca5
5
5
  SHA512:
6
- metadata.gz: 802d1b5d46141a0c76af5daa092d4b026b62032cc54b3df3137a2e00c0443dd218f04b68cc8e7a6d7935addbbd434f20aa46a20083815a2524244212e959dffc
7
- data.tar.gz: af4f6ca0d3cae7de44de60b28dc77b0db1446f3925d32d25eb72280c347c806d06743de2315d9616885112a9766a8c7f9a30e65c82f3e573a39ca3aa3639f5a0
6
+ metadata.gz: 08172f430be1bdad603cb4200e8e8443e459b174e2b4b2958d514c4bca876837994264cbf11329a8e2b595f482c24621f94da4833c212c1da2c569c748db5504
7
+ data.tar.gz: 4f943051fd300cffcef499f29bcfd7936186dde850b5e130132f5418c06275c4ba8dd9e333b24fbfc0c1d96242aa991126c79dd504905e8e4f72c51439bfd0da
@@ -1,12 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.0
3
+ - 2.1.2
4
4
  - 2.0.0
5
- - 1.9.3
6
- - jruby-18mode
7
- - jruby-19mode
8
- - rbx-2
9
- - ruby-head
10
- - jruby-head
11
- - ree
12
5
  script: bundle exec rspec --pattern "spec/*_spec.rb"
6
+ gemfile: spec/support/rails_test_app/Gemfile
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  [![Code Climate](https://codeclimate.com/github/Nedomas/zapata/badges/gpa.svg)](https://codeclimate.com/github/Nedomas/zapata)
2
+ [![Gem Version](https://badge.fury.io/rb/zapata.svg)](http://badge.fury.io/rb/zapata)
3
+ [![Build Status](https://travis-ci.org/Nedomas/zapata.svg?branch=master)](https://travis-ci.org/Nedomas/zapata)
2
4
 
3
5
  # Zapata
4
6
 
@@ -118,6 +120,11 @@ __To be more specific:__
118
120
  For more things it can currently do check
119
121
  https://github.com/Nedomas/zapata/tree/master/spec
120
122
 
123
+ ## Requirements
124
+
125
+ - Ruby 2.0+
126
+ - Rails 3.0+
127
+
121
128
  ## Installation
122
129
 
123
130
  It should be as easy as
@@ -131,16 +138,29 @@ or
131
138
  gem 'zapata', groups: %w(development test)
132
139
  ```
133
140
 
141
+ ## Usage
142
+
134
143
  To use run
135
144
  ```sh
136
145
  zapata generate app/models/model_name.rb
137
146
  ```
138
147
 
148
+ To ignore other files and analyze a single model you want to generate a spec for:
149
+ ```sh
150
+ zapata generate app/models/model_name.rb --single
151
+ ```
152
+
139
153
  ## Collaboration :heart:
140
154
 
141
- I know that code analyzing is a sexy sphere to work on for many developers.
142
- So here it is - a sexy project where you can realize your wet dreams about magic
143
- in Ruby.
155
+ It is encouraged by somehow managing to bring a cake to your house. I promise,
156
+ I will really try.
157
+
158
+ This is a great project to understand language architecture in general. A
159
+ project to let your free and expressionistic side shine through by leaving meta
160
+ hacks and rainbows everywhere.
161
+
162
+ Thank you to everyone who do. I strongly believe that this can make the
163
+ developer job less robotic and more creative.
144
164
 
145
165
  To install, run:
146
166
  ```sh
@@ -44,28 +44,33 @@ module Zapata
44
44
  end
45
45
 
46
46
  def dive(code)
47
- unless code
48
- return Primitive::Nil.new
47
+ return Primitive::Nil.new unless code
48
+ return Primitive::Raw.new(:missing, :hard_type) if HARD_TYPES.include?(code.type)
49
+
50
+ if (klass = primitive_klass(code))
51
+ result = klass.new(code)
52
+ DB.create(result) if search_for_types.include?(code.type)
49
53
  end
50
54
 
51
- current_type = code.type
52
- return Primitive::Raw.new(:missing, :hard_type) if HARD_TYPES.include?(current_type)
55
+ deeper_dives(code)
53
56
 
54
- subklass_pair = PRIMITIVE_TYPES.detect do |_, types|
55
- types.include?(current_type)
56
- end
57
+ result || Primitive::Raw.new(:super, nil)
58
+ end
57
59
 
58
- if subklass_pair
59
- klass = "Zapata::Primitive::#{subklass_pair.first}".constantize
60
- result = klass.new(code)
60
+ def primitive_klass(code)
61
+ primitive_type = find_primitive_type(code)
62
+ return unless primitive_type
61
63
 
62
- DB.create(result) if search_for_types.include?(current_type)
63
- else
64
- end
64
+ "Zapata::Primitive::#{primitive_type}".constantize
65
+ end
65
66
 
66
- deeper_dives(code) if DIVE_TYPES.include?(current_type)
67
+ def find_primitive_type(code)
68
+ klass_pair = PRIMITIVE_TYPES.detect do |_, types|
69
+ types.include?(code.type)
70
+ end
71
+ return unless klass_pair
67
72
 
68
- result || Primitive::Raw.new(:super, nil)
73
+ klass_pair.first
69
74
  end
70
75
 
71
76
  def search_for_types
@@ -73,6 +78,8 @@ module Zapata
73
78
  end
74
79
 
75
80
  def deeper_dives(code)
81
+ return unless DIVE_TYPES.include?(code.type)
82
+
76
83
  code.to_a.compact.each do |part|
77
84
  dive(part)
78
85
  end
@@ -9,7 +9,7 @@ module Zapata
9
9
 
10
10
  def to_raw
11
11
  chosen_value = Predictor::Value.new(node.name, self).choose.to_raw
12
- return_with_super_as_missing(chosen_value, node.name)
12
+ return_with_super_as_missing(chosen_value, self)
13
13
  end
14
14
  end
15
15
  end
@@ -18,7 +18,7 @@ module Zapata
18
18
 
19
19
  if raw.type == :super
20
20
  predicted = Predictor::Value.new(raw.value).choose.to_raw
21
- return_with_super_as_missing(predicted, primitive.name)
21
+ return_with_super_as_missing(predicted, primitive)
22
22
  else
23
23
  raw
24
24
  end
@@ -23,8 +23,8 @@ module Zapata
23
23
  Diver.dive(node.body).to_raw
24
24
  end
25
25
 
26
- def return_with_super_as_missing(raw, name)
27
- raw.type == :super ? Missing.new(name).to_raw : raw
26
+ def return_with_super_as_missing(raw, primitive)
27
+ raw.type == :super ? Missing.new(primitive.name).to_raw : raw
28
28
  end
29
29
 
30
30
  def return_with_missing_as_super(raw, name)
@@ -33,7 +33,8 @@ module Zapata
33
33
  ConstSend.new(raw_receiver, node.name, node.args).to_raw
34
34
  else
35
35
  raw = Predictor::Value.new(node.name, self).choose.to_raw
36
- return_with_missing_as_super(raw, node.name)
36
+ missing_name = raw.type == :super ? Unparser.unparse(code) : node.name
37
+ Missing.new(missing_name).to_raw
37
38
  end
38
39
  end
39
40
  end
@@ -1,3 +1,3 @@
1
1
  module Zapata
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -101,7 +101,13 @@ def exec_generation(generate_for)
101
101
  end
102
102
 
103
103
  output = stdout.readlines
104
- generated_filename = output.last.match(/File\ (.+)\ was/)[1]
104
+ begin
105
+ generated_filename = output.last.match(/File\ (.+)\ was/)[1]
106
+ rescue
107
+ raise "Did not get the message that file was generated. Got this instead:
108
+ STDOUT: #{output}
109
+ STDERR: #{stderr.readlines}"
110
+ end
105
111
  spec_path = "#{RAILS_TEST_APP_DIR}/#{generated_filename}"
106
112
 
107
113
  clean(
@@ -30,7 +30,7 @@ end
30
30
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
31
31
  gem 'spring', group: :development
32
32
 
33
- gem 'zapata', path: '~/Developer/zapata'
33
+ gem 'zapata'
34
34
 
35
35
  # Use ActiveModel has_secure_password
36
36
  # gem 'bcrypt', '~> 3.1.7'
@@ -1,20 +1,3 @@
1
- PATH
2
- remote: ~/Developer/zapata
3
- specs:
4
- zapata (0.0.2)
5
- andand (~> 1.3)
6
- file-temp (~> 1.2)
7
- memoist
8
- parser (~> 2.1)
9
- pry (~> 0.9)
10
- pry-stack_explorer (~> 0.4)
11
- rails (>= 3.0.0)
12
- require_all (~> 1.3)
13
- rspec
14
- rspec-rails
15
- slop (~> 3.4)
16
- unparser (~> 0.1)
17
-
18
1
  GEM
19
2
  remote: https://rubygems.org/
20
3
  specs:
@@ -188,6 +171,19 @@ GEM
188
171
  equalizer (~> 0.0.9)
189
172
  parser (~> 2.1)
190
173
  procto (~> 0.0.2)
174
+ zapata (0.0.2)
175
+ andand (~> 1.3)
176
+ file-temp (~> 1.2)
177
+ memoist
178
+ parser (~> 2.1)
179
+ pry (~> 0.9)
180
+ pry-stack_explorer (~> 0.4)
181
+ rails (>= 3.0.0)
182
+ require_all (~> 1.3)
183
+ rspec
184
+ rspec-rails
185
+ slop (~> 3.4)
186
+ unparser (~> 0.1)
191
187
 
192
188
  PLATFORMS
193
189
  ruby
@@ -204,4 +200,4 @@ DEPENDENCIES
204
200
  sqlite3
205
201
  turbolinks
206
202
  uglifier (>= 1.3.0)
207
- zapata!
203
+ zapata
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zapata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Domas Bitvinskas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-12 00:00:00.000000000 Z
11
+ date: 2014-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser