elastify 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52f92afd2a45df622a50571ed9a39d5ec3cb8518
4
- data.tar.gz: 467a2373ede71ebadf822f31e7452e19ef4c7f71
3
+ metadata.gz: 39b47345213b76f73caeca0ede7a9eee9714f969
4
+ data.tar.gz: dd96aae8aa98923485139aee53348e6d4749d989
5
5
  SHA512:
6
- metadata.gz: 6c86d092e4fbbde756540849a5227398c735aa0c81757d2d177b0b4900838533a7e12bed990e836af6fcd64154002838315712a37dced0475441542ca5d0d240
7
- data.tar.gz: 46a90cfc07fb96296b46a572a328799c2098a94f26e0b91689dce6b450677469bd99276781ecb6ac0af67b533462ad88e0815ca79a7bcb794406bd24e280e150
6
+ metadata.gz: 1a751e4ac6c914c472b472155a4090bceba325b8f341bf9ce2f03a4ad03a5204c23261241056ca6218f9e51b48eb68115268ba55155e12cf1d1297cd78c8e277
7
+ data.tar.gz: 1e958d6c57eeeceb74d4374231109b7c5596a496667236cda47e6638e3d794f8ba4bd3fc8e762c957039410e03c41e82fdda4b06d4b3cf3dccd3f0a7ddc0109c
@@ -1,22 +1,23 @@
1
1
  require 'active_record'
2
2
  require 'backgrounded'
3
3
  require 'elastify/elastic_search_helper'
4
+ require 'elastify'
4
5
 
5
6
  module Elastify
6
7
  module ActiveRecordExtensions
7
8
  extend ActiveSupport::Concern
8
9
 
9
10
  module ClassMethods
10
- def elastify elastify_options = {}, &block
11
+ def elastify type, index, &block
11
12
  include Elastify::ActiveRecordExtensions::LocalMethods
12
13
  cattr_accessor :elastify_options, :elastify_model_block
13
14
  attr_accessor :elastify_serialized_document
14
15
 
15
16
  self.elastify_options = {
16
- base_url: Elastify.defaults[:base_url],
17
- index: elastify_options[:index] || Elastify.defaults[:default_index],
18
- type: elastify_options[:type] || Elastify.defaults[:default_type],
19
- map: elastify_options[:map] || Elastify.defaults[:default_map]
17
+ base_url: Elastify.configs[:base_url],
18
+ index: index,
19
+ type: type,
20
+ map: Elastify.mappings.symbolize_keys[type.to_sym]
20
21
  }
21
22
 
22
23
  self.elastify_options.each do |key, value|
@@ -28,9 +29,13 @@ module Elastify
28
29
  if block_given?
29
30
  self.elastify_model_block = block
30
31
  else
31
- self.elastify_model_block = Proc.new { |item|
32
- next Hash.new
33
- }
32
+ if self.respond_to?(:to_elastify)
33
+ self.elastify_model_block = Proc.new { |item| next item.to_elastify }
34
+ elsif self.respond_to?(:to_serial)
35
+ self.elastify_model_block = Proc.new { |item| next item.to_serial }
36
+ else
37
+ self.elastify_model_block = Proc.new { |item| next item.serializable_hash }
38
+ end
34
39
  end
35
40
  end
36
41
  end
@@ -106,4 +111,4 @@ module Elastify
106
111
  end
107
112
  end
108
113
 
109
- ActiveRecord::Base.send(:include, Elastify::ActiveRecordExtensions)
114
+ ActiveRecord::Base.send(:include, Elastify::ActiveRecordExtensions)
@@ -80,7 +80,8 @@ module Elastify
80
80
  end
81
81
  def self.create_mapping options
82
82
  url = "#{options[:base_url]}/#{options[:index]}/_mappings/#{options[:type]}"
83
- response = JSON.parse(RestClient.put(url, options[:map].to_json, {})).to_hash
83
+ puts options[:map]
84
+ response = JSON.parse(RestClient.put(url, options[:map].squish, {})).to_hash
84
85
  end
85
86
  end
86
87
  class SearchResultSet
@@ -1,3 +1,3 @@
1
1
  module Elastify
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/elastify.rb CHANGED
@@ -2,12 +2,35 @@ require "elastify/version"
2
2
  require "elastify/active_record_extensions"
3
3
 
4
4
  module Elastify
5
- cattr_accessor :defaults
6
5
 
7
-
8
6
  class << self
9
-
10
- end
7
+ def configure &block
8
+ mappings = {}
9
+ configs = OpenStruct.new({
10
+ base_url: "http://localhost:9200",
11
+ mappings_path: Rails.root.join("config/elastify/mappings")
12
+ })
13
+ block.call(configs) if block_given?
14
+ dir = configs.mappings_path
15
+ if Dir.exist?(dir)
16
+ Dir.glob("#{dir}/*.json") do |file_path|
17
+ mappings[File.basename(file_path, ".json")] = JSON.parse(File.read(file_path))
18
+ end
19
+ end
20
+ Rails.application.config.elastify = {
21
+ configs: configs,
22
+ mappings: mappings,
23
+ }
24
+ end
25
+
26
+ def configs
27
+ return Rails.application.config.elastify[:configs]
28
+ end
11
29
 
30
+ def mappings
31
+ return Rails.application.config.elastify[:mappings]
32
+ end
33
+ end
34
+
12
35
  class ElastifyError < StandardError; end
13
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Bortolotti Ribeiro