code_analyzer 0.5.2 → 0.5.5

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
  SHA256:
3
- metadata.gz: 5a68561649e1e345495d4a494530dc7abb9ca256dc5a999d1aa71b1c567b0e66
4
- data.tar.gz: d21414e33aa72bbb23571985b9eaa00e177057f7781cbb3f1398476119f38c69
3
+ metadata.gz: 4c37841a3a698b9ce2fa6c4aa80b0a03eb204a4f6ae43e3a0c8d48e78c5f8916
4
+ data.tar.gz: f4e3b26a9afb7ce80266d590a98e5f838944b9a892a8748374828aa4387aa592
5
5
  SHA512:
6
- metadata.gz: 99369336e083dd38d76e7436ee9d824565108760339d3da59b057649341917da4649e68c78f01a29ba45c09c95a2ca71c1b2392d9c2a252826cb81abb2580131
7
- data.tar.gz: cbba861e5caa35dcd4a0e887159ae0a14bb166a21f2b0bb8b5e33f188c346f9b71b6b11bbee253e9ee2b18b4fc7be039801d438168d43d00b4f007b0541698d8
6
+ metadata.gz: 60042c122b97be0ece07e2898f245430f4ff8d11f61d68008de00f1a37bd8fa4022d33f98f5d3d13c04138afaa4c6ce724ead33be9ead570b8194809742b7eb7
7
+ data.tar.gz: e4ee8925dadae37e1a594c114a0ddff4e09e2adabdc92621284323bdd2cb9247b4ec0829a252b6e3050dac5453c250b98b61d3b44f513bbae77aa45bac5c5ac1
@@ -0,0 +1,31 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: CI
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+ runs-on: ubuntu-latest
19
+ strategy:
20
+ matrix:
21
+ ruby-version: ['2.6', '2.7', '3.0', '3.1']
22
+
23
+ steps:
24
+ - uses: actions/checkout@v2
25
+ - name: Set up Ruby
26
+ uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: ${{ matrix.ruby-version }}
29
+ bundler-cache: true
30
+ - name: Run tests
31
+ run: bundle exec rspec spec
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.0
data/README.md CHANGED
@@ -1,11 +1,6 @@
1
1
  # CodeAnalyzer
2
2
 
3
- | Project | code_analyzer
4
- |:---------|:--------------------------------------------
5
- | Homepage | https://github.com/flyerhzm/code_analyzer
6
- | Document | http://rubydoc.info/gems/code_analyzer/frames
7
- | CI | [![Build Status](https://travis-ci.org/flyerhzm/code_analyzer.png)](https://travis-ci.org/flyerhzm/code_analyzer)
8
- | Author | [Richard Huang][0]
3
+ [![CI](https://github.com/flyerhzm/code_analyzer/actions/workflows/main.yml/badge.svg)](https://github.com/flyerhzm/code_analyzer/actions/workflows/main.yml)
9
4
 
10
5
  code_analyzer is extracted from [rails_best_practices][1], it helps you
11
6
  easily build your own code analyzer tool.
@@ -36,5 +31,4 @@ Or install it yourself as:
36
31
  4. Push to the branch (`git push origin my-new-feature`)
37
32
  5. Create new Pull Request
38
33
 
39
- [0]: http://huangzhimin.com
40
34
  [1]: https://github.com/railsbp/rails_best_practices
@@ -688,6 +688,31 @@ class Sexp
688
688
  end
689
689
  end
690
690
 
691
+ # Get the hash key
692
+ #
693
+ # s(:assoc_new, s(:@label, "first_name:", s(1, 1)), s(:string_literal, s(:string_add, s(:string_content), s(:@tstring_content, "Richard", s(1, 14)))))
694
+ # =>
695
+ # s(:@label, "first_name:", s(1, 1))
696
+ def key
697
+ if :assoc_new == sexp_type
698
+ self[1].to_s
699
+ end
700
+ end
701
+
702
+ # Get the hash value
703
+ #
704
+ # s(:assoc_new, s(:@label, "first_name:", s(1, 1)), s(:string_literal, s(:string_add, s(:string_content), s(:@tstring_content, "Richard", s(1, 14)))))
705
+ # =>
706
+ # s(:string_literal, s(:string_add, s(:string_content), s(:@tstring_content, "Richard", s(1, 14))))
707
+ def value
708
+ if :assoc_new == sexp_type
709
+ return nil if self[2].nil?
710
+ return self[2] if :array == self[2].sexp_type
711
+
712
+ self[2].to_s
713
+ end
714
+ end
715
+
691
716
  # Get the array size.
692
717
  #
693
718
  # s(:array,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodeAnalyzer
4
- VERSION = '0.5.2'
4
+ VERSION = '0.5.5'
5
5
  end
@@ -644,6 +644,42 @@ describe Sexp do
644
644
  end
645
645
  end
646
646
 
647
+ describe 'key' do
648
+ it 'should get key for assoc_new' do
649
+ node =
650
+ parse_content("add_user :user, first_name: 'Richard'").grep_node(
651
+ sexp_type: :assoc_new
652
+ )
653
+ expect(node.key).to eq 'first_name'
654
+ end
655
+ end
656
+
657
+ describe 'value' do
658
+ it 'should get value for assoc_new' do
659
+ node =
660
+ parse_content("add_user :user, first_name: 'Richard'").grep_node(
661
+ sexp_type: :assoc_new
662
+ )
663
+ expect(node.value).to eq 'Richard'
664
+ end
665
+
666
+ it 'should get value for assoc_new' do
667
+ node =
668
+ parse_content("add_user :user, first_name:").grep_node(
669
+ sexp_type: :assoc_new
670
+ )
671
+ expect(node.value).to be_nil
672
+ end
673
+
674
+ it 'should get array value for assoc_new' do
675
+ node =
676
+ parse_content("add_user :user, name: %w[Richard Huang]").grep_node(
677
+ sexp_type: :assoc_new
678
+ )
679
+ expect(node.value.array_values.map(&:to_s)).to eq ['Richard', 'Huang']
680
+ end
681
+ end
682
+
647
683
  describe 'array_size' do
648
684
  it 'should get array size' do
649
685
  node = parse_content("['first_name', 'last_name']").grep_node(sexp_type: :array)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-01 00:00:00.000000000 Z
11
+ date: 2022-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sexp_processor
@@ -60,9 +60,10 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
+ - ".github/workflows/main.yml"
63
64
  - ".gitignore"
64
65
  - ".rspec"
65
- - ".travis.yml"
66
+ - ".ruby-version"
66
67
  - Gemfile
67
68
  - LICENSE
68
69
  - README.md
@@ -106,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
107
  - !ruby/object:Gem::Version
107
108
  version: '0'
108
109
  requirements: []
109
- rubygems_version: 3.1.2
110
+ rubygems_version: 3.3.3
110
111
  signing_key:
111
112
  specification_version: 4
112
113
  summary: a code analyzer helps you build your own code analyzer tool.
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- rvm:
4
- - 2.6.6
5
- - 2.7.1