to_source 0.2.15 → 0.2.16
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.
- data/.gitignore +6 -6
 - data/Changelog.md +4 -0
 - data/README.md +1 -1
 - data/bin/to_source +1 -0
 - data/config/flay.yml +1 -1
 - data/config/flog.yml +1 -1
 - data/config/roodi.yml +4 -4
 - data/config/site.reek +5 -2
 - data/config/yardstick.yml +1 -1
 - data/lib/to_source.rb +1 -1
 - data/lib/to_source/command.rb +63 -1
 - data/lib/to_source/emitter.rb +221 -32
 - data/lib/to_source/emitter/access.rb +8 -0
 - data/lib/to_source/emitter/actual_arguments.rb +51 -8
 - data/lib/to_source/emitter/alias.rb +11 -2
 - data/lib/to_source/emitter/assignment.rb +62 -22
 - data/lib/to_source/emitter/attribute_assignment.rb +11 -2
 - data/lib/to_source/emitter/begin.rb +34 -14
 - data/lib/to_source/emitter/binary_operator.rb +34 -17
 - data/lib/to_source/emitter/binary_operator_method.rb +36 -17
 - data/lib/to_source/emitter/block.rb +7 -0
 - data/lib/to_source/emitter/block_argument.rb +7 -0
 - data/lib/to_source/emitter/block_pass.rb +7 -0
 - data/lib/to_source/emitter/case.rb +85 -0
 - data/lib/to_source/emitter/class.rb +21 -6
 - data/lib/to_source/emitter/concat_arguments.rb +11 -3
 - data/lib/to_source/emitter/default_arguments.rb +7 -0
 - data/lib/to_source/emitter/define.rb +46 -8
 - data/lib/to_source/emitter/defined.rb +7 -0
 - data/lib/to_source/emitter/element_assignment.rb +10 -1
 - data/lib/to_source/emitter/element_reference.rb +10 -1
 - data/lib/to_source/emitter/empty_body.rb +9 -0
 - data/lib/to_source/emitter/ensure.rb +34 -7
 - data/lib/to_source/emitter/ensure_body.rb +14 -5
 - data/lib/to_source/emitter/execute_string.rb +9 -0
 - data/lib/to_source/emitter/formal_arguments.rb +131 -39
 - data/lib/to_source/emitter/if.rb +59 -14
 - data/lib/to_source/emitter/iter.rb +10 -3
 - data/lib/to_source/emitter/keyword_value.rb +28 -4
 - data/lib/to_source/emitter/literal.rb +99 -14
 - data/lib/to_source/emitter/literal/dynamic.rb +88 -13
 - data/lib/to_source/emitter/loop.rb +14 -11
 - data/lib/to_source/emitter/match3.rb +7 -0
 - data/lib/to_source/emitter/module.rb +10 -3
 - data/lib/to_source/emitter/multiple_assignment.rb +19 -0
 - data/lib/to_source/emitter/nth_ref.rb +7 -0
 - data/lib/to_source/emitter/op_assign1.rb +7 -0
 - data/lib/to_source/emitter/op_assign2.rb +7 -0
 - data/lib/to_source/emitter/pattern_arguments.rb +7 -0
 - data/lib/to_source/emitter/rescue.rb +10 -4
 - data/lib/to_source/emitter/rescue_condition.rb +40 -3
 - data/lib/to_source/emitter/scope.rb +7 -0
 - data/lib/to_source/emitter/scope_name.rb +7 -0
 - data/lib/to_source/emitter/scoped_name.rb +7 -0
 - data/lib/to_source/emitter/send.rb +71 -5
 - data/lib/to_source/emitter/send_with_arguments.rb +53 -7
 - data/lib/to_source/emitter/singleton_class.rb +17 -5
 - data/lib/to_source/emitter/splat.rb +7 -0
 - data/lib/to_source/emitter/splat_when.rb +7 -0
 - data/lib/to_source/emitter/static.rb +19 -0
 - data/lib/to_source/emitter/super.rb +49 -4
 - data/lib/to_source/emitter/to_array.rb +7 -0
 - data/lib/to_source/emitter/to_string.rb +7 -0
 - data/lib/to_source/emitter/toplevel.rb +9 -0
 - data/lib/to_source/emitter/unary_operator_method.rb +7 -0
 - data/lib/to_source/emitter/unless.rb +23 -4
 - data/lib/to_source/emitter/util.rb +8 -0
 - data/lib/to_source/emitter/when.rb +28 -3
 - data/lib/to_source/emitter/yield.rb +9 -0
 - data/lib/to_source/emitter/z_super.rb +7 -0
 - data/lib/to_source/state.rb +95 -11
 - data/spec/unit/to_source/class_methods/run_spec.rb +13 -0
 - data/to_source.gemspec +1 -1
 - metadata +3 -4
 - data/lib/to_source/buffer.rb +0 -40
 - data/lib/to_source/emitter/receiver_case.rb +0 -35
 
