flubber 0.0.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 +7 -0
- data/lib/flubber.rb +79 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 91ad4381dc64ed02369e983a90fb054f09f4fc9d
|
4
|
+
data.tar.gz: 1977f550a64f3f7b46de3e0b74c2590d368a2166
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 517610654acb3709c1c11b5795fffccb3b3dc97fd8a230b59406360aebb19dd763b81c812e0c8b0394064b1c3d5fe6eef7ee073077ca39721205ecfa7cb68467
|
7
|
+
data.tar.gz: 6427d3ba7ea6138ae682d0d9a5adff95f45c7b89e5979d9b13ed640e662b9a3067a32127d6a12d6b63dcd903cf76a43c3c755428178e6197c4cdfab647b9f010
|
data/lib/flubber.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Flubber is just some simple, stupid bindings to use Elasticsearch as a plain old CRUD database.
|
2
|
+
# Create will make an id if you do not provide one; Read, Update, and Delete all require an id.
|
3
|
+
# We also support a default index/type to make it really brain-dead to use. Huzzah!
|
4
|
+
# It sits on top of the vendor-provided elasticsearch gem - you can, and should, use the client
|
5
|
+
# this provides via client() to talk directly to elasticsearch if you need to be more savvy.
|
6
|
+
|
7
|
+
# Why Flubber?
|
8
|
+
# - All the good names were taken?
|
9
|
+
# - Flubber is kind of a CRUDdy Elastic?
|
10
|
+
# - The original was pretty awesome. Jerry Lewis 4tW.
|
11
|
+
|
12
|
+
class Flubber
|
13
|
+
|
14
|
+
def initialize(a)
|
15
|
+
@attr = { url: ENV['ELASTICSEARCH_URL'], index: 'test', type: 'test' }
|
16
|
+
if !a.nil? then
|
17
|
+
self.default(a) if a.class == Hash
|
18
|
+
@attr[:url] = a if a.class == String
|
19
|
+
end
|
20
|
+
@client = Elasticsearch::Client.new url: @attr[:url]
|
21
|
+
end
|
22
|
+
|
23
|
+
def client
|
24
|
+
return @client
|
25
|
+
end
|
26
|
+
|
27
|
+
# Copy key value from one hash to another, forcing key to sym, only if it exists
|
28
|
+
def setval(dest, source, name)
|
29
|
+
return unless source.class == Hash
|
30
|
+
return if source[name].nil? and source[name.to_sym].nil?
|
31
|
+
dest[name.to_sym] = source[name].to_s unless source[name].nil?
|
32
|
+
dest[name.to_sym] = source[name.to_sym].to_s unless source[name.to_sym].nil?
|
33
|
+
dest[name.to_sym] = source[name.to_s].to_s unless source[name.to_s].nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
# Replace defaults
|
37
|
+
def default(a)
|
38
|
+
a.keys.each { |k| self.setval(@attr, a, k) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def info
|
42
|
+
@client.info
|
43
|
+
end
|
44
|
+
|
45
|
+
def setup(a)
|
46
|
+
q = { index: @attr[:index], type: @attr[:type] }
|
47
|
+
if a.class == Hash then
|
48
|
+
[:index, :type, :id].each { |k| self.setval(q, a, k) }
|
49
|
+
else
|
50
|
+
q[:id] = a.to_s
|
51
|
+
end
|
52
|
+
return q
|
53
|
+
end
|
54
|
+
|
55
|
+
def create(a, j)
|
56
|
+
q = setup(a)
|
57
|
+
j = j.to_s if j.respond_to?(:to_s)
|
58
|
+
q[:body] = j
|
59
|
+
@client.index q
|
60
|
+
end
|
61
|
+
|
62
|
+
def read(a)
|
63
|
+
@client.get setup(a)
|
64
|
+
end
|
65
|
+
|
66
|
+
def update(a, j) # maybe add modify() that only changes some fields? hmmm.
|
67
|
+
q = setup(a)
|
68
|
+
q[:body] = j
|
69
|
+
@client.index q
|
70
|
+
end
|
71
|
+
|
72
|
+
def delete(a)
|
73
|
+
@client.delete setup(a)
|
74
|
+
end
|
75
|
+
|
76
|
+
def search(a)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flubber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom Bortels
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Flubber is a simple CRUD interface for elasticsearch.
|
14
|
+
email: bortels@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/flubber.rb
|
20
|
+
homepage: http://rubygems.org/gems/flubber
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements:
|
39
|
+
- elasticsearch
|
40
|
+
- json
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.2.2
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: CRUD for elasticsearch
|
46
|
+
test_files: []
|
47
|
+
has_rdoc:
|