stretchy 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/README.md +76 -46
- data/lib/stretchy/clauses/base.rb +152 -0
- data/lib/stretchy/clauses/boost_clause.rb +139 -0
- data/lib/stretchy/clauses/boost_match_clause.rb +59 -0
- data/lib/stretchy/clauses/boost_where_clause.rb +68 -0
- data/lib/stretchy/clauses/match_clause.rb +100 -0
- data/lib/stretchy/clauses/where_clause.rb +148 -0
- data/lib/stretchy/results/base.rb +20 -1
- data/lib/stretchy/utils/client_actions.rb +24 -4
- data/lib/stretchy/utils/colorize.rb +71 -0
- data/lib/stretchy/utils/configuration.rb +15 -2
- data/lib/stretchy/utils/logger.rb +59 -0
- data/lib/stretchy/utils.rb +4 -2
- data/lib/stretchy/version.rb +1 -1
- data/lib/stretchy.rb +2 -0
- data/stretchy.gemspec +1 -0
- metadata +19 -2
@@ -2,7 +2,7 @@ module Stretchy
|
|
2
2
|
module Utils
|
3
3
|
module Configuration
|
4
4
|
|
5
|
-
attr_accessor :index_name, :logger, :url, :adapter, :client
|
5
|
+
attr_accessor :index_name, :logger, :log_level, :log_color, :url, :adapter, :client
|
6
6
|
|
7
7
|
def self.extended(base)
|
8
8
|
base.set_default_configuration
|
@@ -16,6 +16,7 @@ module Stretchy
|
|
16
16
|
self.index_name = 'myapp'
|
17
17
|
self.adapter = :excon
|
18
18
|
self.url = ENV['ELASTICSEARCH_URL']
|
19
|
+
self.log_level = :silence
|
19
20
|
end
|
20
21
|
|
21
22
|
def client_options
|
@@ -28,8 +29,20 @@ module Stretchy
|
|
28
29
|
]
|
29
30
|
end
|
30
31
|
|
32
|
+
def connect(options = {})
|
33
|
+
@client = Elasticsearch::Client.new(client_options.merge(options))
|
34
|
+
end
|
35
|
+
|
31
36
|
def client(options = {})
|
32
|
-
@client
|
37
|
+
@client || connect(options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def log_handler
|
41
|
+
@log_handler ||= Stretchy::Utils::Logger.new(logger, log_level, log_color)
|
42
|
+
end
|
43
|
+
|
44
|
+
def log(*args)
|
45
|
+
args.each {|arg| log_handler.log(arg) }
|
33
46
|
end
|
34
47
|
end
|
35
48
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'stretchy/utils/colorize'
|
3
|
+
|
4
|
+
module Stretchy
|
5
|
+
module Utils
|
6
|
+
class Logger
|
7
|
+
|
8
|
+
include Stretchy::Utils::Contract
|
9
|
+
|
10
|
+
LEVELS = [:silence, :debug, :info, :warn, :error, :fatal]
|
11
|
+
|
12
|
+
attr_accessor :base, :level, :color
|
13
|
+
|
14
|
+
contract base: { responds_to: LEVELS.last },
|
15
|
+
level: { in: LEVELS },
|
16
|
+
color: { in: Colorize::COLORS }
|
17
|
+
|
18
|
+
def self.log(msg_or_obj)
|
19
|
+
self.new.log(msg_or_obj)
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(base = nil, level = nil, color = nil)
|
23
|
+
@base = base || ::Logger.new(STDOUT)
|
24
|
+
@level = level || :silence
|
25
|
+
@color = color || :blue
|
26
|
+
|
27
|
+
@color = @color.to_s if @color.is_a?(Symbol)
|
28
|
+
validate!
|
29
|
+
end
|
30
|
+
|
31
|
+
def log(msg_or_obj, _level = nil, _color = nil)
|
32
|
+
_level ||= level
|
33
|
+
_color ||= color
|
34
|
+
|
35
|
+
return if _level == :silence
|
36
|
+
output = nil
|
37
|
+
|
38
|
+
case msg_or_obj
|
39
|
+
when String
|
40
|
+
output = Colorize.send(_color, msg_or_obj)
|
41
|
+
when Hash, Array
|
42
|
+
output = Colorize.send(_color, JSON.pretty_generate(msg_or_obj))
|
43
|
+
when Stretchy::Boosts::Base, Stretchy::Filters::Base, Stretchy::Queries::Base
|
44
|
+
output = Colorize.send(_color, JSON.pretty_generate(msg_or_obj.to_search))
|
45
|
+
else
|
46
|
+
output = Colorize.send(_color, msg_or_obj.inspect)
|
47
|
+
end
|
48
|
+
|
49
|
+
base.send(_level, output)
|
50
|
+
end
|
51
|
+
|
52
|
+
LEVELS.each do |_level|
|
53
|
+
define_method _level do |msg_or_obj, _color|
|
54
|
+
send(log, _level, msg_or_obj)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/stretchy/utils.rb
CHANGED
data/lib/stretchy/version.rb
CHANGED
data/lib/stretchy.rb
CHANGED
data/stretchy.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stretchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- agius
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '1.6'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: yard
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.8'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.8'
|
125
139
|
description: Build queries for Elasticsearch with a chainable interface like ActiveRecord's.
|
126
140
|
email:
|
127
141
|
- andrew@atevans.com
|
@@ -131,6 +145,7 @@ extra_rdoc_files: []
|
|
131
145
|
files:
|
132
146
|
- ".gitignore"
|
133
147
|
- ".travis.yml"
|
148
|
+
- ".yardopts"
|
134
149
|
- Gemfile
|
135
150
|
- README.md
|
136
151
|
- Rakefile
|
@@ -182,8 +197,10 @@ files:
|
|
182
197
|
- lib/stretchy/types/range.rb
|
183
198
|
- lib/stretchy/utils.rb
|
184
199
|
- lib/stretchy/utils/client_actions.rb
|
200
|
+
- lib/stretchy/utils/colorize.rb
|
185
201
|
- lib/stretchy/utils/configuration.rb
|
186
202
|
- lib/stretchy/utils/contract.rb
|
203
|
+
- lib/stretchy/utils/logger.rb
|
187
204
|
- lib/stretchy/version.rb
|
188
205
|
- stretchy.gemspec
|
189
206
|
homepage: https://github.com/hired/stretchy
|