| 
         @@ -1,32 +1,57 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module ToSource
         
     | 
| 
       2 
2 
     | 
    
         
             
              class Emitter
         
     | 
| 
      
 3 
     | 
    
         
            +
                # Emitter for when nodes
         
     | 
| 
       3 
4 
     | 
    
         
             
                class When < self
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
6 
     | 
    
         
             
                  handle(Rubinius::AST::When)
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
       7 
8 
     | 
    
         
             
                private
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
      
 10 
     | 
    
         
            +
                  # Perform dispatch
         
     | 
| 
      
 11 
     | 
    
         
            +
                  #
         
     | 
| 
      
 12 
     | 
    
         
            +
                  # @return [undefined]
         
     | 
| 
      
 13 
     | 
    
         
            +
                  #
         
     | 
| 
      
 14 
     | 
    
         
            +
                  # @api private
         
     | 
| 
      
 15 
     | 
    
         
            +
                  #
         
     | 
| 
       9 
16 
     | 
    
         
             
                  def dispatch
         
     | 
| 
       10 
17 
     | 
    
         
             
                    emit('when ')
         
     | 
| 
       11 
18 
     | 
    
         
             
                    emit_single
         
     | 
| 
       12 
19 
     | 
    
         
             
                    emit_conditions
         
     | 
| 
       13 
20 
     | 
    
         
             
                    emit_splat
         
     | 
| 
       14 
     | 
    
         
            -
                     
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                     
     | 
| 
      
 21 
     | 
    
         
            +
                    indented do
         
     | 
| 
      
 22 
     | 
    
         
            +
                      visit(node.body)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    end
         
     | 
| 
       17 
24 
     | 
    
         
             
                  end
         
     | 
| 
       18 
25 
     | 
    
         | 
| 
      
 26 
     | 
    
         
            +
                  # Emit single
         
     | 
| 
      
 27 
     | 
    
         
            +
                  #
         
     | 
| 
      
 28 
     | 
    
         
            +
                  # @return [undefined]
         
     | 
| 
      
 29 
     | 
    
         
            +
                  #
         
     | 
| 
      
 30 
     | 
    
         
            +
                  # @api private
         
     | 
| 
      
 31 
     | 
    
         
            +
                  #
         
     | 
| 
       19 
32 
     | 
    
         
             
                  def emit_single
         
     | 
| 
       20 
33 
     | 
    
         
             
                    single = node.single
         
     | 
| 
       21 
34 
     | 
    
         
             
                    visit(single) if single
         
     | 
| 
       22 
35 
     | 
    
         
             
                  end
         
     | 
| 
       23 
36 
     | 
    
         | 
| 
      
 37 
     | 
    
         
            +
                  # Emit splat
         
     | 
| 
      
 38 
     | 
    
         
            +
                  #
         
     | 
| 
      
 39 
     | 
    
         
            +
                  # @return [undefined]
         
     | 
| 
      
 40 
     | 
    
         
            +
                  #
         
     | 
| 
      
 41 
     | 
    
         
            +
                  # @api private
         
     | 
| 
      
 42 
     | 
    
         
            +
                  #
         
     | 
| 
       24 
43 
     | 
    
         
             
                  def emit_splat
         
     | 
| 
       25 
44 
     | 
    
         
             
                    splat = node.splat
         
     | 
| 
       26 
45 
     | 
    
         
             
                    return unless splat
         
     | 
| 
       27 
46 
     | 
    
         
             
                    visit(splat)
         
     | 
| 
       28 
47 
     | 
    
         
             
                  end
         
     | 
| 
       29 
48 
     | 
    
         | 
| 
      
 49 
     | 
    
         
            +
                  # Emit conditions
         
     | 
| 
      
 50 
     | 
    
         
            +
                  #
         
     | 
