gitignore_rb 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/ext/gitignore_binding/Rakefile +29 -1
  4. data/ext/gitignore_binding/src/lib.rs +22 -10
  5. data/ext/gitignore_binding/target/debug/build/advapi32-sys-cfef7a1f30f1e5f6/build-script-build +0 -0
  6. data/ext/gitignore_binding/target/debug/build/advapi32-sys-cfef7a1f30f1e5f6/build_script_build.dSYM/Contents/Info.plist +20 -0
  7. data/ext/gitignore_binding/target/debug/build/advapi32-sys-cfef7a1f30f1e5f6/build_script_build.dSYM/Contents/Resources/DWARF/build_script_build +0 -0
  8. data/ext/gitignore_binding/target/debug/build/advapi32-sys-cfef7a1f30f1e5f6/output +0 -0
  9. data/ext/gitignore_binding/target/debug/deps/libadvapi32-cfef7a1f30f1e5f6.rlib +0 -0
  10. data/ext/gitignore_binding/target/debug/deps/libbuild-304afb6bdff23d72.rlib +0 -0
  11. data/ext/gitignore_binding/target/debug/deps/libgitignore-c7373b3d965f16d9.rlib +0 -0
  12. data/ext/gitignore_binding/target/debug/deps/libglob-25f28f4f852d8a9f.rlib +0 -0
  13. data/ext/gitignore_binding/target/debug/deps/liblibc-144c435538abd757.rlib +0 -0
  14. data/ext/gitignore_binding/target/debug/deps/librand-bdfcc55d3466feb3.rlib +0 -0
  15. data/ext/gitignore_binding/target/debug/deps/libtempdir-666eac814577b56f.rlib +0 -0
  16. data/ext/gitignore_binding/target/debug/deps/libwinapi-04bd24ca029a2f2c.rlib +0 -0
  17. data/ext/gitignore_binding/target/debug/libgitignore_binding.dylib +0 -0
  18. data/ext/gitignore_binding/target/debug/libgitignore_binding.dylib.dSYM/Contents/Info.plist +20 -0
  19. data/ext/gitignore_binding/target/debug/libgitignore_binding.dylib.dSYM/Contents/Resources/DWARF/libgitignore_binding.dylib +0 -0
  20. data/ext/gitignore_binding/target/release/build/advapi32-sys-cfef7a1f30f1e5f6/build-script-build +0 -0
  21. data/ext/gitignore_binding/target/release/build/advapi32-sys-cfef7a1f30f1e5f6/build_script_build.dSYM/Contents/Resources/DWARF/build_script_build +0 -0
  22. data/ext/gitignore_binding/target/release/deps/libadvapi32-cfef7a1f30f1e5f6.rlib +0 -0
  23. data/ext/gitignore_binding/target/release/deps/libbuild-304afb6bdff23d72.rlib +0 -0
  24. data/ext/gitignore_binding/target/release/deps/libgitignore-c7373b3d965f16d9.rlib +0 -0
  25. data/ext/gitignore_binding/target/release/deps/libglob-25f28f4f852d8a9f.rlib +0 -0
  26. data/ext/gitignore_binding/target/release/deps/liblibc-144c435538abd757.rlib +0 -0
  27. data/ext/gitignore_binding/target/release/deps/librand-bdfcc55d3466feb3.rlib +0 -0
  28. data/ext/gitignore_binding/target/release/deps/libtempdir-666eac814577b56f.rlib +0 -0
  29. data/ext/gitignore_binding/target/release/deps/libwinapi-04bd24ca029a2f2c.rlib +0 -0
  30. data/ext/gitignore_binding/target/release/libgitignore_binding.dylib +0 -0
  31. data/lib/gitignore_rb.rb +10 -1
  32. data/lib/gitignore_rb/rust.rb +5 -2
  33. metadata +21 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8396d599d3e691008f1143d27f12cf2346e3e176
