ripgrep 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cafb81708017c1ce6aaa88f54211574a80d72c871061fa14204198a4132a2431
4
- data.tar.gz: 47aeb2330a95c67ec6af3fffd0e80fda58e16708caad5e08303e678af9454110
3
+ metadata.gz: 3778f790aa4fe46bd2573b5e5fefa8429cfda234928d56c89b4b5485c8e681d4
4
+ data.tar.gz: 5e15af07a7008e772666d35a0c38e0e5d2ad8824a4ae4a42b77c2073d4252645
5
5
  SHA512:
6
- metadata.gz: e075f5ba6d493db81d068696a724e8ddaaac311b22dcb368e86552f43cf77e1a2051f7d55e2215b999d3580b9877406b6f0fde465d82f1d06a4d4dc7b5b78f99
7
- data.tar.gz: 76fff37ad3a3e68793356d38702ff3b156e95f1ab3bd80aaf6e040b0622cedc606e4ae5fcb8d6c6977153d7d531ca42b2f02a4fec5331e18a9cf539f9bba40be
6
+ metadata.gz: 53c17879617f7a49629ffda4099cd231ae1b2746c3b1c456a7a613b453dbb55466996b560cf8e3db7e46dfda098fe5d59c4cd09f06f6edea1cd28de4e66f29b7
7
+ data.tar.gz: f87295bc407b1b46bc916110c34a74230691d6e3af81cfeaa7c0ebd407456a09477daf8049c7ce1f54a7ccb25462bf08224bc0c97154f0aaaac0feb8eb30ae4c
data/README.md CHANGED
@@ -40,17 +40,19 @@ puts result
40
40
  # lib/ripgrep.rb:require 'ripgrep/core'
41
41
  # lib/ripgrep.rb:require 'ripgrep/client'
42
42
  # lib/ripgrep.rb:require 'ripgrep/result'
43
- # lib/ripgrep/client.rb:require 'forwardable'
43
+ # lib/ripgrep.rb:require 'ripgrep/match'
44
44
  # lib/ripgrep/core.rb:require 'open3'
45
+ # lib/ripgrep/client.rb:require 'forwardable'
45
46
 
46
- puts result.matches
47
+ puts result.matches.map(&:to_json)
47
48
  # =>
48
- # {:file=>"lib/ripgrep.rb", :body=>"require 'ripgrep/version'"}
49
- # {:file=>"lib/ripgrep.rb", :body=>"require 'ripgrep/core'"}
50
- # {:file=>"lib/ripgrep.rb", :body=>"require 'ripgrep/client'"}
51
- # {:file=>"lib/ripgrep.rb", :body=>"require 'ripgrep/result'"}
52
- # {:file=>"lib/ripgrep/client.rb", :body=>"require 'forwardable'"}
53
- # {:file=>"lib/ripgrep/core.rb", :body=>"require 'open3'"}
49
+ # {"file":"lib/ripgrep.rb","body":"require 'ripgrep/version'","raw_line":"lib/ripgrep.rb:require 'ripgrep/version'"}
50
+ # {"file":"lib/ripgrep.rb","body":"require 'ripgrep/core'","raw_line":"lib/ripgrep.rb:require 'ripgrep/core'"}
51
+ # {"file":"lib/ripgrep.rb","body":"require 'ripgrep/client'","raw_line":"lib/ripgrep.rb:require 'ripgrep/client'"}
52
+ # {"file":"lib/ripgrep.rb","body":"require 'ripgrep/result'","raw_line":"lib/ripgrep.rb:require 'ripgrep/result'"}
53
+ # {"file":"lib/ripgrep.rb","body":"require 'ripgrep/match'","raw_line":"lib/ripgrep.rb:require 'ripgrep/match'"}
54
+ # {"file":"lib/ripgrep/core.rb","body":"require 'open3'","raw_line":"lib/ripgrep/core.rb:require 'open3'"}
55
+ # {"file":"lib/ripgrep/client.rb","body":"require 'forwardable'","raw_line":"lib/ripgrep/client.rb:require 'forwardable'"}
54
56
 
55
57
  ### Search like `rg --ignore-case ruby ripgrep.gemspec`
56
58
  result = rg.exec 'ruby', path: 'ripgrep.gemspec', options: { ignore_case: true }
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "ripgrep"
3
+ require 'bundler/setup'
4
+ require 'pry'
5
+ require 'ripgrep'
5
6
 
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
7
+ def rg
8
+ @rg ||= Ripgrep::Client.new
9
+ end
8
10
 
9
- require "pry"
10
11
  Pry.start
@@ -2,6 +2,7 @@ require 'ripgrep/version'
2
2
  require 'ripgrep/core'
3
3
  require 'ripgrep/client'
4
4
  require 'ripgrep/result'
5
+ require 'ripgrep/match'
5
6
 
6
7
  module Ripgrep
7
8
  class Error < StandardError; end
@@ -0,0 +1,19 @@
1
+ module Ripgrep
2
+ class Match
3
+ attr_reader :file, :body, :raw_line
4
+
5
+ def initialize(file:, body:, raw_line:)
6
+ @file = file
7
+ @body = body
8
+ @raw_line = raw_line
9
+ end
10
+
11
+ def to_s
12
+ raw_line
13
+ end
14
+
15
+ def to_json
16
+ { file: file, body: body, raw_line: raw_line }.to_json
17
+ end
18
+ end
19
+ end
@@ -14,10 +14,10 @@ module Ripgrep
14
14
  @exit_status = exit_status
15
15
 
16
16
  # TODO: skip when not matching result. like a help or version.
17
+ # $ rg --files で対象ファイルが取れるので、これと比較してmatch結果かどうか見るのがいいかも
17
18
  @matches = result.split("\n").map do |line|
18
- # TODO: implement Match class. make more rich and useful interface.
19
19
  file, *body = line.split(':')
20
- { file: file, body: body.join(':') }
20
+ Match.new file: file, body: body.join(':'), raw_line: line
21
21
  end
22
22
 
23
23
  case exit_status
@@ -1,3 +1,3 @@
1
1
  module Ripgrep
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripgrep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - motoki-shun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-12 00:00:00.000000000 Z
11
+ date: 2019-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,6 +85,7 @@ files:
85
85
  - lib/ripgrep.rb
86
86
  - lib/ripgrep/client.rb
87
87
  - lib/ripgrep/core.rb
88
+ - lib/ripgrep/match.rb
88
89
  - lib/ripgrep/result.rb
89
90
  - lib/ripgrep/version.rb
90
91
  - ripgrep.gemspec