| 
      
 51 
     | 
    
         
            +
                  # @return [undefined]
         
     | 
| 
      
 52 
     | 
    
         
            +
                  #
         
     | 
| 
      
 53 
     | 
    
         
            +
                  # @api private
         
     | 
| 
      
 54 
     | 
    
         
            +
                  #
         
     | 
| 
       30 
55 
     | 
    
         
             
                  def emit_conditions
         
     | 
| 
       31 
56 
     | 
    
         
             
                    conditions = node.conditions 
         
     | 
| 
       32 
57 
     | 
    
         
             
                    return unless conditions
         
     | 
| 
         @@ -1,9 +1,18 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module ToSource
         
     | 
| 
       2 
2 
     | 
    
         
             
              class Emitter
         
     | 
| 
      
 3 
     | 
    
         
            +
                # Emitter for yield nodes
         
     | 
| 
       3 
4 
     | 
    
         
             
                class Yield < self
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
6 
     | 
    
         
             
                  handle(Rubinius::AST::Yield)
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
      
 8 
     | 
    
         
            +
                private
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                  # Perform dispatch
         
     | 
| 
      
 11 
     | 
    
         
            +
                  #
         
     | 
| 
      
 12 
     | 
    
         
            +
                  # @return [undefined]
         
     | 
| 
      
 13 
     | 
    
         
            +
                  #
         
     | 
| 
      
 14 
     | 
    
         
            +
                  # @api private
         
     | 
| 
      
 15 
     | 
    
         
            +
                  #
         
     | 
| 
       7 
16 
     | 
    
         
             
                  def dispatch
         
     | 
| 
       8 
17 
     | 
    
         
             
                    emit('yield')
         
     | 
| 
       9 
18 
     | 
    
         
             
                    arguments = node.arguments
         
     | 
| 
         @@ -1,11 +1,18 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module ToSource
         
     | 
| 
       2 
2 
     | 
    
         
             
              class Emitter
         
     | 
| 
      
 3 
     | 
    
         
            +
                # Emitter for zsuper nodes
         
     | 
| 
       3 
4 
     | 
    
         
             
                class ZSuper < self
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
6 
     | 
    
         
             
                  handle(Rubinius::AST::ZSuper)
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
       7 
8 
     | 
    
         
             
                private
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
      
 10 
     | 
    
         
            +
                  # Perform dispatch
         
     | 
| 
      
 11 
     | 
    
         
            +
                  #
         
     | 
| 
      
 12 
     | 
    
         
            +
                  # @return [undefined]
         
     | 
| 
      
 13 
     | 
    
         
            +
                  #
         
     | 
| 
      
 14 
     | 
    
         
            +
                  # @api private
         
     | 
| 
      
 15 
     | 
    
         
            +
                  #
         
     | 
| 
       9 
16 
     | 
    
         
             
                  def dispatch
         
     | 
| 
       10 
17 
     | 
    
         
             
                    emit('super')
         
     | 
| 
       11 
18 
     | 
    
         
             
                    block = node.block
         
     | 
    
        data/lib/to_source/state.rb
    CHANGED
    
    | 
         @@ -1,55 +1,139 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module ToSource
         
     | 
| 
      
 2 
     | 
    
         
            +
              # Emitter state
         
     | 
| 
       2 
3 
     | 
    
         
             
              class State
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
      
 5 
     | 
    
         
            +
                # Return last command
         
     | 
| 
      
 6 
     | 
    
         
            +
                #
         
     | 
| 
      
 7 
     | 
    
         
            +
                # @return [Command]
         
     | 
| 
      
 8 
     | 
    
         
            +
                #
         
     | 
| 
      
 9 
     | 
    
         
            +
                # @api private
         
     | 
| 
      
 10 
     | 
    
         
            +
                #
         
     | 
| 
       4 
11 
     | 
    
         
             
                attr_reader :last
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                # Return current indentation level
         
     | 
| 
      
 14 
     | 
    
         
            +
                #
         
     | 
| 
      
 15 
     | 
    
         
            +
                # @return [Fixnum]
         
     | 
| 
      
 16 
     | 
    
         
            +
                #
         
     | 
| 
      
 17 
     | 
    
         
            +
                # @api private
         
     | 
| 
      
 18 
     | 
    
         
            +
                #
         
     | 
| 
       5 
19 
     | 
    
         
             
                attr_reader :identation
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                # Return buffer
         
     | 
