rethinkdb_helper 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 01cd1baa0c8ff2bc88067c0ab507364320d6eef2
4
+ data.tar.gz: 2c16cb84eb4de3331525b90c24afa511ad78104e
5
+ SHA512:
6
+ metadata.gz: 938adb9955c1787b7183d5984dcf0e9b7ce2d046b19f28cd40184443c4567dce929634d236f49b2e207f421dd5c108f840239ced866712bd1748375b7e79b564
7
+ data.tar.gz: 9269ac2b91b32c96e794a58446afe2cdd319eb6f3629cdbf846c71ba87bc8e38f519c6e904d48532d8bf9e5c4c979a0d105700a21d392017612c6f659dbecc64
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rethinkdb_helper.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # RethinkdbHelper
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rethinkdb_helper`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rethinkdb_helper'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rethinkdb_helper
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/rethinkdb_helper/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,108 @@
1
+ ##########################################################
2
+ ###
3
+ ## File: rethinkdb_helper.rb
4
+ ## Desc: Encapsulates some basic utility functions
5
+ ## By: Dewayne VanHoozer (dvanhoozer@gmail.com)
6
+ #
7
+ require 'rethinkdb'
8
+
9
+ class RethinkdbHelper
10
+ include RethinkDB::Shortcuts
11
+
12
+ DEFAULTS = {
13
+ host: ENV['RETHINKDB_HOST'] || 'localhost',
14
+ port: (ENV['RETHINKDB_PORT'] || '28015').to_i,
15
+ db: ENV['RETHINKDB_DB'] || 'test',
16
+ table: ENV['RETHINKDB_TABLE'] || 'test',
17
+ drop: false,
18
+ create_if_missing: false
19
+ }
20
+
21
+ # TODO: Limited to one table per instance, consider
22
+ # support for multiple table per db support;
23
+ # consider multiple db per instance support.
24
+ def initialize(options={})
25
+ @options = DEFAULTS.merge(options)
26
+
27
+ @connection = r.connect(
28
+ host: @options[:host],
29
+ port: @options[:port]
30
+ ).repl
31
+
32
+ r.db_drop(@options[:db]) if db_exist? && drop?
33
+
34
+ unless db_exist?
35
+ if create_if_missing?
36
+ r.db_create(@options[:db]).run
37
+ else
38
+ raise "db: '#{@options[:db]}' does not exist"
39
+ end
40
+ end
41
+
42
+ @connection.use(@options[:db])
43
+
44
+ unless table_exist?
45
+ if create_if_missing?
46
+ r.table_create(@options[:table]).run
47
+ else
48
+ raise "table: '#{@options[:table]}' does not exist"
49
+ end
50
+ end
51
+
52
+ @table = r.table(@options[:table])
53
+ end # def initialize
54
+
55
+ def db_exist?
56
+ r.db_list.run.include?(@options[:db])
57
+ end
58
+
59
+ def table_exist?
60
+ r.table_list.run.include?($options[:table])
61
+ end
62
+
63
+ def drop?
64
+ @options[:drop]
65
+ end
66
+
67
+ def create_if_missing?
68
+ @options[:create_if_missing]
69
+ end
70
+
71
+ # payloads is an array of hashes or a single
72
+ # hash document.
73
+ def insert(*payloads)
74
+ raise 'No document provided' if payloads.empty?
75
+ invalid_payloads = false
76
+ payloads.map{|doc| invalid_payloads &&= !doc.is_a?(Hash)}
77
+ raise 'Invalid document: must be Hash' if invalid_payloads
78
+ @table.insert(payloads).run
79
+ end
80
+ alias :add :insert
81
+ alias :load :insert
82
+
83
+ # TODO: Currently limited to one search field and regex
84
+ # consider how to use more than one field
85
+ #
86
+ # returns an enumerable cursor into the database for
87
+ # documents that match the search terms.
88
+ #
89
+ # params is a hash where the key is the symbolized field_name
90
+ # and its value is the regex by which to filter
91
+ def filter(params={})
92
+ raise 'No search terms' if params.empty?
93
+ field_name = params.keys.first
94
+ search_regex = params[field_name]
95
+
96
+ @table.filter{|document| document[field_name].
97
+ match(search_regex)}.
98
+ run
99
+ end
100
+ alias :search :filter
101
+
102
+ def close
103
+ @connection.close
104
+ end
105
+
106
+ end # class RethinkdbHelper
107
+
108
+ ReDBH = RethinkdbHelper unless defined?(ReDBH)
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rethinkdb_helper"
7
+ spec.version = '0.0.1'
8
+ spec.authors = ["Dewayne VanHoozer"]
9
+ spec.email = ["dvanhoozer@gmail.com"]
10
+
11
+ spec.summary = %q{A wrapper around the ruby rethinkdb gem}
12
+ spec.description = %q{The rethinkDB is an interesting NoSQL massively scalable open
13
+ source project. It may have some impact on the real-time processing
14
+ community. This little gem is just a convention wrapper around the official
15
+ rethinkdb. Its my conventions which are subject to change at a momments
16
+ notice. I would not use this gem if I were you.}
17
+ spec.homepage = "https://github.com/MadBomber/rethinkdb_helper"
18
+ spec.license = "You want it? It's yours."
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ if spec.respond_to?(:metadata)
24
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
25
+ end
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.8"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+
30
+ spec.add_dependency "rethinkdb", "~> 1.16"
31
+
32
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rethinkdb_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dewayne VanHoozer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-19 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.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rethinkdb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ description: |-
56
+ The rethinkDB is an interesting NoSQL massively scalable open
57
+ source project. It may have some impact on the real-time processing
58
+ community. This little gem is just a convention wrapper around the official
59
+ rethinkdb. Its my conventions which are subject to change at a momments
60
+ notice. I would not use this gem if I were you.
61
+ email:
62
+ - dvanhoozer@gmail.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - ".gitignore"
68
+ - ".travis.yml"
69
+ - Gemfile
70
+ - README.md
71
+ - Rakefile
72
+ - lib/rethinkdb_helper.rb
73
+ - rethinkdb_helper.gemspec
74
+ homepage: https://github.com/MadBomber/rethinkdb_helper
75
+ licenses:
76
+ - You want it? It's yours.
77
+ metadata:
78
+ allowed_push_host: https://rubygems.org
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.6
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: A wrapper around the ruby rethinkdb gem
99
+ test_files: []