sorcerer 0.3.10 → 0.3.11
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.
- checksums.yaml +7 -0
 - data/README.md +6 -1
 - data/lib/sorcerer/subexpression.rb +25 -11
 - data/lib/sorcerer/version.rb +1 -1
 - data/test/sorcerer/resource_test.rb +13 -1
 - data/test/sorcerer/subexpression_test.rb +5 -2
 - metadata +7 -9
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: f65acc7f174926768d7515c943f2895106a79f80
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 79dce6386aa13cef261f88b20be6594406f325d9
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 471a9b64f1487826f2f7ee8b3844d655004765b338686debdab40c3a173bf8b0ad5b36bd544eab9adf2eb0901acd480261c5761b233e51a0d76221efdb2d1e15
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 67d2541e79034a1172be87e26eeddb02bfa9346a607d82d578531f1883f0919a9ba436c9687ae2062f8fd225ada3661fcbc3de68247ebf29852f074ce3d63d64
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -11,7 +11,7 @@ Sorcerer is targetted mainly at small snippets of Ruby code, 
     | 
|
| 
       11 
11 
     | 
    
         
             
            expressable in a single line. Longer examples may be re-sourced, but
         
     | 
| 
       12 
12 
     | 
    
         
             
            they will be rendered in a single line format.
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
            **Version: 0.3. 
     | 
| 
      
 14 
     | 
    
         
            +
            **Version: 0.3.11**
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
            ## Limitations
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
         @@ -123,6 +123,11 @@ output emitted, then use the debug option: 
     | 
|
| 
       123 
123 
     | 
    
         
             
              puts Sorcerer.source(sexp, debug: true)
         
     | 
| 
       124 