| 
      
 22 
     | 
    
         
            +
                #
         
     | 
| 
      
 23 
     | 
    
         
            +
                # @return [Array]
         
     | 
| 
      
 24 
     | 
    
         
            +
                #
         
     | 
| 
      
 25 
     | 
    
         
            +
                # @api private
         
     | 
| 
      
 26 
     | 
    
         
            +
                #
         
     | 
| 
       6 
27 
     | 
    
         
             
                attr_reader :buffer
         
     | 
| 
       7 
28 
     | 
    
         | 
| 
      
 29 
     | 
    
         
            +
                # Initialize object
         
     | 
| 
      
 30 
     | 
    
         
            +
                #
         
     | 
| 
      
 31 
     | 
    
         
            +
                # @return [undefined]
         
     | 
| 
      
 32 
     | 
    
         
            +
                #
         
     | 
| 
      
 33 
     | 
    
         
            +
                # @api private
         
     | 
| 
      
 34 
     | 
    
         
            +
                #
         
     | 
| 
       8 
35 
     | 
    
         
             
                def initialize
         
     | 
| 
       9 
36 
     | 
    
         
             
                  @last        = Command::NULL
         
     | 
| 
       10 
37 
     | 
    
         
             
                  @indentation = 0
         
     | 
| 
       11 
38 
     | 
    
         
             
                  @buffer      = []
         
     | 
| 
       12 
39 
     | 
    
         
             
                end
         
     | 
| 
       13 
40 
     | 
    
         | 
| 
      
 41 
     | 
    
         
            +
                # Execute command 
         
     | 
| 
      
 42 
     | 
    
         
            +
                #
         
     | 
| 
      
 43 
     | 
    
         
            +
                # @param [Command] command
         
     | 
| 
      
 44 
     | 
    
         
            +
                #
         
     | 
| 
      
 45 
     | 
    
         
            +
                # @return [self]
         
     | 
| 
      
 46 
     | 
    
         
            +
                #
         
     | 
| 
      
 47 
     | 
    
         
            +
                # @api private
         
     | 
| 
      
 48 
     | 
    
         
            +
                #
         
     | 
| 
       14 
49 
     | 
    
         
             
                def execute(command)
         
     | 
| 
       15 
50 
     | 
    
         
             
                  command.run(self)
         
     | 
| 
       16 
51 
     | 
    
         
             
                  @last = command
         
     | 
| 
      
 52 
     | 
    
         
            +
                  self
         
     | 
| 
       17 
53 
     | 
    
         
             
                end
         
     | 
| 
       18 
54 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
                 
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                 
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 55 
     | 
    
         
            +
                # Write string to buffer
         
     | 
| 
      
 56 
     | 
    
         
            +
                #
         
     | 
| 
      
 57 
     | 
    
         
            +
                # @param [String] string
         
     | 
| 
      
 58 
     | 
    
         
            +
                #
         
     | 
| 
      
 59 
     | 
    
         
            +
                # @return [self]
         
     | 
| 
      
 60 
     | 
    
         
            +
                #
         
     | 
| 
      
 61 
     | 
    
         
            +
                # @api private
         
     | 
| 
      
 62 
     | 
    
         
            +
                #
         
     | 
| 
       23 
63 
     | 
    
         
             
                def write(string)
         
     | 
| 
       24 
64 
     | 
    
         
             
                  @buffer << string
         
     | 
| 
      
 65 
     | 
    
         
            +
                  self
         
     | 
| 
       25 
66 
     | 
    
         
             
                end
         
     | 
| 
       26 
67 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
                 
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
      
 68 
     | 
    
         
            +
                # Return source
         
     | 
| 
      
 69 
     | 
    
         
            +
                #
         
     | 
| 
      
 70 
     | 
    
         
            +
                # @return [String]
         
     | 
| 
      
 71 
     | 
    
         
            +
                # 
         
     | 
| 
      
 72 
     | 
    
         
            +
                # @api private
         
     | 
| 
      
 73 
     | 
    
         
            +
                #
         
     | 
| 
      
 74 
     | 
    
         
            +
                def source
         
     | 
| 
      
 75 
     | 
    
         
            +
                  buffer.join('')
         
     | 
| 
       29 
76 
     | 
    
         
             
                end
         
     | 
| 
       30 
77 
     | 
    
         | 
| 
      
 78 
     | 
    
         
            +
                # Push command
         
     | 
| 
      
 79 
     | 
    
         
            +
                #
         
     | 
| 
      
 80 
     | 
    
         
            +
                # @param [Command] command
         
     | 
| 
      
 81 
     | 
    
         
            +
                #
         
     | 
| 
      
 82 
     | 
    
         
            +
                # @return [self]
         
     | 
| 
      
 83 
     | 
    
         
            +
                #
         
     | 
| 
      
 84 
     | 
    
         
            +
                # @api private
         
     | 
| 
      
 85 
     | 
    
         
            +
                #
         
     | 
| 
       31 
86 
     | 
    
         
             
                def push(command)
         
     | 
| 
       32 
87 
     | 
    
         
             
                  indent
         
     | 
| 
       33 
88 
     | 
    
         
             
                  write(command.content)
         
     | 
| 
      
 89 
     | 
    
         
            +
                  self
         
     | 
| 
       34 
90 
     | 
    
         
             
                end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
      
 91 
     | 
    
         
            +
             
         
     | 
| 
      
 92 
     | 
    
         
            +
                # Indent line if needed
         
     | 
| 
      
 93 
     | 
    
         
            +
                #
         
     | 
| 
      
 94 
     | 
    
         
            +
                # @return [self]
         
     | 
| 
      
 95 
     | 
    
         
            +
                #
         
     | 
| 
      
 96 
     | 
    
         
            +
                # @api private
         
     | 
| 
      
 97 
     | 
    
         
            +
                #
         
     | 
| 
       36 
98 
     | 
    
         
             
                def indent
         
     | 
| 
       37 
99 
     | 
    
         
             
                  return unless blank?
         
     | 
| 
       38 
100 
     | 
    
         
             
                  write(' ' * @indentation)
         
     | 
| 
      
 101 
     | 
    
         
            +
                  self
         
     | 
| 
       39 
102 
     | 
    
         
             
                end
         
     | 
| 
       40 
103 
     | 
    
         | 
| 
      
 104 
     | 
    
         
            +
                # Test for blank line
         
     | 
| 
      
 105 
     | 
    
         
            +
                #
         
     | 
| 
      
 106 
     | 
    
         
            +
                # @return [true]
         
     | 
| 
      
 107 
     | 
    
         
            +
                #   if line is blank
         
     | 
| 
      
 108 
     | 
    
         
            +
                #
         
     | 
| 
      
 109 
     | 
    
         
            +
                # @return [false]
         
     | 
| 
      
 110 
     | 
    
         
            +
                #   otherwise
         
     | 
| 
      
 111 
     | 
    
         
            +
                #
         
     | 
| 
      
 112 
     | 
    
         
            +
                # @api private
         
     | 
| 
      
 113 
     | 
    
         
            +
                #
         
     | 
| 
       41 
114 
     | 
    
         
             
                def blank?
         
     | 
| 
       42 
115 
     | 
    
         
             
                  buffer.last == "\n"
         
     | 
| 
       43 
116 
     | 
    
         
             
                end
         
     | 
| 
       44 
117 
     | 
    
         | 
| 
      
 118 
     | 
    
         
            +
                # Write newline
         
     | 
| 
      
 119 
     | 
    
         
            +
                #
         
     | 
| 
      
 120 
     | 
    
         
            +
                # @return [self]
         
     | 
| 
      
 121 
     | 
    
         
            +
                #
         
     | 
| 
      
 122 
     | 
    
         
            +
                # @api private
         
     | 
| 
      
 123 
     | 
    
         
            +
                #
         
     | 
| 
       45 
124 
     | 
    
         
             
                def new_line
         
     | 
| 
       46 
125 
     | 
    
         
             
                  write("\n")
         
     | 
| 
      
 126 
     | 
    
         
            +
                  self
         
     | 
| 
       47 
127 
     | 
    
         
             
                end
         
     | 
| 
       48 
128 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
                 
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                 
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
      
 129 
     | 
    
         
            +
                # Perform shift by width
         
     | 
| 
      
 130 
     | 
    
         
            +
                #
         
     | 
| 
      
 131 
     | 
    
         
            +
                # @param [Fixnum] width
         
     | 
| 
      
 132 
     | 
    
         
            +
                #
         
     | 
| 
      
 133 
     | 
    
         
            +
                # @return [self]
         
     | 
| 
      
 134 
     | 
    
         
            +
                #
         
     | 
| 
      
 135 
     | 
    
         
            +
                # @api private
         
     | 
| 
      
 136 
     | 
    
         
            +
                #
         
     | 
| 
       53 
137 
     | 
    
         
             
                def shift(width)
         
     | 
| 
       54 
138 
     | 
    
         
             
                  @indentation += width
         
     | 
| 
       55 
139 
     | 
    
         
             
                  @indentation = 0 if @indentation < 0
         
     | 
| 
         @@ -814,6 +814,19 @@ describe ToSource,'.to_source' do 
     | 
|
| 
       814 
814 
     | 
    
         
             
              end
         
     | 
| 
       815 
815 
     | 
    
         | 
| 
       816 
816 
     | 
    
         
             
              context 'case statement' do
         
     | 
| 
      
 817 
     | 
    
         
            +
                context 'without else branch' do
         
     | 
| 
      
 818 
     | 
    
         
            +
                  assert_source <<-RUBY
         
     | 
| 
      
 819 
     | 
    
         
            +
                    case 
         
     | 
| 
      
 820 
     | 
    
         
            +
                    when bar
         
     | 
| 
      
 821 
     | 
    
         
            +
                      baz
         
     | 
| 
      
 822 
     | 
    
         
            +
                    when baz
         
     | 
| 
      
 823 
     | 
    
         
            +
                      bar
         
     | 
| 
      
 824 
     | 
    
         
            +
                    end
         
     | 
| 
      
 825 
     | 
    
         
            +
                  RUBY
         
     | 
| 
      
 826 
     | 
    
         
            +
                end
         
     | 
| 
      
 827 
     | 
    
         
            +
              end
         
     | 
| 
      
 828 
     | 
    
         
            +
             
     | 
| 
      
 829 
     | 
    
         
            +
              context 'receiver case statement' do
         
     | 
| 
       817 
830 
     | 
    
         
             
                context 'without else branch' do
         
     | 
| 
       818 
831 
     | 
    
         
             
                  assert_source <<-RUBY
         
     | 
| 
       819 
832 
     | 
    
         
             
                    case foo
         
     | 
    
        data/to_source.gemspec
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: to_source
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.16
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2013-01- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2013-01-25 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: adamantium
         
     | 
| 
         @@ -104,7 +104,6 @@ files: 
     | 
|
| 
       104 
104 
     | 
    
         
             
            - config/site.reek
         
     | 
| 
       105 
105 
     | 
    
         
             
            - config/yardstick.yml
         
     | 
| 
       106 
106 
     | 
    
         
             
            - lib/to_source.rb
         
     | 
| 
       107 
     | 
    
         
            -
            - lib/to_source/buffer.rb
         
     | 
| 
       108 
107 
     | 
    
         
             
            - lib/to_source/command.rb
         
     | 
| 
       109 
108 
     | 
    
         
             
            - lib/to_source/emitter.rb
         
     | 
| 
       110 
109 
     | 
    
         
             
            - lib/to_source/emitter/access.rb
         
     | 
| 
         @@ -118,6 +117,7 @@ files: 
     | 
|
| 
       118 
117 
     | 
    
         
             
            - lib/to_source/emitter/block.rb
         
     | 
| 
       119 
118 
     | 
    
         
             
            - lib/to_source/emitter/block_argument.rb
         
     | 
| 
       120 
119 
     | 
    
         
             
            - lib/to_source/emitter/block_pass.rb
         
     | 
| 
      
 120 
     | 
    
         
            +
            - lib/to_source/emitter/case.rb
         
     | 
| 
       121 
121 
     | 
    
         
             
            - lib/to_source/emitter/class.rb
         
     | 
| 
       122 
122 
     | 
    
         
             
            - lib/to_source/emitter/concat_arguments.rb
         
     | 
| 
       123 
123 
     | 
    
         
             
            - lib/to_source/emitter/default_arguments.rb
         
     | 
| 
         @@ -143,7 +143,6 @@ files: 
     | 
|
| 
       143 
143 
     | 
    
         
             
            - lib/to_source/emitter/op_assign1.rb
         
     | 
| 
       144 
144 
     | 
    
         
             
            - lib/to_source/emitter/op_assign2.rb
         
     | 
| 
       145 
145 
     | 
    
         
             
            - lib/to_source/emitter/pattern_arguments.rb
         
     | 
