stretchy-model 0.1.0 → 0.2.0
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 +4 -4
- data/README.md +3 -3
- data/lib/rails/instrumentation/publishers.rb +1 -1
- data/lib/rails/instrumentation/railtie.rb +13 -19
- data/lib/stretchy/delegation/gateway_delegation.rb +1 -1
- data/lib/stretchy/scoping/scope_registry.rb +7 -7
- data/lib/stretchy/scoping.rb +4 -4
- data/lib/stretchy/version.rb +1 -1
- data/lib/stretchy.rb +20 -3
- data/stretchy-model/lib/stretchy-model.rb +1 -0
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1709205b5fe75817fe79c5047b6f4d3531257cf8a3118f84d8fa4b92adb8932
|
4
|
+
data.tar.gz: 1add1b8c78f9c27362d31e0f1f8c141a429af4b6176b7d521e32e8a3e9230039
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf690ed5affe0224370f50e5208a6fcd0a91e611460fecf3f9a024464b0c87fa9b2718932fefca49c4ad9d587c4cc956b3490738fd794176f35d8f180dc16998
|
7
|
+
data.tar.gz: bc518187e999e3e989332612294ec8152bcc673fd5c025683e1170e8549491d8f8f3b578d4feb82a8fc4b564811f625eaae21fa5b754f0cd8fc7e36ae136c744
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
stretchy
|
1
|
+
stretchy-model
|
2
2
|
===
|
3
3
|
|
4
4
|
<p>
|
@@ -112,11 +112,11 @@ Blanket (6.322ms) curl -X GET 'http://localhost:9200/blankets/_search?size=1' -d
|
|
112
112
|
|
113
113
|
Install the gem and add to the application's Gemfile by executing:
|
114
114
|
|
115
|
-
$ bundle add stretchy
|
115
|
+
$ bundle add stretchy-model
|
116
116
|
|
117
117
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
118
118
|
|
119
|
-
$ gem install stretchy
|
119
|
+
$ gem install stretchy-model
|
120
120
|
|
121
121
|
## Development
|
122
122
|
|
@@ -14,7 +14,7 @@ module Rails
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def search_with_instrumentation!(query_or_definition, options={})
|
17
|
-
ActiveSupport::Notifications.instrument "search.
|
17
|
+
ActiveSupport::Notifications.instrument "search.stretchy",
|
18
18
|
name: "Search",
|
19
19
|
klass: self.base_class.to_s,
|
20
20
|
search: {index: self.index_name, body: query_or_definition }.merge(options) do
|
@@ -2,27 +2,21 @@ module Stretchy
|
|
2
2
|
module Instrumentation
|
3
3
|
|
4
4
|
class Railtie < ::Rails::Railtie
|
5
|
-
include ActionView::Helpers::NumberHelper
|
6
|
-
def time_diff(start, finish)
|
7
|
-
begin
|
8
|
-
((finish.to_time - start.to_time) * 1000).to_s(:rounded, precision: 5, strip_insignificant_zeros: true)
|
9
|
-
rescue
|
10
|
-
number_with_precision((finish.to_time - start.to_time) * 1000, precision: 5, strip_insignificant_zeros: true)
|
11
|
-
end
|
12
|
-
end
|
13
5
|
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
require 'rails/instrumentation/publishers'
|
7
|
+
ActiveSupport::Notifications.subscribe 'search.stretchy' do |name, start, finish, id, payload|
|
8
|
+
message = [
|
9
|
+
Rainbow(" #{payload[:klass]}").bright,
|
10
|
+
"(#{(finish.to_time - start.to_time).round(2)}ms)",
|
11
|
+
Stretchy::Utils.to_curl(payload[:klass].constantize, payload[:search])
|
12
|
+
].join(" ")
|
13
|
+
::Rails.logger.debug(Rainbow(message).color(:yellow))
|
14
|
+
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
initializer 'stretchy.set_defaults' do
|
23
|
-
config.elasticsearch_cache_store = :redis_store
|
24
|
-
config.elasticsearch_expire_cache_in = 15.minutes
|
25
|
-
end
|
16
|
+
# initializer 'stretchy.set_defaults' do
|
17
|
+
# config.elasticsearch_cache_store = :redis_store
|
18
|
+
# config.elasticsearch_expire_cache_in = 15.minutes
|
19
|
+
# end
|
26
20
|
|
27
21
|
end
|
28
22
|
end
|
@@ -33,7 +33,7 @@ module Stretchy
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def gateway(&block)
|
36
|
-
@gateway ||= Stretchy::Repository.create(index_name: index_name, klass: base_class)
|
36
|
+
@gateway ||= Stretchy::Repository.create(client: Stretchy.configuration.client, index_name: index_name, klass: base_class)
|
37
37
|
block.arity < 1 ? @gateway.instance_eval(&block) : block.call(@gateway) if block_given?
|
38
38
|
@gateway
|
39
39
|
end
|
@@ -6,20 +6,20 @@ module Stretchy
|
|
6
6
|
|
7
7
|
VALID_SCOPE_TYPES = [:current_scope, :ignore_default_scope]
|
8
8
|
|
9
|
-
def initialize
|
10
|
-
|
11
|
-
end
|
9
|
+
# def initialize
|
10
|
+
self.registry = Hash.new { |hash, key| hash[key] = {} }
|
11
|
+
# end
|
12
12
|
|
13
13
|
# Obtains the value for a given +scope_name+ and +variable_name+.
|
14
|
-
def value_for(scope_type, variable_name)
|
14
|
+
def self.value_for(scope_type, variable_name)
|
15
15
|
raise_invalid_scope_type!(scope_type)
|
16
|
-
|
16
|
+
self.registry[scope_type][variable_name]
|
17
17
|
end
|
18
18
|
|
19
19
|
# Sets the +value+ for a given +scope_type+ and +variable_name+.
|
20
|
-
def set_value_for(scope_type, variable_name, value)
|
20
|
+
def self.set_value_for(scope_type, variable_name, value)
|
21
21
|
raise_invalid_scope_type!(scope_type)
|
22
|
-
|
22
|
+
self.registry[scope_type][variable_name] = value
|
23
23
|
end
|
24
24
|
|
25
25
|
private
|
data/lib/stretchy/scoping.rb
CHANGED
@@ -13,13 +13,13 @@ module Stretchy
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def current_scope
|
16
|
-
|
17
|
-
ScopeRegistry.
|
16
|
+
ScopeRegistry.new.registry[:current_scope][base_class.to_s]
|
17
|
+
# ScopeRegistry.value_for(:current_scope, base_class.to_s)
|
18
18
|
end
|
19
19
|
|
20
20
|
def current_scope=(scope) #:nodoc:
|
21
|
-
|
22
|
-
ScopeRegistry.
|
21
|
+
ScopeRegistry.new.registry[:current_scope][base_class.to_s] = scope
|
22
|
+
# ScopeRegistry.set_value_for(:current_scope, base_class.to_s, scope)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
data/lib/stretchy/version.rb
CHANGED
data/lib/stretchy.rb
CHANGED
@@ -3,10 +3,8 @@ require 'zeitwerk'
|
|
3
3
|
require 'amazing_print'
|
4
4
|
require 'rainbow'
|
5
5
|
require 'jbuilder'
|
6
|
-
# require 'elasticsearch/rails'
|
7
6
|
require 'elasticsearch/model'
|
8
7
|
require 'elasticsearch/persistence'
|
9
|
-
# require 'active_support/concern'
|
10
8
|
require 'active_model'
|
11
9
|
require 'active_support/all'
|
12
10
|
require 'active_model/type/array'
|
@@ -16,19 +14,38 @@ ActiveModel::Type.register(:array, ActiveModel::Type::Array)
|
|
16
14
|
ActiveModel::Type.register(:hash, ActiveModel::Type::Hash)
|
17
15
|
|
18
16
|
require_relative "stretchy/version"
|
19
|
-
require_relative "
|
17
|
+
require_relative "rails/instrumentation/railtie" if defined?(Rails)
|
20
18
|
|
21
19
|
module Stretchy
|
22
20
|
module Errors
|
23
21
|
class QueryOptionMissing < StandardError; end
|
24
22
|
end
|
25
23
|
|
24
|
+
class Configuration
|
25
|
+
|
26
|
+
attr_accessor :client
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@client = Elasticsearch::Client.new url: 'http://localhost:9200'
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
26
34
|
class << self
|
27
35
|
def logger
|
28
36
|
@logger ||= Logger.new(STDOUT)
|
29
37
|
end
|
38
|
+
|
39
|
+
def configuration
|
40
|
+
@configuration ||= Configuration.new
|
41
|
+
end
|
42
|
+
|
43
|
+
def configure
|
44
|
+
yield configuration
|
45
|
+
end
|
30
46
|
end
|
31
47
|
|
48
|
+
|
32
49
|
end
|
33
50
|
|
34
51
|
loader = Zeitwerk::Loader.new
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "../../lib/stretchy"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stretchy-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Spencer Markowski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -28,42 +28,42 @@ dependencies:
|
|
28
28
|
name: elasticsearch-rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '7.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '7.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: elasticsearch-persistence
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '7.1'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '7.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: elasticsearch-model
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '7.1'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '7.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
@@ -217,6 +217,7 @@ files:
|
|
217
217
|
- lib/stretchy/utils.rb
|
218
218
|
- lib/stretchy/version.rb
|
219
219
|
- sig/stretchy.rbs
|
220
|
+
- stretchy-model/lib/stretchy-model.rb
|
220
221
|
- stretchy.logo.png
|
221
222
|
homepage: https://github.com/theablefew/stretchy
|
222
223
|
licenses:
|
@@ -229,6 +230,7 @@ post_install_message:
|
|
229
230
|
rdoc_options: []
|
230
231
|
require_paths:
|
231
232
|
- lib
|
233
|
+
- stretchy-model/lib
|
232
234
|
required_ruby_version: !ruby/object:Gem::Requirement
|
233
235
|
requirements:
|
234
236
|
- - ">="
|