Skip to content

Commit

Permalink
v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
printercu committed Nov 11, 2014
1 parent f018cce commit 5c192c6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
[![Code Climate](https://codeclimate.com/github/printercu/elastics-rb/badges/gpa.svg)](https://codeclimate.com/github/printercu/elastics-rb)
[![Build Status](https://travis-ci.org/printercu/elastics-rb.svg)](https://travis-ci.org/printercu/elastics-rb)

Simple ElasticSearch client.
- basic API only
- transparent aliases management & zero-downtime migrations
- capistrano integration
- auto refresh in tests
Simple ElasticSearch client. Everything for deployment & maintaince included.
- Basic API only
- Transparent aliases management & zero-downtime migrations
- Capistrano integration
- Auto refresh in tests
- Instrumentation

Fast and thread-safe [httpclient](https://github.com/nahi/httpclient) is under the hood.

## Install

```ruby
# Gemfile
gem 'elastics', '~> 0.2' # use version from the badge above
gem 'elastics', '~> 0.3' # use version from the badge above
# or
gem 'elastics', github: 'printercu/elastics-rb'
```
Expand All @@ -35,8 +36,8 @@ client = Elastics::Client.new(options)
# :resurrect_timeout - timeout to mark dead host as alive in cluster-mode (default 10)

# basic request
client.request(options)
# options is hash with
client.request(params)
# params is hash with
# :method - default :get
# :body - post body
# :query - query string params
Expand Down Expand Up @@ -76,6 +77,7 @@ When using cluster-mode you should also install `gem 'thread_safe'`.
```ruby
class User < ActiveRecord::Base
indexed_with_elastics
# it'll set after_commit callbacks and add helper methods
# optionally pass :index, :type

# optionally override to export only selected fields
Expand All @@ -84,9 +86,14 @@ class User < ActiveRecord::Base
end
end

User.elastics # Elastics::Client instance
User.elastics_params # hash with index & type values for the model
User.request_elastics(params) # performs request merging params with elastics_params
User.search_elastics(data)
# Returns Elastics::ActiveRecord::SearchResult object with some useful methods
```
Check out [HelperMethods](https://github.com/printercu/elastics-rb/blob/master/lib/elastics/active_record/helper_methods.rb)
for more information.

#### Configure
```yml
Expand Down
12 changes: 5 additions & 7 deletions lib/elastics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ class Error < StandardError; end
class NotFound < Error; end

require 'elastics/client'
require 'elastics/version_manager'
require 'elastics/query_helper'

autoload :AutoRefresh, 'elastics/auto_refresh'
autoload :Tasks, 'elastics/tasks'
autoload :Result, 'elastics/result'

extend QueryHelper
autoload :AutoRefresh, 'elastics/auto_refresh'
autoload :Tasks, 'elastics/tasks'
autoload :QueryHelper, 'elastics/query_helper'
autoload :Result, 'elastics/result'
autoload :VersionManager, 'elastics/version_manager'

class << self
attr_reader :models
Expand Down
1 change: 1 addition & 0 deletions lib/elastics/active_record/helper_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def update_elastics_doc(fields)

def delete_elastics
self.class.request_elastics(method: :delete, id: id)
rescue NotFound
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/elastics/active_record/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def install
if Client.respond_to?(:prepend)
Client.prepend self
else
Client.include Fallback
Client.send :include, Fallback
end
unless ::ActiveRecord::LogSubscriber < LogSubscriber
::ActiveRecord::LogSubscriber.send :include, LogSubscriber
Expand Down
2 changes: 1 addition & 1 deletion lib/elastics/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Elastics
VERSION = '0.2.0'
VERSION = '0.3.0'

def self.gem_version
Gem::Version.new VERSION
Expand Down

0 comments on commit 5c192c6

Please sign in to comment.