pure_mmdb 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.travis.yml +14 -0
- data/Gemfile.lock +2 -2
- data/README.md +39 -9
- data/lib/mmdb/configuration.rb +7 -1
- data/lib/mmdb/version.rb +1 -1
- data/lib/mmdb.rb +15 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d0010e9343a3b56eb03d19206b390f02ec7b3e42
|
4
|
+
data.tar.gz: cab205542fbf0509a112424350449242f5161c12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b86efda039d51dec77abda477a507b54f5ff1e57b381fadd4c3ab12aed9b6d032e4108b62a9635e1a04ae1de8af14eeb7aa63cace07dad90cfaa92122d679b70
|
7
|
+
data.tar.gz: fe9c616737556a8afe3b734c7fae57b55bedbdf04cac6f7cfc879da4eb0948bafe2ed61b6b66a6bdfabd11c88b45114f9d0ddc367bea478ae8df53ac147b3497
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,5 +1,19 @@
|
|
1
|
+
env:
|
2
|
+
global:
|
3
|
+
- CC_TEST_REPORTER_ID=d216d9599c37e222d9ef67dca792a7046dc352a887c8ef4ad8b2ab547bed92fe
|
1
4
|
sudo: false
|
2
5
|
language: ruby
|
3
6
|
rvm:
|
7
|
+
- 2.3.0
|
8
|
+
- 2.4.0
|
4
9
|
- 2.5.0
|
5
10
|
before_install: gem install bundler -v 1.16.1
|
11
|
+
before_script:
|
12
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
13
|
+
- chmod +x ./cc-test-reporter
|
14
|
+
- ./cc-test-reporter before-build
|
15
|
+
script:
|
16
|
+
- bundle exec rake
|
17
|
+
after_script:
|
18
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
19
|
+
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
4
|
+
pure_mmdb (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -36,8 +36,8 @@ PLATFORMS
|
|
36
36
|
|
37
37
|
DEPENDENCIES
|
38
38
|
bundler (~> 1.16)
|
39
|
-
mmdb!
|
40
39
|
pry-byebug (~> 3.0)
|
40
|
+
pure_mmdb!
|
41
41
|
rake (~> 10.0)
|
42
42
|
rspec (~> 3.0)
|
43
43
|
|
data/README.md
CHANGED
@@ -1,15 +1,19 @@
|
|
1
|
-
#
|
1
|
+
# MaxMindDB
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/pure_mmdb.svg)](https://badge.fury.io/rb/pure_mmdb)
|
4
|
+
[![Build Status](https://travis-ci.org/trevorrjohn/mmdb.svg?branch=master)](https://travis-ci.org/trevorrjohn/mmdb)
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/7eb3d3e1389a8c16a2da/maintainability)](https://codeclimate.com/github/trevorrjohn/mmdb/maintainability)
|
4
6
|
|
5
|
-
|
7
|
+
The purpose of this gem is to implement the [MaxMindDB File Format](http://maxmind.github.io/MaxMind-DB/) in Ruby.
|
8
|
+
|
9
|
+
The gem is highly influenced by the implementation of the [MaxMindDB gem](https://github.com/yhirose/maxminddb) and I have to give a lot of credit to that project.
|
6
10
|
|
7
11
|
## Installation
|
8
12
|
|
9
13
|
Add this line to your application's Gemfile:
|
10
14
|
|
11
15
|
```ruby
|
12
|
-
gem '
|
16
|
+
gem 'pure_mmdb'
|
13
17
|
```
|
14
18
|
|
15
19
|
And then execute:
|
@@ -18,11 +22,38 @@ And then execute:
|
|
18
22
|
|
19
23
|
Or install it yourself as:
|
20
24
|
|
21
|
-
$ gem install
|
25
|
+
$ gem install pure_mmdb
|
22
26
|
|
23
27
|
## Usage
|
24
28
|
|
25
|
-
|
29
|
+
### Configuration
|
30
|
+
|
31
|
+
To configure the gem, simply set the `file_path` in the configure block.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
Mmdb.configure do |c|
|
35
|
+
c.file_path = '/path/to/db.mmdb'
|
36
|
+
end
|
37
|
+
Mmdb.query('192.168.1.1')
|
38
|
+
#=> { 'data' => 'hash' }
|
39
|
+
```
|
40
|
+
|
41
|
+
### Multiple Database Files
|
42
|
+
|
43
|
+
If you need to have multiple database files you can query each file individually after specifying the files. You can configure as many database files as you like. The database will only be loaded into memory once it is queried.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
Mmdb.configure do |c|
|
47
|
+
c.files = {
|
48
|
+
vpn: 'path to vpn.mmdb',
|
49
|
+
location: 'path to location.mmdb'
|
50
|
+
}
|
51
|
+
end
|
52
|
+
Mmdb.lookup('192.168.1.1', file_key: :vpn)
|
53
|
+
#=> { 'data' => 'vpn data' }
|
54
|
+
Mmdb.lookup('192.168.1.1', file_key: :location)
|
55
|
+
#=> { 'data' => 'location data' }
|
56
|
+
```
|
26
57
|
|
27
58
|
## Development
|
28
59
|
|
@@ -32,12 +63,11 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
63
|
|
33
64
|
## Contributing
|
34
65
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
36
|
-
|
66
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/trevorrjohn/mmdb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
37
67
|
## License
|
38
68
|
|
39
69
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
70
|
|
41
71
|
## Code of Conduct
|
42
72
|
|
43
|
-
Everyone interacting in the Mmdb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
73
|
+
Everyone interacting in the Mmdb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/trevorrjohn/mmdb/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/mmdb/configuration.rb
CHANGED
data/lib/mmdb/version.rb
CHANGED
data/lib/mmdb.rb
CHANGED
@@ -17,19 +17,28 @@ module Mmdb
|
|
17
17
|
|
18
18
|
def reset
|
19
19
|
@config = Configuration.new
|
20
|
-
@
|
20
|
+
@databases = nil
|
21
21
|
end
|
22
22
|
|
23
|
-
def query(ip)
|
24
|
-
Query.new(db:
|
23
|
+
def query(ip, file_key: Configuration::DEFAULT_FILE_KEY)
|
24
|
+
Query.new(db: db_for_key(file_key), ip: ip).fetch
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
-
attr_reader :
|
29
|
+
attr_reader :databases
|
30
30
|
|
31
|
-
def
|
32
|
-
|
31
|
+
def db_for_key(file_key)
|
32
|
+
databases[file_key].tap do |db|
|
33
|
+
raise DatabaseNotFound if db.nil?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def databases
|
38
|
+
@databases ||=
|
39
|
+
config.files.map do |key, file_path|
|
40
|
+
[key, DB.new(file_path)]
|
41
|
+
end.to_h
|
33
42
|
end
|
34
43
|
end
|
35
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pure_mmdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trevor John
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
115
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.
|
116
|
+
rubygems_version: 2.6.13
|
117
117
|
signing_key:
|
118
118
|
specification_version: 4
|
119
119
|
summary: This is a ruby implementation of the MaxMindDB file format
|