drg 0.15.3 → 0.15.4

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: 69c0e41819c37acab365f77c1c8659c765c5f5be
4
- data.tar.gz: d9d5b708748bf54ba0bd88e6d4296f604ef87144
3
+ metadata.gz: 0d1cc344f3f40558e3ff0b5b1b4e8cb121b28f33
4
+ data.tar.gz: 725395f9526ee8371ccd781be7062aab12415342
5
5
  SHA512:
6
- metadata.gz: eeee5b43f72123668474dcc67f19a053587133e8e833d20b7255f1e711faea040d08582b5de88f8b05597d9c9b9f25635a71bc27dbc32cc2532967ba8c1d7830
7
- data.tar.gz: 2c028a172eae58d4bdd9d16b8e191680974ce480bc175b7cbc1008d034cce4555cd5a68eb9c281c15a059ff433a037e24b0e88284187f422aa82a51e7e64804d
6
+ metadata.gz: ecd79de1e5d14e24502a38492bd154140c7beebcfbab0210152aa0ea4b47662ba03533c044ba10e6ce65bf5fbc130a4e1091326bd0487cf4f3bd9a11a7f396b5
7
+ data.tar.gz: d7670cfd5996e9cc0314088d8d09f89b9aeb006173b7f670f3e80361673062b445f5e8401188963fc087d2318170e945ab2dcb5f25bce768971b791920dd54bf
@@ -1,12 +1,19 @@
1
1
  class DRG::Decorators::SexpDecorator < DelegateClass(Sexp)
2
2
  def each_sexp_condition
3
3
  return enum_for(__method__) unless block_given?
4
+ yielded = []
4
5
  each_sexp do |exp|
5
- next unless exp.is_a?(Sexp)
6
6
  if exp.first == :if
7
7
  yield exp
8
- elsif nested_sexp = exp.enum_for(:deep_each).find { |s| s.first == :if }
9
- yield nested_sexp
8
+ yielded << exp
9
+ else
10
+ nested_sexp = exp.enum_for(:deep_each).select { |s| s.first == :if }
11
+ nested_sexp.each do |sexp|
12
+ if yielded.find { |x| x.object_id == sexp.object_id or x.enum_for(:deep_each).find { |xx| xx.object_id == sexp.object_id } }.nil?
13
+ yield sexp
14
+ yielded << sexp
15
+ end
16
+ end
10
17
  end
11
18
  end
12
19
  end
@@ -2,37 +2,67 @@ require 'ruby2ruby'
2
2
 
3
3
  class DRG::Ruby::Condition
4
4
 
5
- attr_reader :statement, :nested_conditions, :sexp
5
+ module SetComparison
6
+ def eql?(other)
7
+ hash == other.hash
8
+ end
9
+
10
+ def hash
11
+ sexp.object_id
12
+ end
13
+ end
14
+
15
+ include SetComparison
16
+
17
+ attr_reader :statement, :nested_conditions, :sexp, :parts, :unless_found
6
18
 
7
19
  def initialize(sexp)
8
20
  @sexp = sexp
9
21
  @statement = Ruby2Ruby.new.process(sexp.deep_clone)
10
22
  @nested_conditions = create_nested_conditions
23
+ @parts = load_parts
11
24
  end
12
25
 
13
26
  def short_statement
14
- if @statement =~ /(unless|if)(.+)$/
15
- ($1 << $2).strip
16
- elsif @statement =~ /(.*?)\s+\?\s+/
17
- $1.strip
18
- end
27
+ "#{'unless ' if sexp[2].nil?}#{Ruby2Ruby.new.process(sexp[1].clone!)}"
19
28
  end
20
29
 
21
30
  def return_value
22
- edit find_return_value
31
+ edit Ruby2Ruby.new.process(if_return_value.clone!)
32
+ end
33
+
34
+ def else_return_value
35
+ edit Ruby2Ruby.new.process(find_else_return_val.clone!)
36
+ end
37
+
38
+ def if_return_value
39
+ if sexp[2].nil?
40
+ sexp.last
41
+ elsif sexp[2].first == :if
42
+ nil
43
+ elsif sexp[2].first == :block
44
+ sexp[2].last
45
+ elsif sexp[2].first == :rescue
46
+ sexp[2][1].last
47
+ else
48
+ sexp[2]
49
+ end
23
50
  end
24
51
 
25
- def find_return_value
26
- if @statement =~ /\s+\?\s+(.*?)(:|$)/
27
- $1.strip
28
- elsif @statement[/then\n(.+)\nend/]
29
- $1.strip
52
+ def find_else_return_val
53
+ if sexp.compact[3].nil?
54
+ nil
55
+ elsif sexp[3].first == :block
56
+ sexp[3].last
57
+ elsif sexp[3].first == :if
58
+ nil
30
59
  else
31
- @statement[/(.*?)(unless|if)/, 1].to_s.strip
60
+ sexp[3]
32
61
  end
33
62
  end
34
63
 