4
- data.tar.gz: 39290eba069beb20a7fd5e6ea9c72d0b42b3a839
3
+ metadata.gz: ced7dcd87b4e70f51c598a77fda9f4443014e884
4
+ data.tar.gz: cd04335666b8b030c59618be05268ebf0cb372cf
5
5
  SHA512:
6
- metadata.gz: 8ee7bd401e7bce01edd422d4aeb66963f426da37a7c87739fa73cb55d736972d39b3561b6a7e6f4b000b41edf12d9963952d5c54b2b063dff559f86563781082
7
- data.tar.gz: 629c661de017d7f06b7eff07adc9efe19f2efd5c5755d37489b2031f1ecdba632d65de5cd6d7a7131fca07bae1f66f9c3f4290ec76b55defd1efb638423a9ea2
6
+ metadata.gz: 3028d368ecfb36abd3fa82f963714e940073c37d9de35fa20917bc748073c1b5940e352cb9464d879155504d258eb3771d139edc5586d92366567680bbaf0dc5
7
+ data.tar.gz: 6283768e29b85d933a5828405e5adfcb9c2316231df7a41f3c4b8363eea40950b048af7b576d372087459400d9a790e02e6f695ffc3a49e1c401c9e34faa02a7
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # gitignore.rb [![Build Status](https://travis-ci.org/nathankleyn/gitignore.rb.svg)](https://travis-ci.org/nathankleyn/gitignore.rb)
1
+ # gitignore.rb [![Build Status](https://travis-ci.org/nathankleyn/gitignore.rb.svg)](https://travis-ci.org/nathankleyn/gitignore.rb) [![RubyGems Version Of gitignore_rb](https://img.shields.io/gem/v/gitignore_rb.svg)](https://rubygems.org/gems/gitignore_rb)
2
2
 
3
3
  This is an implementation of `.gitignore` parsing and matching in Rust. Use this library if you want to check whether a given path would be excluded by a `.gitignore` file.
4
4
 
@@ -1 +1,29 @@
1
- # FIXME: Make this check for presence of `rustc` and compile the library.
1
+ LIB_PATH = 'target/release/libgitignore_binding.dylib'
2
+
3
+ desc 'Ensure rustc is present and is callable on the current PATH.'
4
+ task :check_rustc do
5
+ puts 'Checking for rustc...'
6
+ unless system 'rustc --version'
7
+ fail 'Could not find rustc on your path, please check you have it installed.'
8
+ end
9
+ end
10
+
11
+ desc 'Ensure cargo is present and is callable on the current PATH.'
12
+ task :check_cargo do
13
+ puts 'Checking for cargo...'
14
+ unless system 'cargo --version'
15
+ fail 'Could not find cargo on your path, please check you have it installed.'
16
+ end
17
+ end
18
+
19
+ desc 'Execute cargo build to construct the dynamic library.'
20
+ task :build do
21
+ unless system 'cargo build --release'
22
+ fail 'Could not execute cargo build successfully, please check the logs and try again.'
23
+ end
24
+ end
25
+
26
+ file LIB_PATH => :build
27
+
28
+ desc 'Build the dynamic library.'
29
+ task default: LIB_PATH
@@ -1,13 +1,11 @@
1
- #![feature(cstr_to_str)]
2
- #![feature(cstr_memory)]
3
-
4
1
  extern crate gitignore;
5
2
  extern crate libc;
6
3
 
7
4
  use std::ffi::CStr;
8
5
  use std::ffi::CString;
9
6
  use std::mem;
10
- use std::path::Path;
7
+ use std::path::{Path, PathBuf};
8
+ use std::string::FromUtf8Error;
11
9
 
12
10
  #[repr(C)]
