Skip to content

[STORE] Refactor Repository as mixin #824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions elasticsearch-persistence/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--tty
--colour
5 changes: 5 additions & 0 deletions elasticsearch-persistence/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ gemspec
gem 'elasticsearch-model', :path => File.expand_path("../../elasticsearch-model", __FILE__), :require => false

gem 'virtus'

group :development, :testing do
gem 'rspec'
gem 'pry-nav'
end
16 changes: 8 additions & 8 deletions elasticsearch-persistence/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ task :test => 'test:unit'
# ----- Test tasks ------------------------------------------------------------

require 'rake/testtask'
require 'rspec/core/rake_task'

namespace :test do

RSpec::Core::RakeTask.new(:spec)
Rake::TestTask.new(:unit) do |test|
test.libs << 'lib' << 'test'
test.test_files = FileList["test/unit/**/*_test.rb"]
test.verbose = false
test.warning = false
end

Rake::TestTask.new(:integration) do |test|
test.libs << 'lib' << 'test'
test.test_files = FileList["test/integration/**/*_test.rb"]
test.verbose = false
test.warning = false
test.deps = [ :spec ]
end

Rake::TestTask.new(:all) do |test|
test.libs << 'lib' << 'test'
test.test_files = FileList["test/unit/**/*_test.rb", "test/integration/**/*_test.rb"]
test.verbose = false
test.warning = false
test.deps = [ :spec ]
end
end

Expand Down
112 changes: 2 additions & 110 deletions elasticsearch-persistence/lib/elasticsearch/persistence.rb
Original file line number Diff line number Diff line change
@@ -1,116 +1,8 @@
require 'hashie/mash'

require 'elasticsearch'

require 'elasticsearch/model/hash_wrapper'
require 'elasticsearch/model/indexing'
require 'elasticsearch/model/searching'

require 'active_support/inflector'
require 'elasticsearch/model'

require 'elasticsearch/persistence/version'

require 'elasticsearch/persistence/client'
require 'elasticsearch/persistence/repository/response/results'
require 'elasticsearch/persistence/repository/naming'
require 'elasticsearch/persistence/repository/serialize'
require 'elasticsearch/persistence/repository/store'
require 'elasticsearch/persistence/repository/find'
require 'elasticsearch/persistence/repository/search'
require 'elasticsearch/persistence/repository/class'
require 'elasticsearch/persistence/repository'

module Elasticsearch

# Persistence for Ruby domain objects and models in Elasticsearch
# ===============================================================
#
# `Elasticsearch::Persistence` contains modules for storing and retrieving Ruby domain objects and models
# in Elasticsearch.
#
# == Repository
#
# The repository patterns allows to store and retrieve Ruby objects in Elasticsearch.
#
# require 'elasticsearch/persistence'
#
# class Note
# def to_hash; {foo: 'bar'}; end
# end
#
# repository = Elasticsearch::Persistence::Repository.new
#
# repository.save Note.new
# # => {"_index"=>"repository", "_type"=>"note", "_id"=>"mY108X9mSHajxIy2rzH2CA", ...}
#
# Customize your repository by including the main module in a Ruby class
# class MyRepository
# include Elasticsearch::Persistence::Repository
#
# index 'my_notes'
# klass Note
#
# client Elasticsearch::Client.new log: true
# end
#
# repository = MyRepository.new
#
# repository.save Note.new
# # 2014-04-04 22:15:25 +0200: POST http://localhost:9200/my_notes/note [status:201, request:0.009s, query:n/a]
# # 2014-04-04 22:15:25 +0200: > {"foo":"bar"}
# # 2014-04-04 22:15:25 +0200: < {"_index":"my_notes","_type":"note","_id":"-d28yXLFSlusnTxb13WIZQ", ...}
#
# == Model
#
# The active record pattern allows to use the interface familiar from ActiveRecord models:
#
# require 'elasticsearch/persistence'
#
# class Article
# attribute :title, String, mapping: { analyzer: 'snowball' }
# end
#
# article = Article.new id: 1, title: 'Test'
# article.save
#
# Article.find(1)
#
# article.update_attributes title: 'Update'
#
# article.destroy
#
module Persistence

# :nodoc:
module ClassMethods

# Get or set the default client for all repositories and models
#
# @example Set and configure the default client
#
# Elasticsearch::Persistence.client Elasticsearch::Client.new host: 'http://localhost:9200', tracer: true
#
# @example Perform an API request through the client
#
# Elasticsearch::Persistence.client.cluster.health
# # => { "cluster_name" => "elasticsearch" ... }
#
def client client=nil
@client = client || @client || Elasticsearch::Client.new
end

# Set the default client for all repositories and models
#
# @example Set and configure the default client
#
# Elasticsearch::Persistence.client = Elasticsearch::Client.new host: 'http://localhost:9200', tracer: true
# => #<Elasticsearch::Transport::Client:0x007f96a6dd0d80 @transport=... >
#
def client=(client)
@client = client
end
end

extend ClassMethods
end
end
require 'elasticsearch/persistence/repository/response/results'
51 changes: 0 additions & 51 deletions elasticsearch-persistence/lib/elasticsearch/persistence/client.rb

This file was deleted.

Loading