124 
     | 
    
         
             
            ```
         
     | 
| 
       125 
125 
     | 
    
         | 
| 
      
 126 
     | 
    
         
            +
            ## License
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
            Sorcerer is available under the terms of the MIT license. See the
         
     | 
| 
      
 129 
     | 
    
         
            +
            MIT-LICENSE file for details.
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
       126 
131 
     | 
    
         
             
            ## History
         
     | 
| 
       127 
132 
     | 
    
         | 
| 
       128 
133 
     | 
    
         
             
            * 0.3.9 - Support %i{} and %I{}.
         
     | 
| 
         @@ -34,18 +34,30 @@ module Sorcerer 
     | 
|
| 
       34 
34 
     | 
    
         
             
                  case sexp.first
         
     | 
| 
       35 
35 
     | 
    
         
             
                  when :var_ref
         
     | 
| 
       36 
36 
     | 
    
         
             
                    list_sexp(sexp)
         
     | 
| 
       37 
     | 
    
         
            -
                  when :vcall 
     | 
| 
      
 37 
     | 
    
         
            +
                  when :vcall               # [:vcall, target]
         
     | 
| 
      
 38 
     | 
    
         
            +
                    @result << sexp
         
     | 
| 
      
 39 
     | 
    
         
            +
                  when :fcall               # [:fcall, target]
         
     | 
| 
      
 40 
     | 
    
         
            +
                    # ignore
         
     | 
| 
      
 41 
     | 
    
         
            +
                  when :call                # [:call, target, ".", meth]
         
     | 
| 
      
 42 
     | 
    
         
            +
                    @result << sexp
         
     | 
| 
      
 43 
     | 
    
         
            +
                    recur(sexp[3])
         
     | 
| 
      
 44 
     | 
    
         
            +
                    recur(sexp[1])
         
     | 
| 
      
 45 
     | 
    
         
            +
                  when :method_add_arg      # [:method_add_arg, call, args]
         
     | 
| 
      
 46 
     | 
    
         
            +
                    @result << sexp
         
     | 
| 
      
 47 
     | 
    
         
            +
                    recur(sexp[2])
         
     | 
| 
      
 48 
     | 
    
         
            +
                    within_method_sexp(sexp[1])
         
     | 
| 
      
 49 
     | 
    
         
            +
                  when :method_add_block    # [:method_add_block, call, block]
         
     | 
| 
      
 50 
     | 
    
         
            +
                    @result << sexp
         
     | 
| 
      
 51 
     | 
    
         
            +
                    within_method_sexp(sexp[1])
         
     | 
| 
      
 52 
     | 
    
         
            +
                  when :binary, :array, :hash, :unary, :defined
         
     | 
| 
       38 
53 
     | 
    
         
             
                    @result << sexp
         
     | 
| 
       39 
54 
     | 
    
         
             
                    list_sexp(sexp)
         
     | 
| 
       40 
55 
     | 
    
         
             
                  when :aref
         
     | 
| 
       41 
56 
     | 
    
         
             
                    @result << sexp
         
     | 
| 
       42 
57 
     | 
    
         
             
                    recur(sexp[1])
         
     | 
| 
       43 
58 
     | 
    
         
             
                    recur(sexp[2])
         
     | 
| 
       44 
     | 
    
         
            -
                  when :brace_block
         
     | 
| 
      
 59 
     | 
    
         
            +
                  when :brace_block         # [:brace_block, nil, statments]
         
     | 
| 
       45 
60 
     | 
    
         
             
                    # ignore
         
     | 
| 
       46 
     | 
    
         
            -
                  when :call, :method_add_block, :method_add_arg
         
     | 
| 
       47 
     | 
    
         
            -
                    @result << sexp
         
     | 
| 
       48 
     | 
    
         
            -
                    method_sexp(sexp)
         
     | 
| 
       49 
61 
     | 
    
         
             
                  when :const_path_ref
         
     | 
| 
       50 
62 
     | 
    
         
             
                    @result << sexp
         
     | 
| 
       51 
63 
     | 
    
         
             
                    recur(sexp[1])
         
     | 
| 
         @@ -61,15 +73,17 @@ module Sorcerer 
     | 
|
| 
       61 
73 
     | 
    
         
             
                  end
         
     | 
| 
       62 
74 
     | 
    
         
             
                end
         
     | 
| 
       63 
75 
     | 
    
         | 
| 
       64 
     | 
    
         
            -
                 
     | 
| 
      
 76 
     | 
    
         
            +
                # When already handling a method call, we don't need to recur on
         
     | 
| 
      
 77 
     | 
    
         
            +
                # some items.
         
     | 
| 
      
 78 
     | 
    
         
            +
                def within_method_sexp(sexp)
         
     | 
| 
       65 
79 
     | 
    
         
             
                  case sexp.first
         
     | 
| 
       66 
     | 
    
         
            -
                  when :call
         
     | 
| 
      
 80 
     | 
    
         
            +
                  when :call                # [:call, target, ".", meth]
         
     | 
| 
       67 
81 
     | 
    
         
             
                    recur(sexp[1])
         
     | 
| 
       68 
     | 
    
         
            -
                  when :method_add_block
         
     | 
| 
       69 
     | 
    
         
            -
                     
     | 
| 
       70 
     | 
    
         
            -
                  when :method_add_arg
         
     | 
| 
      
 82 
     | 
    
         
            +
                  when :method_add_block    # [:method_add_block, call, block]
         
     | 
| 
      
 83 
     | 
    
         
            +
                    within_method_sexp(sexp[1])
         
     | 
| 
      
 84 
     | 
    
         
            +
                  when :method_add_arg      # [:method_add_arg, call, args]
         
     | 
| 
       71 
85 
     | 
    
         
             
                    recur(sexp[2])
         
     | 
| 
       72 
     | 
    
         
            -
                     
     | 
| 
      
 86 
     | 
    
         
            +
                    within_method_sexp(sexp[1])
         
     | 
| 
       73 
87 
     | 
    
         
             
                  else
         
     | 
| 
       74 
88 
     | 
    
         
             
                    recur(sexp)
         
     | 
| 
       75 
89 
     | 
    
         
             
                  end
         
     | 
    
        data/lib/sorcerer/version.rb
    CHANGED
    
    
| 
         @@ -117,6 +117,7 @@ class ResourceTest < Test::Unit::TestCase 
     | 
|
| 
       117 
117 
     | 
    
         
             
                # I don't think we get enough info to accurately resource these.
         
     | 
| 
       118 
118 
     | 
    
         
             
                # All these calls come back with a period rather than a double
         
     | 
| 
       119 
119 
     | 
    
         
             
                # colon.
         
     | 
| 
      
 120 
     | 
    
         
            +
                skip "Can't resource methods calls with ::"
         
     | 
| 
       120 
121 
     | 
    
         
             
                assert_resource "Const::meth(a)"
         
     | 
| 
       121 
122 
     | 
    
         
             
                assert_resource "Const::meth(a, b)"
         
     | 
| 
       122 
123 
     | 
    
         
             
                assert_resource "Const::meth(a, *b)"
         
     | 
| 
         @@ -134,7 +135,14 @@ class ResourceTest < Test::Unit::TestCase 
     | 
|
| 
       134 
135 
     | 
    
         
             
                assert_resource "meth(a, *args, &code)"
         
     | 
| 
       135 
136 
     | 
    
         
             
              end
         
     | 
| 
       136 
137 
     | 
    
         | 
| 
       137 
     | 
    
         
            -
              def  
     | 
| 
      
 138 
     | 
    
         
            +
              def test_can_source_capitalized_method_without_explicit_target
         
     | 
| 
      
 139 
     | 
    
         
            +
                assert_resource "Meth()"
         
     | 
| 
      
 140 
     | 
    
         
            +
                assert_resource "Meth a"
         
     | 
| 
      
 141 
     | 
    
         
            +
                assert_resource "Meth(a)"
         
     | 
| 
      
 142 
     | 
    
         
            +
                assert_resource "Meth { a }"
         
     | 
| 
      
 143 
     | 
    
         
            +
              end
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
      
 145 
     | 
    
         
            +
              def test_can_source_method_without_explicit_target_in_poetry_mode
         
     | 
| 
       138 
146 
     | 
    
         
             
                assert_resource "meth a"
         
     | 
| 
       139 
147 
     | 
    
         
             
                assert_resource "meth a, b"
         
     | 
| 
       140 
148 
     | 
    
         
             
                assert_resource "meth a, b, c"
         
     | 
| 
         @@ -586,6 +594,10 @@ class ResourceTest < Test::Unit::TestCase 
     | 
|
| 
       586 
594 
     | 
    
         
             
                assert_resource_lines "def f █ end"
         
     | 
| 
       587 
595 
     | 
    
         
             
              end
         
     | 
| 
       588 
596 
     | 
    
         | 
| 
      
 597 
     | 
    
         
            +
              def test_can_source_capitalized_def
         
     | 
| 
      
 598 
     | 
    
         
            +
                assert_resource_lines "def F(); end"
         
     | 
| 
      
 599 
     | 
    
         
            +
              end
         
     | 
| 
      
 600 
     | 
    
         
            +
             
     | 
| 
       589 
601 
     | 
    
         
             
              if RUBY_VERSION >= "2.0.0"
         
     | 
| 
       590 
602 
     | 
    
         
             
                def test_can_source_ruby2_defs
         
     | 
| 
       591 
603 
     | 
    
         
             
                  assert_resource_lines "def f(a, b=1, *args, c: 2, **opts, &block); end"
         
     | 
| 
         @@ -4,9 +4,10 @@ require 'ripper' 
     | 
|
| 
       4 
4 
     | 
    
         
             
            require 'pp'
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            class SubexpressionTest < Test::Unit::TestCase
         
     | 
| 
       7 
     | 
    
         
            -
              def assert_subexpressions(code, subexpressions,  
     | 
| 
      
 7 
     | 
    
         
            +
              def assert_subexpressions(code, subexpressions, options={})
         
     | 
| 
       8 
8 
     | 
    
         
             
                sexp = Ripper::SexpBuilder.new(code).parse
         
     | 
| 
       9 
     | 
    
         
            -
                if debug
         
     | 
| 
      
 9 
     | 
    
         
            +
                if options[:debug]
         
     | 
| 
      
 10 
     | 
    
         
            +
                  puts "CODE: <#{code}>"
         
     | 
| 
       10 
11 
     | 
    
         
             
                  pp sexp
         
     | 
| 
       11 
12 
     | 
    
         
             
                end
         
     | 
| 
       12 
13 
     | 
    
         
             
                subs = Sorcerer.subexpressions(sexp)
         
     | 
| 
         @@ -32,7 +33,9 @@ class SubexpressionTest < Test::Unit::TestCase 
     | 
|
| 
       32 
33 
     | 
    
         | 
| 
       33 
34 
     | 
    
         
             
              def test_method_calls_without_args
         
     | 
| 
       34 
35 
     | 
    
         
             
                assert_subexpressions "o.f", ["o.f", "o"]
         
     | 
| 
      
 36 
     | 
    
         
            +
                assert_subexpressions "f",   ["f"]
         
     | 
| 
       35 
37 
     | 
    
         
             
                assert_subexpressions "f()", ["f()"]
         
     | 
| 
      
 38 
     | 
    
         
            +
                assert_subexpressions "F()", ["F()"]
         
     | 
| 
       36 
39 
     | 
    
         
             
              end
         
     | 
| 
       37 
40 
     | 
    
         | 
| 
       38 
41 
     | 
    
         
             
              def test_method_calls_with_args
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,15 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: sorcerer
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.3. 
     | 
| 
       5 
     | 
    
         
            -
              prerelease: 
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.11
         
     | 
| 
       6 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       8 
7 
     | 
    
         
             
            - Jim Weirich
         
     | 
| 
       9 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2013- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2013-07-10 00:00:00.000000000 Z
         
     | 
| 
       13 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       14 
13 
     | 
    
         
             
            description: Generate the original Ruby source from a Ripper-style abstract syntax
         
     | 
| 
       15 
14 
     | 
    
         
             
              tree.
         
     | 
| 
         @@ -35,6 +34,7 @@ files: 
     | 
|
| 
       35 
34 
     | 
    
         
             
            - test/sorcerer/subexpression_test.rb
         
     | 
| 
       36 
35 
     | 
    
         
             
            homepage: http://github.com/jimweirich/sorcerer
         
     | 
| 
       37 
36 
     | 
    
         
             
            licenses: []
         
     | 
| 
      
 37 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
       38 
38 
     | 
    
         
             
            post_install_message: 
         
     | 
| 
       39 
39 
     | 
    
         
             
            rdoc_options:
         
     | 
| 
       40 
40 
     | 
    
         
             
            - --line-numbers
         
     | 
| 
         @@ -44,21 +44,19 @@ rdoc_options: 
     | 
|
| 
       44 
44 
     | 
    
         
             
            require_paths:
         
     | 
| 
       45 
45 
     | 
    
         
             
            - lib
         
     | 
| 
       46 
46 
     | 
    
         
             
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
       47 
     | 
    
         
            -
              none: false
         
     | 
| 
       48 
47 
     | 
    
         
             
              requirements:
         
     | 
| 
       49 
     | 
    
         
            -
              - -  
     | 
| 
      
 48 
     | 
    
         
            +
              - - '>='
         
     | 
| 
       50 
49 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       51 
50 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       52 
51 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       53 
     | 
    
         
            -
              none: false
         
     | 
| 
       54 
52 
     | 
    
         
             
              requirements:
         
     | 
| 
       55 
     | 
    
         
            -
              - -  
     | 
| 
      
 53 
     | 
    
         
            +
              - - '>='
         
     | 
| 
       56 
54 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       57 
55 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       58 
56 
     | 
    
         
             
            requirements: []
         
     | 
| 
       59 
57 
     | 
    
         
             
            rubyforge_project: sorcerer
         
     | 
| 
       60 
     | 
    
         
            -
            rubygems_version:  
     | 
| 
      
 58 
     | 
    
         
            +
            rubygems_version: 2.0.3
         
     | 
| 
       61 
59 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       62 
     | 
    
         
            -
            specification_version:  
     | 
| 
      
 60 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
       63 
61 
     | 
    
         
             
            summary: Generate Source from Ripper ASTs
         
     | 
| 
       64 
62 
     | 
    
         
             
            test_files: []
         
     |