Class: Flubber
- Inherits:
-
Object
- Object
- Flubber
- Defined in:
- lib/flubber.rb
Overview
Why Flubber?
-
All the good names were taken?
-
Flubber is kind of a CRUDdy Elastic?
-
The original was pretty awesome. Jerry Lewis 4tW.
Instance Method Summary collapse
- #client ⇒ Object
- #create(a, j) ⇒ Object
-
#default(a) ⇒ Object
Replace defaults.
- #delete(a) ⇒ Object
- #info ⇒ Object
-
#initialize(a) ⇒ Flubber
constructor
A new instance of Flubber.
- #read(a) ⇒ Object
- #search(a) ⇒ Object
- #setup(a) ⇒ Object
-
#setval(dest, source, name) ⇒ Object
Copy key value from one hash to another, forcing key to sym, only if it exists.
-
#update(a, j) ⇒ Object
maybe add modify() that only changes some fields? hmmm.
Constructor Details
#initialize(a) ⇒ Flubber
Returns a new instance of Flubber.
14 15 16 17 18 19 20 21 |
# File 'lib/flubber.rb', line 14 def initialize(a) @attr = { url: ENV['ELASTICSEARCH_URL'], index: 'test', type: 'test' } if !a.nil? then self.default(a) if a.class == Hash @attr[:url] = a if a.class == String end @client = Elasticsearch::Client.new url: @attr[:url] end |
Instance Method Details
#client ⇒ Object
23 24 25 |
# File 'lib/flubber.rb', line 23 def client return @client end |
#create(a, j) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/flubber.rb', line 55 def create(a, j) q = setup(a) j = j.to_s if j.respond_to?(:to_s) q[:body] = j @client.index q end |
#default(a) ⇒ Object
Replace defaults
37 38 39 |
# File 'lib/flubber.rb', line 37 def default(a) a.keys.each { |k| self.setval(@attr, a, k) } end |
#delete(a) ⇒ Object
72 73 74 |
# File 'lib/flubber.rb', line 72 def delete(a) @client.delete setup(a) end |
#info ⇒ Object
41 42 43 |
# File 'lib/flubber.rb', line 41 def info @client.info end |
#read(a) ⇒ Object
62 63 64 |
# File 'lib/flubber.rb', line 62 def read(a) @client.get setup(a) end |
#search(a) ⇒ Object
76 77 |
# File 'lib/flubber.rb', line 76 def search(a) end |
#setup(a) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/flubber.rb', line 45 def setup(a) q = { index: @attr[:index], type: @attr[:type] } if a.class == Hash then [:index, :type, :id].each { |k| self.setval(q, a, k) } else q[:id] = a.to_s end return q end |
#setval(dest, source, name) ⇒ Object
Copy key value from one hash to another, forcing key to sym, only if it exists
28 29 30 31 32 33 34 |
# File 'lib/flubber.rb', line 28 def setval(dest, source, name) return unless source.class == Hash return if source[name].nil? and source[name.to_sym].nil? dest[name.to_sym] = source[name].to_s unless source[name].nil? dest[name.to_sym] = source[name.to_sym].to_s unless source[name.to_sym].nil? dest[name.to_sym] = source[name.to_s].to_s unless source[name.to_s].nil? end |
#update(a, j) ⇒ Object
maybe add modify() that only changes some fields? hmmm.
66 67 68 69 70 |
# File 'lib/flubber.rb', line 66 def update(a, j) # maybe add modify() that only changes some fields? hmmm. q = setup(a) q[:body] = j @client.index q end |