| 
       146 
     | 
    
         
            -
            - lib/to_source/emitter/receiver_case.rb
         
     | 
| 
       147 
146 
     | 
    
         
             
            - lib/to_source/emitter/rescue.rb
         
     | 
| 
       148 
147 
     | 
    
         
             
            - lib/to_source/emitter/rescue_condition.rb
         
     | 
| 
       149 
148 
     | 
    
         
             
            - lib/to_source/emitter/scope.rb
         
     | 
    
        data/lib/to_source/buffer.rb
    DELETED
    
    | 
         @@ -1,40 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module ToSource
         
     | 
| 
       2 
     | 
    
         
            -
              class Buffer
         
     | 
| 
       3 
     | 
    
         
            -
                include Adamantium::Flat
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
                attr_reader :lines
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                def initialize(lines = [])
         
     | 
| 
       8 
     | 
    
         
            -
                  @lines = lines
         
     | 
| 
       9 
     | 
    
         
            -
                end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
                def to_s
         
     | 
| 
       12 
     | 
    
         
            -
                  @lines.join("\n")
         
     | 
| 
       13 
     | 
    
         
            -
                end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                def indent
         
     | 
| 
       16 
     | 
    
         
            -
                  new(lines.map { |line| "  #{line}" })
         
     | 
| 
       17 
     | 
    
         
            -
                end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
                def body(body)
         
     | 
| 
       20 
     | 
    
         
            -
                  self
         
     | 
| 
       21 
     | 
    
         
            -
                end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                def class_open(name, superclass)
         
     | 
| 
       24 
     | 
    
         
            -
                  push('class')
         
     | 
| 
       25 
     | 
    
         
            -
                end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                def push(token)
         
     | 
| 
       28 
     | 
    
         
            -
                  new(lines.dup << token)
         
     | 
| 
       29 
     | 
    
         
            -
                end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                def end
         
     | 
| 
       32 
     | 
    
         
            -
                  push('end')
         
     | 
| 
       33 
     | 
    
         
            -
                end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                def new(*args)
         
     | 
| 
       36 
     | 
    
         
            -
                  self.class.new(*args)
         
     | 
| 
       37 
     | 
    
         
            -
                end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
              end
         
     | 
| 
       40 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,35 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module ToSource
         
     | 
| 
       2 
     | 
    
         
            -
              class Emitter
         
     | 
| 
       3 
     | 
    
         
            -
                class ReceiverCase < self
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
                  handle(Rubinius::AST::ReceiverCase)
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                  def dispatch
         
     | 
| 
       8 
     | 
    
         
            -
                    emit('case ')
         
     | 
| 
       9 
     | 
    
         
            -
                    visit(node.receiver)
         
     | 
| 
       10 
     | 
    
         
            -
                    emit_whens
         
     | 
| 
       11 
     | 
    
         
            -
                    emit_else
         
     | 
| 
       12 
     | 
    
         
            -
                    emit_end
         
     | 
| 
       13 
     | 
    
         
            -
                  end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                  def emit_else
         
     | 
| 
       16 
     | 
    
         
            -
                    body = node.else
         
     | 
| 
       17 
     | 
    
         
            -
                    return if body.kind_of?(Rubinius::AST::NilLiteral)
         
     | 
| 
       18 
     | 
    
         
            -
                    emit('else')
         
     | 
| 
       19 
     | 
    
         
            -
                    indent
         
     | 
| 
       20 
     | 
    
         
            -
                    visit(body)
         
     | 
| 
       21 
     | 
    
         
            -
                    unindent
         
     | 
| 
       22 
     | 
    
         
            -
                  end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                  def emit_whens
         
     | 
| 
       25 
     | 
    
         
            -
                    first = true
         
     | 
| 
       26 
     | 
    
         
            -
                    node.whens.each do |member|
         
     | 
| 
       27 
     | 
    
         
            -
                      new_line if first
         
     | 
| 
       28 
     | 
    
         
            -
                      first = false
         
     | 
| 
       29 
     | 
    
         
            -
                      visit(member)
         
     | 
| 
       30 
     | 
    
         
            -
                    end
         
     | 
| 
       31 
     | 
    
         
            -
                  end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                end
         
     | 
| 
       34 
     | 
    
         
            -
              end
         
     | 
| 
       35 
     | 
    
         
            -
            end
         
     |