drg 0.14.3 → 0.15.0

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: bcfba0400c2db2e1a03310eb1283a46eee235f8c
4
- data.tar.gz: c5ebe017de7b5ad902e8f572f0d5d271566f34c0
3
+ metadata.gz: 237cf5d636b5f61623d98f0de080baf9eee6ec1a
4
+ data.tar.gz: ef2cff5a52e8a897e2bcc12579c5eb5fcd7217c8
5
5
  SHA512:
6
- metadata.gz: 0ebc05ba36eae6d52d2cf9a17ab063ebb639ca324f5890435adedc198d30d10912a61bebe55f399ad7c1282795d091b66a468b06b27575ee821ea341cb2607f5
7
- data.tar.gz: 3017a31f9100ec3eb7eb69f81c12349b2b220ff413bfc8097935dbad38787d0395af11b5fdbda6e6d071503ed50a4782f8ddc59daaa445829b17154f3fbad025
6
+ metadata.gz: f737cf78ee76ee24f33e365c2d21948253785d34708aeca2bdfb0e66658dab5d4939c9a55e4cf0a1455562c65a56acd013814b4b525f934921350e5fca7f6f67
7
+ data.tar.gz: 7c1fcda522637511851f0d6a582171bfa30e78b0f57485a1ecebc492ec4b36145f19519dfb2724dfb2a883a548b9c432fad86ef3c00367d9a0af7f2016928459
@@ -19,14 +19,20 @@ class DRG::Ruby::Condition
19
19
  end
20
20
 
21
21
  def return_value
22
+ edit find_return_value
23
+ end
24
+
25
+ def find_return_value
22
26
  if @statement =~ /\s+\?\s+(.*?)(:|$)/
23
27
  $1.strip
28
+ elsif @statement[/then\n(.+)\nend/]
29
+ $1.strip
24
30
  else
25
- translate @statement[/(.*?)(unless|if)/, 1].to_s.strip
31
+ @statement[/(.*?)(unless|if)/, 1].to_s.strip
26
32
  end
27
33
  end
28
34
 
29
- def translate(txt)
35
+ def edit(txt)
30
36
  txt.sub! /^return\s*/, 'returns '
31
37
  txt.sub! /^returns\s*$/, 'returns nil'
32
38
  if txt.split(/\s/).length == 1
data/lib/drg/spec.rb CHANGED
@@ -2,6 +2,10 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
2
2
  # = Class
3
3
  # generate a rspec file based on existing code
4
4
 
5
+ def self.default_indent_size
6
+ 2
7
+ end
8
+
5
9
  def self.generate(file)
6
10
  spec = DRG::Spec.new(file)
7
11
  return if spec.funcs.empty? # nothing to do
@@ -44,7 +48,7 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
44
48
  end
45
49
 
46
50
  def collect_contexts(condition, indent = '', contexts = [])
47
- new_indent = indent + ' '
51
+ new_indent = indent + (' ' * self.class.default_indent_size)
48
52
  contexts << %Q(#{indent}context #{quote(tr(condition.short_statement))} do) << %Q(#{new_indent}before {})
49
53
  unless condition.return_value.empty?
50
54
  contexts << %Q(#{new_indent}it #{quote(condition.return_value)} do) << %Q(#{new_indent}end)
@@ -61,7 +65,7 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
61
65
  def quote(txt)
62
66
  txt.strip!
63
67
  if txt =~ /"/
64
- "%Q(#{txt})"
68
+ "%Q[#{txt.gsub(/\#\{(.*?)\}/m, '@\1')}]"
65
69
  else
66
70
  %Q("#{txt}")
67
71
  end
@@ -79,7 +83,7 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
79
83
  phrase.sub! /^if /, 'when '
80
84
  phrase.sub! /^not if /, 'unless '
81
85
  phrase.sub! /^if not /, 'unless '
82
- phrase.sub! %r"then$", ''
86
+ phrase.sub! /then$/, ''
83
87
  if phrase !~ /^(when|unless|not)/
84
88
  phrase = "when #{phrase}"
85
89
  end
data/lib/drg/tasks/log.rb CHANGED
@@ -3,8 +3,8 @@ module DRG
3
3
  module Log
4
4
  module_function
5
5
 
6
- def log(msg = nil)
7
- say %Q( * <%= color('#{msg}', :green) %>)
6
+ def log(msg = nil, color = :green)
7
+ say %Q( <%= color('#{msg}', :#{color}) %>)
8
8
  end
9
9
  end
10
10
  end
@@ -18,13 +18,18 @@ module DRG
18
18
  file_path = Pathname.new(File.expand_path(ruby_file))
19
19
  spec = DRG::Spec.generate(file_path)
20
20
  unless spec
21
- log "Skipping #{file_path}: no methods found"
21
+ log "- #{ruby_file} - no methods", :gray
22
22
  next
23
23
  end
24
24
  rspec_file = Pathname.new(spec_file(ruby_file))
25
- log "Generating #{rspec_file}"
25
+ spec_file_path = rspec_file.to_s[%r|/(spec/.+)|, 1]
26
+ if rspec_file.exist?
27
+ log "- #{spec_file_path} - already exists", :gray
28
+ next
29
+ end
30
+ log "+ #{spec_file_path}"
26
31
  FileUtils.mkdir_p(rspec_file.parent)
27
- File.open(spec_file(ruby_file), 'wb') do |f|
32
+ File.open(rspec_file, 'wb') do |f|
28
33
  f << spec.join("\n")
29
34
  end
30
35
  end
@@ -44,7 +49,11 @@ module DRG
44
49
 
45
50
  # @note subbing out /app/ is Rails specific
46
51
  def spec_file(ruby_file)
47
- File.join(spec_path, "#{ruby_file.sub('.rb', '_spec.rb')}").sub '/app/', '/'
52
+ File.join(spec_path, "#{specify(ruby_file)}").sub '/app/', '/'
53
+ end
54
+
55
+ def specify(file_name)
56
+ file_name.sub('.rb', '_spec.rb')
48
57
  end
49
58
 
50
59
  def spec_path
data/lib/drg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DRG
2
- VERSION = '0.14.3'.freeze
2
+ VERSION = '0.15.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.3
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Buckley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-22 00:00:00.000000000 Z
11
+ date: 2015-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_parser