mini-smart-box 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.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/elasticsearch-rails-8.0.1/CHANGELOG.md +44 -0
  3. data/elasticsearch-rails-8.0.1/Gemfile +38 -0
  4. data/elasticsearch-rails-8.0.1/LICENSE.txt +202 -0
  5. data/elasticsearch-rails-8.0.1/README.md +149 -0
  6. data/elasticsearch-rails-8.0.1/Rakefile +67 -0
  7. data/elasticsearch-rails-8.0.1/elasticsearch-rails.gemspec +67 -0
  8. data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails/instrumentation/controller_runtime.rb +58 -0
  9. data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails/instrumentation/log_subscriber.rb +67 -0
  10. data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails/instrumentation/publishers.rb +53 -0
  11. data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails/instrumentation/railtie.rb +44 -0
  12. data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails/instrumentation.rb +53 -0
  13. data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails/lograge.rb +57 -0
  14. data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails/tasks/import.rb +128 -0
  15. data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails/version.rb +22 -0
  16. data/elasticsearch-rails-8.0.1/lib/elasticsearch/rails.rb +24 -0
  17. data/elasticsearch-rails-8.0.1/lib/rails/templates/01-basic.rb +364 -0
  18. data/elasticsearch-rails-8.0.1/lib/rails/templates/02-pretty.rb +348 -0
  19. data/elasticsearch-rails-8.0.1/lib/rails/templates/03-expert.rb +358 -0
  20. data/elasticsearch-rails-8.0.1/lib/rails/templates/04-dsl.rb +146 -0
  21. data/elasticsearch-rails-8.0.1/lib/rails/templates/05-settings-files.rb +88 -0
  22. data/elasticsearch-rails-8.0.1/lib/rails/templates/articles.yml.gz +0 -0
  23. data/elasticsearch-rails-8.0.1/lib/rails/templates/articles_settings.json +1 -0
  24. data/elasticsearch-rails-8.0.1/lib/rails/templates/index.html.dsl.erb +178 -0
  25. data/elasticsearch-rails-8.0.1/lib/rails/templates/index.html.erb +178 -0
  26. data/elasticsearch-rails-8.0.1/lib/rails/templates/indexer.rb +44 -0
  27. data/elasticsearch-rails-8.0.1/lib/rails/templates/search.css +76 -0
  28. data/elasticsearch-rails-8.0.1/lib/rails/templates/search_controller_test.dsl.rb +148 -0
  29. data/elasticsearch-rails-8.0.1/lib/rails/templates/search_controller_test.rb +148 -0
  30. data/elasticsearch-rails-8.0.1/lib/rails/templates/searchable.dsl.rb +234 -0
  31. data/elasticsearch-rails-8.0.1/lib/rails/templates/searchable.rb +224 -0
  32. data/elasticsearch-rails-8.0.1/lib/rails/templates/seeds.rb +75 -0
  33. data/elasticsearch-rails-8.0.1/spec/instrumentation/log_subscriber_spec.rb +57 -0
  34. data/elasticsearch-rails-8.0.1/spec/instrumentation_spec.rb +103 -0
  35. data/elasticsearch-rails-8.0.1/spec/lograge_spec.rb +52 -0
  36. data/elasticsearch-rails-8.0.1/spec/spec_helper.rb +65 -0
  37. data/mini-smart-box.gemspec +11 -0
  38. metadata +76 -0
