fiddler-rb 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ad1560071c9282bd9dd9b02fc4035b771417c827
4
+ data.tar.gz: 6ba239d0d6c4dfcc8ce41787c081ee07b29ead00
5
+ SHA512:
6
+ metadata.gz: b8be159ba937d61065c900a729292662ab1d32a98a6c687eecd69db851264e55ad76aa8ab56ff2c352d4d611f1ee224169a5fc20ca47fa33ed57b4908e6e4b68
7
+ data.tar.gz: 103536bd9dc9af4e832d1af044aec552b1f439accb9acc7bfd3245489ff86f5f06811d55d1df4bfe723d49e0b6f7b0aa5e8cf4cbe7f3c3174611cccbf262add8
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fiddler.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Davide D'Agostino
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,66 @@
1
+ # Fiddler
2
+
3
+ Fiddler is a super tiny (80 LOC) for [fiddle](http://www.ruby-doc.org/stdlib-2.0/libdoc/fiddle/rdoc/Fiddle.html)
4
+ of **RUBY 2.+**.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'fiddler-rb', require: 'fiddler'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install fiddler-rb
19
+
20
+ ## Usage
21
+
22
+ You can wrap your library like:
23
+
24
+ ```rb
25
+ require 'fiddler'
26
+
27
+ module LevelDB
28
+ module C
29
+ include Fiddler
30
+
31
+ prefix 'leveldb_'
32
+ dlload 'libleveldb'
33
+
34
+ cdef :open, VOIDP, options: VOIDP, name: VOIDP, errptr: VOIDP
35
+ cdef :put, VOID, db: VOIDP, options: VOIDP, key: VOIDP, keylen: ULONG, val: VOIDP, vallen: ULONG, errptr: VOIDP
36
+ cdef :get, VOIDP, db: VOIDP, options: VOIDP, key: VOIDP, keylen: ULONG, vallen: VOIDP, errptr: VOIDP
37
+ cdef :delete, VOID, db: VOIDP, options: VOIDP, key: VOIDP, keylen: ULONG, errptr: VOIDP
38
+ end
39
+ end
40
+ ```
41
+
42
+ And then use the wrapper:
43
+
44
+ ```
45
+ errors = C::Pointer.malloc(C::SIZEOF_VOIDP)
46
+ options = C.struct ['char c', 'long n']
47
+
48
+ db = C.open options, './path', errors
49
+ db.free = C[:release_db]
50
+
51
+ C.put db, 'a', 1 ...
52
+ C.get db, 'a', ...
53
+ C.delete db, 'a', ...
54
+ ```
55
+
56
+ ## Examples
57
+
58
+ * [leveldb](https://github.com/DAddYE/leveldb/blob/master/lib/leveldb/db.rb)
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it
63
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
64
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
65
+ 4. Push to the branch (`git push origin my-new-feature`)
66
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fiddler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fiddler-rb"
8
+ spec.version = Fiddler::VERSION
9
+ spec.authors = ["Davide D'Agostino"]
10
+ spec.email = ["info@daddye.it"]
11
+ spec.description = %q{A nano helper for ruby fiddle}
12
+ spec.summary = spec.description
13
+ spec.homepage = "http://github.com/DAddYE/fiddler"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,77 @@
1
+ require 'fiddle'
2
+ require 'fiddle/import'
3
+ require 'rbconfig'
4
+
5
+ module Fiddler
6
+ include Fiddle
7
+ include Fiddle::CParser
8
+ include Fiddle::Importer
9
+ extend Fiddle::Importer
10
+ extend self
11
+
12
+ LIBSUFFIX =
13
+ case RbConfig::CONFIG['host_os'].downcase
14
+ when /windows|cgywin/ then 'dll'
15
+ when /darwin/ then 'dylib'
16
+ else 'so'
17
+ end
18
+
19
+ LIBPATHS =
20
+ [ '/usr/local/lib',
21
+ '/opt/local/lib',
22
+ '/usr/lib64',
23
+ File.expand_path("../../ext/leveldb", __FILE__)]
24
+
25
+ def dlload(*libs)
26
+ libs.map! do |lib|
27
+ LIBPATHS.map { |l| File.join(l, "#{lib}.#{LIBSUFFIX}") }.
28
+ detect { |l| File.exist?(l) }
29
+ end
30
+ super(*libs)
31
+ end
32
+
33
+ # Alias CTypes
34
+ ::Fiddle.constants.each do |c|
35
+ next unless c.to_s =~ /^TYPE_(.+)$/
36
+ const_set $1, const_get(c)
37
+ end
38
+
39
+ ULONG = -LONG
40
+ LLONG = LONG_LONG
41
+ ULLONG = -LONG_LONG
42
+ UCHAR = -CHAR
43
+ USHORT = -SHORT
44
+ UINT = -INT
45
+
46
+ def cdef(name, ret_type, args_types={}, options={})
47
+ address = handler["#{@_prefix}#{name}"] || handler[name.to_s]
48
+ options = {name: name}.merge(options)
49
+ call_type = options.delete(:call_type) || Function::DEFAULT
50
+ params = args_types.keys.join(', ')
51
+ values = args_types.values
52
+ cdefs[name] = Function.new(address, values, ret_type, call_type, options)
53
+
54
+ module_eval <<-RB, __FILE__, __LINE__ + 1
55
+ def #{name}(#{params})
56
+ cdefs[#{name.inspect}].call(#{params})
57
+ end
58
+ module_function #{name.inspect}
59
+ RB
60
+ end
61
+
62
+ def cdefs
63
+ @_cdefs ||= {}
64
+ end
65
+
66
+ def [](val)
67
+ cdefs[val]
68
+ end
69
+
70
+ def prefix(value)
71
+ @_prefix = value
72
+ end
73
+
74
+ def self.included(base)
75
+ base.extend self
76
+ end
77
+ end
@@ -0,0 +1,3 @@
1
+ module Fiddler
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fiddler-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Davide D'Agostino
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A nano helper for ruby fiddle
42
+ email:
43
+ - info@daddye.it
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - fiddler.gemspec
54
+ - lib/fiddler.rb
55
+ - lib/fiddler/version.rb
56
+ homepage: http://github.com/DAddYE/fiddler
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.0.3
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: A nano helper for ruby fiddle
80
+ test_files: []
81
+ has_rdoc: