elastic_models 0.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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in elastic_models.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Brian McNabb
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,20 @@
1
+ = elastic_models
2
+
3
+ A wrapper for the tire gem that includes a base level ElasticSearch configuration in ActiveRecord models.
4
+
5
+ == Features
6
+
7
+ === Easy to use
8
+ Just bundle the gem, then your models are ElasticSearch-able.
9
+
10
+ == Install
11
+
12
+ Put this line in your Gemfile:
13
+ gem 'elastic_models'
14
+
15
+ Then bundle:
16
+ % bundle
17
+
18
+ == Copyright
19
+
20
+ Copyright (c) 2012 Brian McNabb. See LICENSE for further details.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "elastic_models/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "elastic_models"
7
+ s.version = ElasticModels::VERSION
8
+ s.authors = ["Brian McNabb"]
9
+ s.email = ["brian.d.mcnabb@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{A wrapper for the tire gem that includes a base level ElasticSearch configuration in ActiveRecord models using Tire.}
12
+ s.description = %q{ElasticSearch-able Models!}
13
+
14
+ s.rubyforge_project = "elastic_models"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "tire"
22
+ s.add_dependency "sortable_columns"
23
+
24
+ s.add_development_dependency "rspec"
25
+ end
@@ -0,0 +1,8 @@
1
+ require 'rails'
2
+
3
+ module ElasticModels
4
+ ActiveSupport.on_load(:active_record) do
5
+ require 'elastic_models/active_record_extension'
6
+ include ElasticModels::ActiveRecordExtension
7
+ end
8
+ end
@@ -0,0 +1,31 @@
1
+ require 'tire'
2
+ require File.join(File.dirname(__FILE__), 'search')
3
+
4
+ module ElasticModels
5
+ module ActiveRecordExtension
6
+ extend ActiveSupport::Concern
7
+ included do
8
+ # Future subclasses will pick up the model extension
9
+ class << self
10
+ def inherited_with_elastic_models(subclass) #:nodoc:
11
+ inherited_without_elastic_models subclass
12
+ if subclass.superclass == ActiveRecord::Base
13
+ subclass.send(:include, Tire::Model::Search)
14
+ subclass.send(:include, Tire::Model::Callbacks)
15
+ subclass.send(:include, ElasticModels::Search)
16
+ end
17
+ end
18
+ alias_method_chain :inherited, :elastic_models
19
+ end
20
+
21
+ # Existing subclasses pick up the model extension as well
22
+ self.descendants.each do |subclass|
23
+ if subclass.superclass == ActiveRecord::Base
24
+ subclass.send(:include, Tire::Model::Search)
25
+ subclass.send(:include, Tire::Model::Callbacks)
26
+ subclass.send(:include, ElasticModels::Search)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ module ElasticModels
2
+ module Search
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ class << self
7
+ def search(params)
8
+ tire.search(load: true, page: (params[:page] || 1), per_page: 2 ) do |t|
9
+
10
+ if params[:query].present?
11
+ t.query { string params[:query], default_operator: 'AND' }
12
+ end
13
+
14
+ if params[:query].blank?
15
+ sorting = SortableColumns::ColumnSorter.new(self)
16
+ t.sort { by sorting.column(params[:sort]), sorting.direction(params[:direction]) }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module ElasticModels
2
+ VERSION = "0.0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elastic_models
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brian McNabb
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-10 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: tire
16
+ requirement: &70334135035300 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70334135035300
25
+ - !ruby/object:Gem::Dependency
26
+ name: sortable_columns
27
+ requirement: &70334135034760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70334135034760
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70334135034180 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70334135034180
47
+ description: ElasticSearch-able Models!
48
+ email:
49
+ - brian.d.mcnabb@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.rdoc
58
+ - Rakefile
59
+ - elastic_models.gemspec
60
+ - lib/elastic_models.rb
61
+ - lib/elastic_models/active_record_extension.rb
62
+ - lib/elastic_models/search.rb
63
+ - lib/elastic_models/version.rb
64
+ homepage: ''
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project: elastic_models
84
+ rubygems_version: 1.8.10
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: A wrapper for the tire gem that includes a base level ElasticSearch configuration
88
+ in ActiveRecord models using Tire.
89
+ test_files: []