@@ -0,0 +1,57 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ require 'spec_helper'
19
+ require 'elasticsearch/rails/instrumentation/log_subscriber'
20
+
21
+ describe Elasticsearch::Rails::Instrumentation::LogSubscriber do
22
+ subject(:instance) { described_class.new }
23
+
24
+ let(:logger) { instance_double(Logger) }
25
+
26
+ before do
27
+ allow(instance).to receive(:logger) { logger }
28
+ end
29
+
30
+ describe '#search' do
31
+ subject { instance.search(event) }
32
+
33
+ let(:event) { double("search.elasticsearch", duration: 1.2345, payload: { name: "execute", search: { query: { match_all: {}}}}) }
34
+
35
+ it 'logs the event' do
36
+ expect(instance).to receive(:color).with(" execute (1.2ms)", described_class::GREEN, { bold: true }).and_call_original
37
+ expect(logger).to receive(:debug?) { true }
38
+ expect(logger).to receive(:debug).with(" \e[1m\e[32m execute (1.2ms)\e[0m \e[2m{query: {match_all: {}}}\e[0m")
39
+ subject
40
+ end
41
+
42
+ context 'when ActiveSupport version is older' do
43
+ let(:active_support_version) { '7.0.0' }
44
+
45
+ before do
46
+ allow(::ActiveSupport).to receive(:gem_version) { Gem::Version.new(active_support_version) }
47
+ end
48
+
49
+ it 'logs the event' do
50
+ expect(instance).to receive(:color).with(' execute (1.2ms)', described_class::GREEN, true).and_return "\e[1m\e[32m execute (1.2ms)\e[0m"
51
+ expect(logger).to receive(:debug?) { true }
52
+ expect(logger).to receive(:debug).with(" \e[1m\e[32m execute (1.2ms)\e[0m \e[2m{query: {match_all: {}}}\e[0m")
53
+ subject
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,103 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ require 'spec_helper'
19
+
20
+ describe 'ActiveSupport::Instrumentation integration' do
21
+ before(:all) do
22
+ class DummyInstrumentationModel
23
+ extend Elasticsearch::Model::Searching::ClassMethods
24
+ def self.index_name; 'foo'; end
25
+ end
26
+ end
27
+
28
+ after(:all) do
29
+ remove_classes(DummyInstrumentationModel)
30
+ end
31
+
32
+ let(:response_document) do
33
+ {
34
+ 'took' => '5ms',
35
+ 'hits' => {
36
+ 'total' => 123,
37
+ 'max_score' => 456,
38
+ 'hits' => []
39
+ }
40
+ }
41
+ end
42
+
43
+ let(:search) do
44
+ Elasticsearch::Model::Searching::SearchRequest.new(DummyInstrumentationModel, 'foo')
45
+ end
46
+
47
+ let(:client) do
48
+ double('client', search: response_document)
49
+ end
50
+
51
+ before do
52
+ allow(DummyInstrumentationModel).to receive(:client).and_return(client)
53
+ Elasticsearch::Rails::Instrumentation::Railtie.run_initializers
54
+ end
55
+
56
+ context 'SearchRequest#execute!' do
57
+ it 'wraps the method with instrumentation' do
58
+ expect(search).to respond_to(:execute_without_instrumentation!)
59
+ expect(search).to respond_to(:execute_with_instrumentation!)
60
+ end
61
+ end
62
+
63
+ context 'Model#search' do
64
+ before do
65
+ expect(ActiveSupport::Notifications).
66
+ to receive(:instrument).
67
+ with('search.elasticsearch',
68
+ {
69
+ klass: 'DummyInstrumentationModel',
70
+ name: 'Search',
71
+ search: {
72
+ body: query,
73
+ index: 'foo',
74
+ }
75
+ }
76
+ ).and_return({})
77
+ end
78
+
79
+ let(:query) do
80
+ { query: { match: { foo: 'bar' } } }
81
+ end
82
+
83
+ let(:logged_message) do
84
+ @logger.logged(:debug).first
85
+ end
86
+
87
+ it 'publishes a notification' do
88
+ expect(DummyInstrumentationModel.search(query).response).to eq({})
89
+ end
90
+
91
+ context 'when a message is logged', unless: defined?(RUBY_VERSION) && RUBY_VERSION > '2.2' do
92
+
93
+ let(:query) do
94
+ { query: { match: { moo: 'bam' } } }
95
+ end
96
+
97
+ it 'prints the debug information to the log' do
98
+ expect(logged_message).to match(/DummyInstrumentationModel Search \(\d+\.\d+ms\)/)
99
+ expect(logged_message).to match(/body\: \{query\: \{match\: \{moo\: "bam"\}\}\}\}/)
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,52 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+
19
+ # Licensed to Elasticsearch B.V. under one or more contributor
20
+ # license agreements. See the NOTICE file distributed with
21
+ # this work for additional information regarding copyright
22
+ # ownership. Elasticsearch B.V. licenses this file to you under
23
+ # the Apache License, Version 2.0 (the "License"); you may
24
+ # not use this file except in compliance with the License.
25
+ # You may obtain a copy of the License at
26
+ #
27
+ # http://www.apache.org/licenses/LICENSE-2.0
28
+ #
29
+ # Unless required by applicable law or agreed to in writing,
30
+ # software distributed under the License is distributed on an
31
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
32
+ # KIND, either express or implied. See the License for the
33
+ # specific language governing permissions and limitations
34
+ # under the License.
35
+ require 'spec_helper'
36
+ require 'action_pack'
37
+ require 'lograge'
38
+ require 'elasticsearch/rails/lograge'
39
+
40
+ describe 'ActiveSupport::Instrumentation integration' do
41
+ before do
42
+ Elasticsearch::Rails::Lograge::Railtie.run_initializers
43
+ end
44
+
45
+ it 'customizes the Lograge configuration' do
46
+ expect(
47
+ Elasticsearch::Rails::Lograge::Railtie.initializers
48
+ .select { |i| i.name == 'elasticsearch.lograge' }
49
+ .first
50
+ ).not_to be_nil
51
+ end
52
+ end
@@ -0,0 +1,65 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ require 'pry-nav'
19
+ require 'active_record'
20
+ require 'elasticsearch/model'
21
+ require 'elasticsearch/rails'
22
+ require 'rails/railtie'
23
+ require 'rails/version'
24
+ require 'elasticsearch/rails/instrumentation'
25
+
26
+
27
+ unless defined?(ELASTICSEARCH_URL)
28
+ ELASTICSEARCH_URL = ENV['ELASTICSEARCH_URL'] || "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9200)}"
29
+ end
30
+
31
+ RSpec.configure do |config|
32
+ config.formatter = 'documentation'
33
+ config.color = true
34
+
35
+ config.before(:suite) do
36
+ require 'ansi'
37
+ tracer = ::Logger.new(STDERR)
38
+ tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" }
39
+ Elasticsearch::Model.client = Elasticsearch::Client.new host: ELASTICSEARCH_URL,
40
+ tracer: (ENV['QUIET'] ? nil : tracer),
41
+ transport_options: { :ssl => { verify: false } }
42
+ puts "Elasticsearch Version: #{Elasticsearch::Model.client.info['version']}"
43
+
44
+ unless ActiveRecord::Base.connected?
45
+ ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :database => ":memory:" )
46
+ end
47
+
48
+ if ::ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks) && ::ActiveRecord::VERSION::MAJOR.to_s < '5'
49
+ ::ActiveRecord::Base.raise_in_transactional_callbacks = true
50
+ end
51
+ end
52
+ end
53
+
54
+ # Remove all classes.
55
+ #
56
+ # @param [ Array<Class> ] classes The list of classes to remove.
57
+ #
58
+ # @return [ true ]
59
+ #
60
+ # @since 6.0.1
61
+ def remove_classes(*classes)
62
+ classes.each do |_class|
63
+ Object.send(:remove_const, _class.name.to_sym) if defined?(_class)
64
+ end and true
65
+ end
@@ -0,0 +1,11 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "mini-smart-box"
3
+ s.version = "0.0.1"
4
+ s.summary = "Research test"
5
+ s.description = "University research based on elasticsearch-rails"
6
+ s.authors = ["Andrey78"]
7
+ s.email = ["cakoc614@gmail.com"]
8
+ s.files = Dir.glob("**/*").reject { |f| f.end_with?('.gem') }
9
+ s.homepage = "https://rubygems.org/profiles/Andrey78"
10
+ s.license = "MIT"
11
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mini-smart-box
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrey78
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2026-07-06 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: University research based on elasticsearch-rails
13
+ email:
14
+ - cakoc614@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - elasticsearch-rails-8.0.1/CHANGELOG.md
20
+ - elasticsearch-rails-8.0.1/Gemfile
21
+ - elasticsearch-rails-8.0.1/LICENSE.txt
22
+ - elasticsearch-rails-8.0.1/README.md
23
+ - elasticsearch-rails-8.0.1/Rakefile
24
+ - elasticsearch-rails-8.0.1/elasticsearch-rails.gemspec
25
+ - elasticsearch-rails-8.0.1/lib/elasticsearch/rails.rb
26
+ - elasticsearch-rails-8.0.1/lib/elasticsearch/rails/instrumentation.rb
27
+ - elasticsearch-rails-8.0.1/lib/elasticsearch/rails/instrumentation/controller_runtime.rb
28
+ - elasticsearch-rails-8.0.1/lib/elasticsearch/rails/instrumentation/log_subscriber.rb
29
+ - elasticsearch-rails-8.0.1/lib/elasticsearch/rails/instrumentation/publishers.rb
30
+ - elasticsearch-rails-8.0.1/lib/elasticsearch/rails/instrumentation/railtie.rb
31
+ - elasticsearch-rails-8.0.1/lib/elasticsearch/rails/lograge.rb
32
+ - elasticsearch-rails-8.0.1/lib/elasticsearch/rails/tasks/import.rb
33
+ - elasticsearch-rails-8.0.1/lib/elasticsearch/rails/version.rb
34
+ - elasticsearch-rails-8.0.1/lib/rails/templates/01-basic.rb
35
+ - elasticsearch-rails-8.0.1/lib/rails/templates/02-pretty.rb
36
+ - elasticsearch-rails-8.0.1/lib/rails/templates/03-expert.rb
37
+ - elasticsearch-rails-8.0.1/lib/rails/templates/04-dsl.rb
38
+ - elasticsearch-rails-8.0.1/lib/rails/templates/05-settings-files.rb
39
+ - elasticsearch-rails-8.0.1/lib/rails/templates/articles.yml.gz
40
+ - elasticsearch-rails-8.0.1/lib/rails/templates/articles_settings.json
41
+ - elasticsearch-rails-8.0.1/lib/rails/templates/index.html.dsl.erb
42
+ - elasticsearch-rails-8.0.1/lib/rails/templates/index.html.erb
43
+ - elasticsearch-rails-8.0.1/lib/rails/templates/indexer.rb
44
+ - elasticsearch-rails-8.0.1/lib/rails/templates/search.css
45
+ - elasticsearch-rails-8.0.1/lib/rails/templates/search_controller_test.dsl.rb
46
+ - elasticsearch-rails-8.0.1/lib/rails/templates/search_controller_test.rb
47
+ - elasticsearch-rails-8.0.1/lib/rails/templates/searchable.dsl.rb
48
+ - elasticsearch-rails-8.0.1/lib/rails/templates/searchable.rb
49
+ - elasticsearch-rails-8.0.1/lib/rails/templates/seeds.rb
50
+ - elasticsearch-rails-8.0.1/spec/instrumentation/log_subscriber_spec.rb
51
+ - elasticsearch-rails-8.0.1/spec/instrumentation_spec.rb
52
+ - elasticsearch-rails-8.0.1/spec/lograge_spec.rb
53
+ - elasticsearch-rails-8.0.1/spec/spec_helper.rb
54
+ - mini-smart-box.gemspec
55
+ homepage: https://rubygems.org/profiles/Andrey78
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.6.2
74
+ specification_version: 4
75
+ summary: Research test
76
+ test_files: []