13
11
  pub struct RubyArray {
@@ -28,14 +26,28 @@ impl RubyArray {
28
26
 
29
27
  #[no_mangle]
30
28
  pub extern "C" fn included_files(path_ptr: *const libc::c_char) -> RubyArray {
31
- let path_cstr = unsafe { CStr::from_ptr(path_ptr) };
32
- let path_and_str = path_cstr.to_str().unwrap();
33
- let path = Path::new(path_and_str).to_path_buf();
29
+ let path_string = ptr_to_string(path_ptr).unwrap();
30
+ let path = Path::new(&*path_string).to_path_buf();
34
31
 
35
32
  let gitignore_path = path.join(".gitignore");
36
33
  let file = gitignore::File::new(&gitignore_path).unwrap();
37
34
 
38
- RubyArray::from_vec(file.included_files().unwrap().iter().map(|f|
39
- CString::new(f.to_str().unwrap()).unwrap().into_raw()
40
- ).collect())
35
+ let files = file.included_files().unwrap();
36
+ println!("{:?}", files);
37
+ RubyArray::from_vec(paths_to_ptrs(files))
38
+ }
39
+
40
+ fn ptr_to_string(ptr: *const libc::c_char) -> Result<String, FromUtf8Error> {
41
+ let cstr = unsafe { CStr::from_ptr(ptr) };
42
+ let mut bytes = Vec::new();
43
+ bytes.extend(cstr.to_bytes());
44
+
45
+ String::from_utf8(bytes)
46
+ }
47
+
48
+ fn paths_to_ptrs(paths: Vec<PathBuf>) -> Vec<*const libc::c_char> {
49
+ paths.iter().flat_map(|p| p.to_str())
50
+ .flat_map(|s| CString::new(s))
51
+ .map(|cs| cs.as_ptr())
52
+ .collect()
41
53
  }
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>English</string>
7
+ <key>CFBundleIdentifier</key>
8
+ <string>com.apple.xcode.dsym.build_script_build</string>
9
+ <key>CFBundleInfoDictionaryVersion</key>
10
+ <string>6.0</string>
11
+ <key>CFBundlePackageType</key>
12
+ <string>dSYM</string>
13
+ <key>CFBundleSignature</key>
14
+ <string>????</string>
15
+ <key>CFBundleShortVersionString</key>
16
+ <string>1.0</string>
17
+ <key>CFBundleVersion</key>
18
+ <string>1</string>
19
+ </dict>
20
+ </plist>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>English</string>
7
+ <key>CFBundleIdentifier</key>
8
+ <string>com.apple.xcode.dsym.libgitignore_binding.dylib</string>
9
+ <key>CFBundleInfoDictionaryVersion</key>
10
+ <string>6.0</string>
11
+ <key>CFBundlePackageType</key>
12
+ <string>dSYM</string>
13
+ <key>CFBundleSignature</key>
14
+ <string>????</string>
15
+ <key>CFBundleShortVersionString</key>
16
+ <string>1.0</string>
17
+ <key>CFBundleVersion</key>
18
+ <string>1</string>
19
+ </dict>
20
+ </plist>
data/lib/gitignore_rb.rb CHANGED
@@ -1,11 +1,20 @@
1
1
  require 'gitignore_rb/rust'
2
+ require 'gitignore_rb/string_array'
2
3
 
4
+ # Represents a `.gitignore` file and the operations one can perform on or with
5
+ # them.
6
+ #
7
+ # This class will take the `.gitignore` file given, parse the rules contained
8
+ # within it, and provides a set of functions to apply these rules in various
9
+ # useful ways.
3
10
  class GitIgnoreRb
4
11
  def initialize(path)
5
12
  @path = path
6
13
  end
7
14
 
8
15
  def included_files
9
- GitIgnoreRust::included_files(@path).to_a
16
+ GitIgnoreRust.included_files(@path).to_a
10
17
  end
11
18
  end
19
+
20
+ GitIgnoreRb.new('/Users/nathan/repos/ihq/platform').included_files
@@ -1,11 +1,14 @@
1
1
  require 'ffi'
2
2
 
3
+ # Wraps up the FFI bindings to the Rust lib. This exposes the functions we have
4
+ # in the Rust library itself and any requisite structs we use.
3
5
  module GitIgnoreRust
4
6
  extend FFI::Library
5
7
 
6
8
  ffi_lib File.expand_path(File.join(__dir__, '../../ext/gitignore_binding/target/release/libgitignore_binding.dylib'))
7
9
 
8
- class GitIgnoreBindingArray < FFI::Struct
10
+ # Struct used to describe a Ruby Array of Strings being passed from Rust.
11
+ class StringArray < FFI::Struct
9
12
  layout :len, :size_t, # dynamic array layout
10
13
  :data, :pointer
11
14
 
@@ -14,5 +17,5 @@ module GitIgnoreRust
14
17
  end
15
18
  end
16
19
 
17
- attach_function :included_files, [:string], GitIgnoreBindingArray.by_value
20
+ attach_function :included_files, [:string], StringArray.by_value
18
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitignore_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Kleyn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-13 00:00:00.000000000 Z
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -108,7 +108,8 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 1.3.1
111
- description: See https://github.com/nathankleyn/gitignore.rb for more information!
111
+ description: A Ruby binding around gitignore.rs, a Rust implementation of .gitignore
112
+ file parsing and glob testing.
112
113
  email: nathan@nathankleyn.com
113
114
  executables: []
114
115
  extensions:
@@ -120,6 +121,21 @@ files:
120
121
  - ext/gitignore_binding/Cargo.toml
121
122
  - ext/gitignore_binding/Rakefile
122
123
  - ext/gitignore_binding/src/lib.rs
124
+ - ext/gitignore_binding/target/debug/build/advapi32-sys-cfef7a1f30f1e5f6/build-script-build
125
+ - ext/gitignore_binding/target/debug/build/advapi32-sys-cfef7a1f30f1e5f6/build_script_build.dSYM/Contents/Info.plist
126
+ - ext/gitignore_binding/target/debug/build/advapi32-sys-cfef7a1f30f1e5f6/build_script_build.dSYM/Contents/Resources/DWARF/build_script_build
127
+ - ext/gitignore_binding/target/debug/build/advapi32-sys-cfef7a1f30f1e5f6/output
128
+ - ext/gitignore_binding/target/debug/deps/libadvapi32-cfef7a1f30f1e5f6.rlib
129
+ - ext/gitignore_binding/target/debug/deps/libbuild-304afb6bdff23d72.rlib
130
+ - ext/gitignore_binding/target/debug/deps/libgitignore-c7373b3d965f16d9.rlib
131
+ - ext/gitignore_binding/target/debug/deps/libglob-25f28f4f852d8a9f.rlib
132
+ - ext/gitignore_binding/target/debug/deps/liblibc-144c435538abd757.rlib
133
+ - ext/gitignore_binding/target/debug/deps/librand-bdfcc55d3466feb3.rlib
134
+ - ext/gitignore_binding/target/debug/deps/libtempdir-666eac814577b56f.rlib
135
+ - ext/gitignore_binding/target/debug/deps/libwinapi-04bd24ca029a2f2c.rlib
136
+ - ext/gitignore_binding/target/debug/libgitignore_binding.dylib
137
+ - ext/gitignore_binding/target/debug/libgitignore_binding.dylib.dSYM/Contents/Info.plist
138
+ - ext/gitignore_binding/target/debug/libgitignore_binding.dylib.dSYM/Contents/Resources/DWARF/libgitignore_binding.dylib
123
139
  - ext/gitignore_binding/target/release/build/advapi32-sys-cfef7a1f30f1e5f6/build-script-build
124
140
  - ext/gitignore_binding/target/release/build/advapi32-sys-cfef7a1f30f1e5f6/build_script_build.dSYM/Contents/Info.plist
125
141
  - ext/gitignore_binding/target/release/build/advapi32-sys-cfef7a1f30f1e5f6/build_script_build.dSYM/Contents/Resources/DWARF/build_script_build
@@ -158,6 +174,6 @@ rubyforge_project:
158
174
  rubygems_version: 2.4.5.1
159
175
  signing_key:
160
176
  specification_version: 4
161
- summary: Implementation of .gitignore file parsing and glob testing. This library
162
- is a Ruby binding around gitignore.rs.
177
+ summary: A Ruby binding around gitignore.rs, a Rust implementation of .gitignore file
178
+ parsing and glob testing.
163
179
  test_files: []