35
64
  def edit(txt)
65
+ txt = txt.to_s
36
66
  txt.sub! /^return\s*/, 'returns '
37
67
  txt.sub! /^returns\s*$/, 'returns nil'
38
68
  if txt.split(/\s/).length == 1
@@ -44,21 +74,20 @@ class DRG::Ruby::Condition
44
74
  end
45
75
 
46
76
  #
47
- # Set related stuff
77
+ # Private
48
78
  #
49
79
 
50
- def eql?(other)
51
- hash == other.hash
52
- end
53
-
54
- def hash
55
- sexp.object_id
80
+ # @description handles elsif
81
+ def load_parts
82
+ condition_parts = Set.new
83
+ sexp.each_sexp do |s|
84
+ if s.first == :if
85
+ condition_parts << self.class.new(s)
86
+ end
87
+ end
88
+ condition_parts.to_a
56
89
  end
57
90
 
58
- #
59
- # Private
60
- #
61
-
62
91
  def create_nested_conditions
63
92
  nc = Set.new
64
93
  s = sexp.drop(1)
data/lib/drg/spec.rb CHANGED
@@ -12,14 +12,13 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
12
12
  lines = [%Q(require "spec_helper"), %Q(), %Q(describe #{spec.const} do)]
13
13
  if spec.class?
14
14
  spec.initialization_args.each do |arg|
15
- lines << %Q( let(:#{arg}) {})
15
+ lines << %Q( let(:#{arg.to_s.sub(/^[&*]/, '')}) {})
16
16
  end
17
17
  lines << %Q()
18
18
  lines << %Q( subject { described_class.new #{spec.initialization_args.join(', ')} })
19
19
  elsif spec.module?
20
20
  lines << %Q( subject { Class.new { include #{spec.const} }.new })
21
21
  end
22
-
23
22
  lines << %Q()
24
23
  spec.funcs.reject(&:private?).each do |func|
25
24
  lines << %Q( describe #{spec.quote("#{func.class? ? '.' : '#'}#{func.name}")} do)
@@ -48,7 +47,7 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
48
47
  end
49
48
 
50
49
  def collect_contexts(condition, indent = '', contexts = [])
51
- new_indent = indent + (' ' * self.class.default_indent_size)
50
+ new_indent = indent + (' ' * self.class.default_indent_size)
52
51
  contexts << %Q(#{indent}context #{quote(tr(condition.short_statement))} do) << %Q(#{new_indent}before {})
53
52
  unless condition.return_value.empty?
54
53
  contexts << %Q(#{new_indent}it #{quote(condition.return_value)} do) << %Q(#{new_indent}end)
@@ -57,15 +56,30 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
57
56
  condition.nested_conditions.each { |nc| collect_contexts(nc, new_indent, contexts) }
58
57
  end
59
58
  contexts << %Q(#{indent}end) << %Q() # /context
60
- contexts << %Q(#{indent}context #{quote(tr(negate(condition.short_statement)))} do) << %Q(#{new_indent}before {})
61
- contexts << %Q(#{indent}end)
59
+ if condition.parts.empty?
60
+ contexts << %Q(#{indent}context #{quote(tr(negate(condition.short_statement)))} do) << %Q(#{new_indent}before {})
61
+ unless condition.else_return_value.empty?
62
+ contexts << %Q(#{new_indent}it #{quote(condition.else_return_value)} do) << %Q(#{new_indent}end)
63
+ end
64
+ contexts << %Q(#{indent}end)
65
+ end
66
+ condition.parts.each do |condition_part|
67
+ contexts << %Q(#{indent}context #{quote(tr(condition_part.short_statement))} do) << %Q(#{new_indent}before {})
68
+ contexts << %Q(#{new_indent}it #{quote(condition_part.return_value)} do) << %Q(#{new_indent}end)
69
+ contexts << %Q(#{indent}end)
70
+ unless condition_part.else_return_value.empty?
71
+ contexts << %Q(#{indent}context #{quote(tr(negate(condition_part.short_statement)))} do) << %Q(#{new_indent}before {})
72
+ contexts << %Q(#{new_indent}it #{quote(condition_part.else_return_value)} do) << %Q(#{new_indent}end)
73
+ contexts << %Q(#{indent}end)
74
+ end
75
+ end
62
76
  contexts
63
77
  end
64
78
 
65
79
  def quote(txt)
66
80
  txt.strip!
67
81
  if txt =~ /"/
68
- "%Q[#{txt.gsub(/\#\{(.*?)\}/m, '@\1')}]"
82
+ "%Q[#{txt.gsub(/\#\{(.*?)\}/m, '\#{\1}')}]"
69
83
  else
70
84
  %Q("#{txt}")
71
85
  end
data/lib/drg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DRG
2
- VERSION = '0.15.3'.freeze
2
+ VERSION = '0.15.4'.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.15.3
4
+ version: 0.15.4
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-23 00:00:00.000000000 Z
11
+ date: 2015-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_parser