code_breaker 0.1.1 → 1.0.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
- SHA1:
3
- metadata.gz: 3b10f45d7870b6729fc5b5632f03351e45014589
4
- data.tar.gz: 40d6687ab9d31cda37ef4cf9d0bb881899e7f047
2
+ SHA256:
3
+ metadata.gz: 34e130c3a963be818c41a997843620e65a3e89aa4daa4aad2d0ffdb8aa380087
4
+ data.tar.gz: e55c8809962f90a39ff8b5ad73f7cb1b3b45d2572f8954578fefabfe8ba00051
5
5
  SHA512:
6
- metadata.gz: 052ec71488e79e1e53bf761976fc16ba2c409469a6c0f8de0be8d41b14db445804564b90ec1007a694e7c1eb287772e1493993434593d30a9152faeef41d804f
7
- data.tar.gz: e02cf3f28507ca5ae3e52ae2a031b73665921aa99e684bc7a1b150820a73a8043fef8ee5fed76b9b9cb3b0835a866838d979391f9c42e99e1e00432da0c40740
6
+ metadata.gz: 42ed1c04674bb3049df6c4a1805cda4e17594ca84f99d48ceb159a9d96580d0061bb9d4c774bb33b0f77dcdb106ab145c616aaaa2a456e0825f2ac3ae213e847
7
+ data.tar.gz: dbb5fe81fa8690056f738496add777f80ae6aab7ab3d36fac9834096cd9ded694bd8ebf744fbfb2926ca83b37039231d23b15679249a922f98a39d5f86932dd1
@@ -0,0 +1,33 @@
1
+ name: Ruby CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main, develop ]
6
+ pull_request:
7
+ branches: [ main, develop ]
8
+
9
+ jobs:
10
+ test:
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ os: [ ubuntu-latest, macos-latest, windows-latest ]
15
+ ruby: [ 2.5, 2.6, 2.7, ruby-head ]
16
+ runs-on: ${{ matrix.os }}
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby }}
22
+ - uses: actions/cache@v2
23
+ with:
24
+ path: vendor/bundle
25
+ key: ${{ matrix.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
26
+ restore-keys: |
27
+ ${{ matrix.os }}-gems-
28
+ - name: Install dependencies
29
+ run: |
30
+ gem install bundler
31
+ bundle install --jobs 4 --retry 3
32
+ - name: Run Tests
33
+ run: bundle exec rake default
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # CodeBreaker
2
2
 
3
- [![Build Status](https://travis-ci.org/daigaku-ruby/code_breaker.svg?branch=master)](https://travis-ci.org/daigaku-ruby/code_breaker)
3
+ [![Build Status](https://github.com/daigaku-ruby/code_breaker/workflows/Ruby%20CI/badge.svg)](https://github.com/daigaku-ruby/code_breaker/workflows/Ruby%20CI/badge.svg)
4
4
  [![Gem Version](https://badge.fury.io/rb/code_breaker.svg)](http://badge.fury.io/rb/code_breaker)
5
5
 
6
6
  CodeBreaker breaks a line of Ruby code into its receiver classes and the methods
@@ -13,7 +13,7 @@ sum = Rational(2, 3) + 4
13
13
  ```
14
14
 
15
15
  By breaking down this line into the receiver classes and called methods you can
16
- check e.g. whether a code snippet assigns the sum of a Rational and a Fixnum to
16
+ check e.g. whether a code snippet assigns the sum of a Rational and an Integer to
17
17
  a variable with the name `sum`.
18
18
 
19
19
  Testing global code snippets might be important for testing the code of simple
@@ -44,7 +44,7 @@ require 'code_breaker'
44
44
 
45
45
  code_snippet = 'crazy_number = Rational(3, 5) + 42 - Complex(2.3, 6.4) * 1.2'
46
46
  CodeBreaker.parse(code_snippet)
47
- # => {:lvasgn=>[:crazy_number, [Rational, :+, Fixnum, :-, Complex, :*, Float]]}
47
+ # => {:lvasgn=>[:crazy_number, [Rational, :+, Integer, :-, Complex, :*, Float]]}
48
48
 
49
49
  code_snippet = '"hello" + "World"'
50
50
  CodeBreaker.parse(code_snippet)
@@ -79,10 +79,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
79
79
 
80
80
  ## Contributing
81
81
 
82
- Bug reports and pull requests are welcome on GitHub at https://github.com/daigaku-ruby/code_breaker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
83
-
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/daigaku-ruby/code_breaker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant code of conduct](http://contributor-covenant.org/version/1/2/0).
84
83
 
85
84
  ## License
86
85
 
87
86
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
88
-
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "code_breaker"
3
+ require 'bundler/setup'
4
+ require 'code_breaker'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "code_breaker"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -4,33 +4,33 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'code_breaker/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "code_breaker"
7
+ spec.name = 'code_breaker'
8
8
  spec.version = CodeBreaker::VERSION
9
- spec.authors = ["Paul Götze"]
10
- spec.email = ["paul.christoph.goetze@gmail.com"]
9
+ spec.authors = ['Paul Götze']
10
+ spec.email = ['paul.christoph.goetze@gmail.com']
11
11
 
12
- spec.summary = %q{Breaking a Ruby code snippet into a sequence of classes and their connecting methods.}
13
- spec.description = %q{Breaking a Ruby code snippet into a sequence of classes and their connecting methods.}
14
- spec.homepage = "https://github.com/daigaku-ruby/code_breaker"
15
- spec.license = "MIT"
12
+ spec.summary = 'Breaking a Ruby code snippet into a sequence of classes and their connecting methods.'
13
+ spec.description = 'Breaking a Ruby code snippet into a sequence of classes and their connecting methods.'
14
+ spec.homepage = 'https://github.com/daigaku-ruby/code_breaker'
15
+ spec.license = 'MIT'
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
18
  # delete this section to allow pushing this gem to any host.
19
19
  if spec.respond_to?(:metadata)
20
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
21
  else
22
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
23
  end
24
24
 
25
25
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
- spec.bindir = "exe"
26
+ spec.bindir = 'exe'
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
28
+ spec.require_paths = ['lib']
29
+ spec.required_ruby_version = '~> 2.5'
29
30
 
30
- spec.add_dependency "parser", "~> 2.2"
31
- spec.add_dependency "activesupport", "~> 4"
31
+ spec.add_dependency 'parser', '~> 2.7'
32
32
 
33
- spec.add_development_dependency "bundler", "~> 1.10"
34
- spec.add_development_dependency "rake", "~> 10.0"
35
- spec.add_development_dependency "rspec", " ~> 3.2"
33
+ spec.add_development_dependency 'bundler', '~> 2.0'
34
+ spec.add_development_dependency 'rake', '~> 13.0'
35
+ spec.add_development_dependency 'rspec', '~> 3.9'
36
36
  end
@@ -2,7 +2,6 @@ require 'code_breaker/version'
2
2
  require 'code_breaker/parser'
3
3
 
4
4
  module CodeBreaker
5
-
6
5
  def self.parse(code)
7
6
  CodeBreaker::Parser.new(code).run
8
7
  end
@@ -1,50 +1,60 @@
1
- require 'active_support/concern'
2
-
3
1
  module CodeBreaker
4
2
  module Parsable
5
3
  module Assignments
6
-
7
- extend ActiveSupport::Concern
8
4
  include Parsable::Node
9
5
 
10
- included do
11
- alias :parse_lvasgn_node :parse_as_hash # local variable assignment
12
- alias :parse_ivasgn_node :parse_as_hash # instance variable assignment
13
- alias :parse_cvasgn_node :parse_as_hash # class variable assignment
14
- alias :parse_gvasgn_node :parse_as_hash # global variable assignment
15
- alias :parse_op_asgn_node :parse_as_hash # operation assignment
16
- alias :parse_or_asgn_node :parse_as_hash # or assignment
17
- alias :parse_and_asgn_node :parse_as_hash # and assignment
18
-
19
- # multiple assignment
20
- def parse_masgn_node(node)
21
- lhs, rhs = parse_children(node)
22
-
23
- values = if rhs.kind_of?(Hash) && rhs.has_key?(:array)
24
- rhs[:array]
25
- else
26
- [rhs] + (1...lhs.count).map { NilClass }
27
- end
28
-
29
- { node.type => { lhs => values } }
30
- end
6
+ # local variable assignment
7
+ alias_method :parse_lvasgn_node, :parse_as_hash
31
8
 
32
- # multiple left hand side
33
- def parse_mlhs_node(node)
34
- parse_children(node).map(&:values).flatten
35
- end
9
+ # instance variable assignment
10
+ alias_method :parse_ivasgn_node, :parse_as_hash
36
11
 
37
- # constant assignment
38
- def parse_casgn_node(node)
39
- name = node.children[1]
40
- children = node.children[2]
41
- value = children.nil? ? name : [name, parse(node.children[2])]
12
+ # class variable assignment
13
+ alias_method :parse_cvasgn_node, :parse_as_hash
42
14
 
43
- { node.type => value }
44
- end
15
+ # global variable assignment
16
+ alias_method :parse_gvasgn_node, :parse_as_hash
17
+
18
+ # operation assignment
19
+ alias_method :parse_op_asgn_node, :parse_as_hash
20
+
21
+ # or assignment
22
+ alias_method :parse_or_asgn_node, :parse_as_hash
23
+
24
+ # and assignment
25
+ alias_method :parse_and_asgn_node, :parse_as_hash
26
+
27
+ # multiple assignment
28
+ def parse_masgn_node(node)
29
+ lhs, rhs = parse_children(node)
30
+ values = multiple_assignment_values(lhs, rhs)
45
31
 
32
+ { node.type => { lhs => values } }
46
33
  end
47
34
 
35
+ # multiple left hand side
36
+ def parse_mlhs_node(node)
37
+ parse_children(node).map(&:values).flatten
38
+ end
39
+
40
+ # constant assignment
41
+ def parse_casgn_node(node)
42
+ name = node.children[1]
43
+ children = node.children[2]
44
+ value = children.nil? ? name : [name, parse(node.children[2])]
45
+
46
+ { node.type => value }
47
+ end
48
+
49
+ private
50
+
51
+ def multiple_assignment_values(lhs, rhs)
52
+ if rhs.is_a?(Hash) && rhs.key?(:array)
53
+ rhs[:array]
54
+ else
55
+ [rhs] + (1...lhs.count).map { NilClass }
56
+ end
57
+ end
48
58
  end
49
59
  end
50
60
  end
@@ -1,57 +1,64 @@
1
- require 'active_support/concern'
2
-
3
1
  module CodeBreaker
4
2
  module Parsable
5
3
  module DataTypes
6
-
7
- extend ActiveSupport::Concern
8
4
  include Parsable::Node
9
5
 
10
- included do
11
- def parse_nil_node(node)
12
- NilClass
13
- end
6
+ def parse_nil_node(node)
7
+ NilClass
8
+ end
14
9
 
15
- def parse_true_node(node)
16
- TrueClass
17
- end
10
+ def parse_true_node(node)
11
+ TrueClass
12
+ end
18
13
 
19
- def parse_false_node(node)
20
- FalseClass
21
- end
14
+ def parse_false_node(node)
15
+ FalseClass
16
+ end
22
17
 
23
- def parse_str_node(node)
24
- String
25
- end
18
+ def parse_str_node(node)
19
+ String
20
+ end
26
21
 
27
- # interpolated executed string
28
- def parse_xstr_node(node)
29
- { node.type => parse_children(node).first }
30
- end
22
+ # interpolated executed string
23
+ def parse_xstr_node(node)
24
+ { node.type => parse_children(node).first }
25
+ end
31
26
 
32
- def parse_sym_node(node)
33
- Symbol
27
+ # interpolated string
28
+ def parse_dstr_node(node)
29
+ values = parse_as_hash(node)[node.type].map do |value|
30
+ if value.is_a?(Array)
31
+ value.flatten(1)
32
+ else
33
+ value
34
+ end
34
35
  end
35
36
 
36
- def parse_float_node(node)
37
- Float
38
- end
37
+ { node.type => values }
38
+ end
39
39
 
40
- def parse_regexp_node(node)
41
- Regexp
42
- end
40
+ def parse_sym_node(node)
41
+ Symbol
42
+ end
43
43
 
44
- def parse_int_node(node)
45
- node.children[0].class
46
- end
44
+ def parse_float_node(node)
45
+ Float
46
+ end
47
47
 
48
- def parse_pair_node(node)
49
- { parse(node.children[0]) => parse(node.children[1]) }
50
- end
48
+ def parse_regexp_node(node)
49
+ Regexp
50
+ end
51
51
 
52
- alias :parse_hash_node :parse_as_hash
53
- alias :parse_array_node :parse_as_hash
52
+ def parse_int_node(node)
53
+ node.children[0].class
54
54
  end
55
+
56
+ def parse_pair_node(node)
57
+ { parse(node.children[0]) => parse(node.children[1]) }
58
+ end
59
+
60
+ alias_method :parse_hash_node, :parse_as_hash
61
+ alias_method :parse_array_node, :parse_as_hash
55
62
  end
56
63
  end
57
64
  end
@@ -1,102 +1,95 @@
1
- require 'active_support/concern'
2
-
3
1
  module CodeBreaker
4
2
  module Parsable
5
3
  module Keywords
6
-
7
- extend ActiveSupport::Concern
8
4
  include Parsable::Node
9
5
 
10
- included do
11
- alias :parse_or_node :parse_as_hash
12
- alias :parse_and_node :parse_as_hash
13
- alias :parse_def_node :parse_as_hash
14
- alias :parse_yield_node :parse_as_hash
15
- alias :parse_rescue_node :parse_as_hash
16
- alias :parse_resbody_node :parse_as_hash
6
+ alias_method :parse_or_node, :parse_as_hash
7
+ alias_method :parse_and_node, :parse_as_hash
8
+ alias_method :parse_def_node, :parse_as_hash
9
+ alias_method :parse_yield_node, :parse_as_hash
10
+ alias_method :parse_rescue_node, :parse_as_hash
11
+ alias_method :parse_resbody_node, :parse_as_hash
17
12
 
18
- alias :parse_break_node :parse_as_node_type
19
- alias :parse_next_node :parse_as_node_type
20
- alias :parse_retry_node :parse_as_node_type
21
- alias :parse_self_node :parse_as_node_type
13
+ alias_method :parse_break_node, :parse_as_node_type
14
+ alias_method :parse_next_node, :parse_as_node_type
15
+ alias_method :parse_retry_node, :parse_as_node_type
16
+ alias_method :parse_self_node, :parse_as_node_type
22
17
 
23
- def parse_loop_node(node)
24
- condition = node.children[0]
25
- body = node.children[1]
18
+ def parse_loop_node(node)
19
+ condition = node.children[0]
20
+ body = node.children[1]
26
21
 
27
- { node.type => parse(condition), do: parse(body) }
28
- end
22
+ { node.type => parse(condition), do: parse(body) }
23
+ end
29
24
 
30
- alias :parse_while_node :parse_loop_node
31
- alias :parse_until_node :parse_loop_node
25
+ alias_method :parse_while_node, :parse_loop_node
26
+ alias_method :parse_until_node, :parse_loop_node
32
27
 
33
- def parse_for_node(node)
34
- variable = node.children[0]
35
- range = node.children[1]
36
- body = node.children[2]
28
+ def parse_for_node(node)
29
+ variable = node.children[0]
30
+ range = node.children[1]
31
+ body = node.children[2]
37
32
 
38
- { node.type => parse(variable), in: parse(range), do: parse(body) }
39
- end
33
+ { node.type => parse(variable), in: parse(range), do: parse(body) }
34
+ end
40
35
 
41
- def parse_if_node(node)
42
- condition = node.children[0]
43
- if_body = node.children[1]
44
- else_body = node.children[2]
36
+ def parse_if_node(node)
37
+ condition = node.children[0]
38
+ if_body = node.children[1]
39
+ else_body = node.children[2]
45
40
 
46
- clause = { node.type => parse(condition), then: parse(if_body) }
47
- clause[:else] = parse(else_body) if else_body
41
+ clause = { node.type => parse(condition), then: parse(if_body) }
42
+ clause[:else] = parse(else_body) if else_body
48
43
 
49
- clause
50
- end
44
+ clause
45
+ end
51
46
 
52
- def parse_module_node(node)
53
- name = parse(node.children[0])
54
- body = node.children[1].nil? ? nil : parse(node.children[1])
55
- value = body ? [name, body] : [name]
47
+ def parse_module_node(node)
48
+ name = parse(node.children[0])
49
+ body = node.children[1].nil? ? nil : parse(node.children[1])
50
+ value = body ? [name, body] : [name]
56
51
 
57
- { node.type => value }
58
- end
52
+ { node.type => value }
53
+ end
59
54
 
60
- def parse_return_node(node)
61
- children = parse_children(node)
62
- values = children.length == 1 ? children[0] : children
55
+ def parse_return_node(node)
56
+ children = parse_children(node)
57
+ values = children.length == 1 ? children[0] : children
63
58
 
64
- { node.type => values }
65
- end
59
+ { node.type => values }
60
+ end
66
61
 
67
- def parse_kwbegin_node(node)
68
- rescue_given = node.children.first.type == :rescue
62
+ def parse_kwbegin_node(node)
63
+ rescue_given = node.children.first.type == :rescue
69
64
 
70
- if rescue_given
71
- rescue_part = parse(node.children.first)[:rescue]
65
+ if rescue_given
66
+ rescue_part = parse(node.children.first)[:rescue]
72
67
 
73
- {
74
- begin: rescue_part.first,
75
- rescue: rescue_part.last[:resbody].first
76
- }
77
- else
78
- { begin: parse(node.children.last) }
79
- end
68
+ {
69
+ begin: rescue_part.first,
70
+ rescue: rescue_part.last[:resbody].first
71
+ }
72
+ else
73
+ { begin: parse(node.children.last) }
80
74
  end
75
+ end
81
76
 
82
- def parse_case_node(node)
83
- case_part = parse(node.children.first)
84
- when_parts = node.children[1...-1].map { |child| parse(child) }
85
- else_part = parse(node.children.last)
77
+ def parse_case_node(node)
78
+ case_part = parse(node.children.first)
79
+ when_parts = node.children[1...-1].map { |child| parse(child) }
80
+ else_part = parse(node.children.last)
86
81
 
87
- statement = { case: when_parts.unshift(case_part) }
88
- statement[:case] << { else: else_part } if else_part
89
- statement
90
- end
82
+ statement = { case: when_parts.unshift(case_part) }
83
+ statement[:case] << { else: else_part } if else_part
84
+ statement
85
+ end
91
86
 
92
- def parse_when_node(node)
93
- when_part = parse(node.children[0])
94
- then_part = parse(node.children[1])
87
+ def parse_when_node(node)
88
+ when_part = parse(node.children[0])
89
+ then_part = parse(node.children[1])
95
90
 
96
- { when: when_part, then: then_part }
97
- end
91
+ { when: when_part, then: then_part }
98
92
  end
99
-
100
93
  end
101
94
  end
102
95
  end
@@ -1,34 +1,36 @@
1
- require 'active_support/concern'
2
-
3
1
  module CodeBreaker
4
2
  module Parsable
5
3
  module LanguageElements
6
-
7
- extend ActiveSupport::Concern
8
4
  include Parsable::Node
9
5
 
10
- included do
11
- alias :parse_block_node :parse_as_hash
12
- alias :parse_args_node :parse_as_hash
13
- alias :parse_arg_node :parse_as_last_child_hash
14
- alias :parse_blockarg_node :parse_as_last_child_hash
15
- alias :parse_restarg_node :parse_as_last_child_hash
16
- alias :parse_optarg_node :parse_as_hash # optional argument
17
- alias :parse_kwarg_node :parse_as_last_child_hash # keyword argument
18
- alias :parse_kwoptarg_node :parse_as_hash # optional keyword argument
19
- alias :parse_kwrestarg_node :parse_as_last_child_hash # keyword rest argument
20
-
21
- def parse_block_pass_node(node)
22
- { node.type => node.children.first.children.last }
23
- end
24
-
25
- def parse_splat_node(node)
26
- children = parse_children(node).flatten(1)
27
- values = children.length == 1 ? children[0] : children
28
-
29
- { node.type => values }
30
- end
6
+ alias_method :parse_block_node, :parse_as_hash
7
+ alias_method :parse_args_node, :parse_as_hash
8
+ alias_method :parse_arg_node, :parse_as_last_child_hash
9
+ alias_method :parse_blockarg_node, :parse_as_last_child_hash
10
+ alias_method :parse_restarg_node, :parse_as_last_child_hash
11
+
12
+ # optional argument
13
+ alias_method :parse_optarg_node, :parse_as_hash
14
+
15
+ # keyword argument
16
+ alias_method :parse_kwarg_node, :parse_as_last_child_hash
17
+
18
+ # optional keyword argument
19
+ alias_method :parse_kwoptarg_node, :parse_as_hash
20
+
21
+ # keyword rest argument
22
+ alias_method :parse_kwrestarg_node, :parse_as_last_child_hash
23
+
24
+ def parse_block_pass_node(node)
25
+ { node.type => node.children.first.children.last }
26
+ end
27
+
28
+ def parse_splat_node(node)
29
+ children = parse_children(node).flatten(1)
30
+ values = children.length == 1 ? children[0] : children
31
+
32
+ { node.type => values }
31
33
  end
32
34
  end
33
35
  end
34
- end
36
+ end
@@ -1,21 +1,22 @@
1
1
  module CodeBreaker
2
2
  module Parsable
3
3
  module Node
4
-
5
4
  def parse(node)
6
- return if node.nil?
7
-
8
- if node.kind_of?(Symbol)
5
+ if node.is_a?(Symbol)
9
6
  node
7
+ elsif node.nil?
8
+ parse_nil_node(node)
10
9
  else
11
10
  send("parse_#{node.type}_node", node)
12
11
  end
13
12
  end
14
13
 
15
- def parse_children(node)
16
- node.children.reduce([]) do |nodes, child|
17
- nodes << parse(child) unless child.nil?
18
- nodes
14
+ def parse_children(node, compact: true)
15
+ children = node.children
16
+ children = children.compact if compact
17
+
18
+ children.each_with_object([]) do |child, nodes|
19
+ nodes << parse(child)
19
20
  end
20
21
  end
21
22
 
@@ -32,21 +33,24 @@ module CodeBreaker
32
33
  end
33
34
 
34
35
  def method_missing(method, *args, &block)
35
- node_type = method.to_s.match(/^parse_(.+)_node$/).captures.first
36
+ matches = method.to_s.match(/^parse_(.+)_node$/)
37
+ node_type = matches ? matches.captures.first : []
36
38
 
37
39
  if node_type.empty?
38
40
  super
39
41
  else
40
- message = [
41
- "Breaking the node type \"#{node_type}\" is not yet implemented.",
42
- "You can open an issue on this in the project's Github repo under:",
43
- "https://github.com/daigaku-ruby/code_breaker/issues/new\n"
44
- ].join("\n")
45
-
46
- raise NotImplementedError, message
42
+ raise NotImplementedError, not_implemented_message(node_type)
47
43
  end
48
44
  end
49
45
 
46
+ def not_implemented_message(node_type)
47
+ [
48
+ %(Breaking the node type "#{node_type}" is not yet implemented.),
49
+ 'You can open an issue on this in the project’s Github repo under:',
50
+ 'https://github.com/daigaku-ruby/code_breaker/issues/new',
51
+ ''
52
+ ].join("\n")
53
+ end
50
54
  end
51
55
  end
52
56
  end
@@ -1,15 +1,16 @@
1
- require 'active_support/concern'
2
-
3
1
  module CodeBreaker
4
2
  module Parsable
5
3
  module Ranges
6
-
7
- extend ActiveSupport::Concern
8
4
  include Parsable::Node
9
5
 
10
- included do
11
- alias :parse_irange_node :parse_as_hash # inclusive range a..b
12
- alias :parse_erange_node :parse_as_hash # exclusive range a...b
6
+ # inclusive range a..b, a.., ..b
7
+ def parse_irange_node(node)
8
+ { node.type => parse_children(node, compact: false) }
9
+ end
10
+
11
+ # exclusive range a...b, a..., ...b
12
+ def parse_erange_node(node)
13
+ { node.type => parse_children(node, compact: false) }
13
14
  end
14
15
  end
15
16
  end
@@ -1,19 +1,21 @@
1
- require 'active_support/concern'
2
-
3
1
  module CodeBreaker
4
2
  module Parsable
5
3
  module VariableTypes
6
-
7
- extend ActiveSupport::Concern
8
4
  include Parsable::Node
9
5
 
10
- included do
11
- alias :parse_const_node :parse_as_last_child_hash
12
- alias :parse_lvar_node :parse_as_last_child_hash # local variable
13
- alias :parse_ivar_node :parse_as_last_child_hash # instance variable
14
- alias :parse_cvar_node :parse_as_last_child_hash # class variable
15
- alias :parse_gvar_node :parse_as_last_child_hash # global variable
16
- end
6
+ alias_method :parse_const_node, :parse_as_last_child_hash
7
+
8
+ # local variable
9
+ alias_method :parse_lvar_node, :parse_as_last_child_hash
10
+
11
+ # instance variable
12
+ alias_method :parse_ivar_node, :parse_as_last_child_hash
13
+
14
+ # class variable
15
+ alias_method :parse_cvar_node, :parse_as_last_child_hash
16
+
17
+ # global variable
18
+ alias_method :parse_gvar_node, :parse_as_last_child_hash
17
19
  end
18
20
  end
19
21
  end
@@ -1,23 +1,17 @@
1
- require 'active_support/concern'
2
-
3
1
  module CodeBreaker
4
2
  module Parsable
5
3
  module Wrappers
6
-
7
- extend ActiveSupport::Concern
8
4
  include Parsable::Node
9
5
 
10
- included do
11
- def parse_send_node(node)
12
- if [:Rational, :Complex].include?(node.children[1])
13
- return node.children[1].to_s.constantize
14
- end
15
-
16
- parse_children(node).flatten(1)
6
+ def parse_send_node(node)
7
+ if [:Rational, :Complex].include?(node.children[1])
8
+ return Kernel.const_get(node.children[1].to_s)
17
9
  end
18
10
 
19
- alias :parse_begin_node :parse_children
11
+ parse_children(node).flatten(1)
20
12
  end
13
+
14
+ alias_method :parse_begin_node, :parse_children
21
15
  end
22
16
  end
23
17
  end
@@ -1,6 +1,5 @@
1
1
  require 'code_breaker/parsable'
2
2
  require 'parser/current'
3
- require 'active_support/inflector'
4
3
 
5
4
  module CodeBreaker
6
5
  class Parser
@@ -21,12 +20,12 @@ module CodeBreaker
21
20
  def run
22
21
  unless @output
23
22
  ast = ::Parser::CurrentRuby.parse(input)
24
- @output = parse(ast.loc.node)
23
+ @output = ast.nil? ? [] : parse(ast.loc.node)
25
24
  end
26
25
 
27
26
  @output
28
27
  end
29
28
 
30
- alias :output :run
29
+ alias output run
31
30
  end
32
31
  end
@@ -1,3 +1,3 @@
1
1
  module CodeBreaker
2
- VERSION = "0.1.1"
2
+ VERSION = '1.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_breaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Götze
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-22 00:00:00.000000000 Z
11
+ date: 2020-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -16,70 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.2'
19
+ version: '2.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.2'
27
- - !ruby/object:Gem::Dependency
28
- name: activesupport
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '4'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '4'
26
+ version: '2.7'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '1.10'
33
+ version: '2.0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '1.10'
40
+ version: '2.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '10.0'
47
+ version: '13.0'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '10.0'
54
+ version: '13.0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rspec
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '3.2'
61
+ version: '3.9'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: '3.2'
68
+ version: '3.9'
83
69
  description: Breaking a Ruby code snippet into a sequence of classes and their connecting
84
70
  methods.
85
71
  email:
@@ -88,9 +74,9 @@ executables: []
88
74
  extensions: []
89
75
  extra_rdoc_files: []
90
76
  files:
77
+ - ".github/workflows/main.yml"
91
78
  - ".gitignore"
92
79
  - ".rspec"
93
- - ".travis.yml"
94
80
  - CODE_OF_CONDUCT.md
95
81
  - Gemfile
96
82
  - LICENSE.txt
@@ -122,17 +108,16 @@ require_paths:
122
108
  - lib
123
109
  required_ruby_version: !ruby/object:Gem::Requirement
124
110
  requirements:
125
- - - ">="
111
+ - - "~>"
126
112
  - !ruby/object:Gem::Version
127
- version: '0'
113
+ version: '2.5'
128
114
  required_rubygems_version: !ruby/object:Gem::Requirement
129
115
  requirements:
130
116
  - - ">="
131
117
  - !ruby/object:Gem::Version
132
118
  version: '0'
133
119
  requirements: []
134
- rubyforge_project:
135
- rubygems_version: 2.4.6
120
+ rubygems_version: 3.1.3
136
121
  signing_key:
137
122
  specification_version: 4
138
123
  summary: Breaking a Ruby code snippet into a sequence of classes and their connecting
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.0
4
- before_install: gem install bundler -v 1.10.6