needle_in_a_haystack 1.0.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4866e9ea873340add03eadd30959c1394cd0168c03ebeeb7e28c37047d4eff29
4
- data.tar.gz: 1764b64f7a33a738335b446faa2340887d95ad9e0d1c12ddc208eadee921f6c1
3
+ metadata.gz: 7e365c25451da6fb9d1ab929ece76bfea7e5753544818eb5e8650642ed5d10b6
4
+ data.tar.gz: d926c7e2ad775dc46d5c38a48b352dfd1ffd369196f3c3aab7aabe40c915d142
5
5
  SHA512:
6
- metadata.gz: e535c31af08738c6064e8bb3c818080ebf4dae98add9a4aa35b19d6485051b2aee6ed8cc474446007773d557f7f2870b9e85963115b6d342c7ad8af101a35c9d
7
- data.tar.gz: 68baca7aacb408a164a8c020c8beda399f9d86955aef9d857a5f6d67ac300943047c21e37732b94130e64efc83bf18689c054488f5da2418fc5ef5f858479a66
6
+ metadata.gz: 6cfd26955113913e7ef3f5f24435485f45d83dac53f54b92d10cc7199f6c48358c1aa8072cdd911bc4e700acbd184ccdab808a987775addd438654e88218c363
7
+ data.tar.gz: 20f66d4f920165380f95fd2f981207131034f96a14b86d6019e62f9c77cc83127669bae046ef02c599a7dd210c716d9a6510582d4f6157fb5b34317e0bd40796
@@ -1,5 +1,5 @@
1
1
  ENABLE_SENTRY_RAVEN ||= true
2
- SERVER_URL ||= "http://localhost"
2
+ SERVER_URL ||= "http://localhost".freeze
3
3
  SERVER_PORT ||= 3000
4
- USERNAME ||= "admin"
5
- PASSWORD ||= "password"
4
+ USERNAME ||= "admin".freeze
5
+ PASSWORD ||= "password".freeze
@@ -1,2 +1,2 @@
1
1
  require "connection_pool"
2
- Redis::Objects.redis = ConnectionPool.new(size: 8, timeout: 5) { Redis.new(path: "/tmp/redis.sock")}
2
+ Redis::Objects.redis = ConnectionPool.new(size: 8, timeout: 5) { Redis.new(path: "/tmp/redis.sock") }
@@ -1,33 +1,2 @@
1
- # Files in the config/locales directory are used for internationalization
2
- # and are automatically loaded by Rails. If you want to use locales other
3
- # than English, add the necessary files in this directory.
4
- #
5
- # To use the locales, use `I18n.t`:
6
- #
7
- # I18n.t 'hello'
8
- #
9
- # In views, this is aliased to just `t`:
10
- #
11
- # <%= t('hello') %>
12
- #
13
- # To use a different locale, set it with `I18n.locale`:
14
- #
15
- # I18n.locale = :es
16
- #
17
- # This would use the information in config/locales/es.yml.
18
- #
19
- # The following keys must be escaped otherwise they will not be retrieved by
20
- # the default I18n backend:
21
- #
22
- # true, false, on, off, yes, no
23
- #
24
- # Instead, surround them with single quotes.
25
- #
26
- # en:
27
- # 'true': 'foo'
28
- #
29
- # To learn more, please read the Rails Internationalization guide
30
- # available at https://guides.rubyonrails.org/i18n.html.
31
-
32
1
  en:
33
- hello: "Hello world"
2
+ circular_reference: Circular reference detected
@@ -1,5 +1,3 @@
1
- module NeedleInAHaystack
2
- class ApplicationRecord < ActiveRecord::Base
3
- self.abstract_class = true
4
- end
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
5
3
  end
@@ -1,9 +1,15 @@
1
- module NeedleInAHaystack
2
- class Configuration
3
- attr_accessor :taggable_models
1
+ class Configuration
2
+ attr_accessor :taggable_models
4
3
 
5
- def initialize
6
- @taggable_models = []
7
- end
4
+ def initialize
5
+ @taggable_models = []
8
6
  end
9
7
  end
8
+
9
+ def self.configuration
10
+ @configuration ||= Configuration.new
11
+ end
12
+
13
+ def self.configure
14
+ yield(configuration)
15
+ end
@@ -1,11 +1,8 @@
1
- module NeedleInAHaystack
2
- class Engine < ::Rails::Engine
3
- isolate_namespace NeedleInAHaystack
4
- end
1
+ class Engine < ::Rails::Engine
2
+ end
5
3
 
6
- raise "Gem 'needle_in_a_haystack' is not loaded" unless Gem.loaded_specs["needle_in_a_haystack"]
4
+ raise "Gem 'needle_in_a_haystack' is not loaded" unless Gem.loaded_specs["needle_in_a_haystack"]
7
5
 
8
- Gem.loaded_specs["needle_in_a_haystack"].dependencies.each do |d|
9
- require d.name
10
- end
6
+ Gem.loaded_specs["needle_in_a_haystack"].dependencies.each do |d|
7
+ require d.name
11
8
  end
@@ -1,68 +1,66 @@
1
- module NeedleInAHaystack
2
- class HaystackOntology < ApplicationRecord
3
- def self.tags
4
- @tags ||= YAML.load_file(Rails.root.join("config/haystack_ontology.yml"))
5
- end
6
-
7
- def self.find_tag(path)
8
- return nil if path.nil?
9
-
10
- path.include?(".") ? find_tag_in_hierarchy(tags, path.split(".").last) : find_tag_in_hierarchy(tags, path)
11
- end
12
-
13
- def self.find_tag_in_hierarchy(current_hash, target_key, path = [])
14
- return nil unless current_hash.is_a?(Hash)
1
+ class HaystackOntology < ApplicationRecord
2
+ def self.tags
3
+ @tags ||= YAML.load_file(Rails.root.join("config/haystack_ontology.yml"))
4
+ end
15
5
 
16
- result = current_hash[target_key]
17
- return result.is_a?(Hash) ? result.merge("path" => path.push(target_key).join(".")) : result if result
6
+ def self.find_tag(path)
7
+ return nil if path.nil?
18
8
 
19
- children = current_hash["children"]
20
- if children.is_a?(Hash)
21
- children.each do |key, value|
22
- new_path = path + [key]
23
- return value.merge("path" => new_path.join(".")) if key == target_key
9
+ path.include?(".") ? find_tag_in_hierarchy(tags, path.split(".").last) : find_tag_in_hierarchy(tags, path)
10
+ end
24
11
 
25
- result = find_tag_in_hierarchy(value, target_key, new_path)
26
- return result if result
27
- end
28
- end
12
+ def self.find_tag_in_hierarchy(current_hash, target_key, path = [])
13
+ return nil unless current_hash.is_a?(Hash)
29
14
 
30
- current_hash.each do |key, value|
31
- next if %w[description children].include?(key) || !value.is_a?(Hash)
15
+ result = current_hash[target_key]
16
+ return result.is_a?(Hash) ? result.merge("path" => path.push(target_key).join(".")) : result if result
32
17
 
18
+ children = current_hash["children"]
19
+ if children.is_a?(Hash)
20
+ children.each do |key, value|
33
21
  new_path = path + [key]
22
+ return value.merge("path" => new_path.join(".")) if key == target_key
23
+
34
24
  result = find_tag_in_hierarchy(value, target_key, new_path)
35
25
  return result if result
36
26
  end
37
-
38
- nil
39
27
  end
40
28
 
41
- def self.create_tags
42
- create_tag_hierarchy(tags)
29
+ current_hash.each do |key, value|
30
+ next if %w[description children].include?(key) || !value.is_a?(Hash)
31
+
32
+ new_path = path + [key]
33
+ result = find_tag_in_hierarchy(value, target_key, new_path)
34
+ return result if result
43
35
  end
44
36
 
45
- def self.create_tag_hierarchy(tag_hash, parent_tag = nil)
46
- tag_hash.each do |name, data|
47
- next if %w[description children].include?(name)
37
+ nil
38
+ end
48
39
 
49
- tag = HaystackTag.find_or_create_by(name: name.to_s)
50
- tag.update(description: data["description"], parent_tag_id: parent_tag&.id, haystack_marker: data["marker"])
40
+ def self.create_tags
41
+ create_tag_hierarchy(tags)
42
+ end
51
43
 
52
- Rails.logger.info("Created tag: #{tag.name}, Parent: #{parent_tag&.name}")
44
+ def self.create_tag_hierarchy(tag_hash, parent_tag = nil)
45
+ tag_hash.each do |name, data|
46
+ next if %w[description children].include?(name)
53
47
 
54
- create_tag_hierarchy(data["children"], tag) if data["children"]
55
- end
56
- end
48
+ tag = HaystackTag.find_or_create_by(name: name.to_s)
49
+ tag.update(description: data["description"], parent_tag_id: parent_tag&.id, haystack_marker: data["marker"])
57
50
 
58
- def self.find_or_create_tag(name)
59
- tag_data = find_tag(name)
60
- return nil if tag_data.nil?
51
+ Rails.logger.info("Created tag: #{tag.name}, Parent: #{parent_tag&.name}")
61
52
 
62
- tag = HaystackTag.find_or_create_by(name: name)
63
- tag.update(description: tag_data["description"], haystack_marker: tag_data["marker"])
64
- Rails.logger.info("Tag aangemaakt of gevonden: #{tag.name}")
65
- tag
53
+ create_tag_hierarchy(data["children"], tag) if data["children"]
66
54
  end
67
55
  end
56
+
57
+ def self.find_or_create_tag(name)
58
+ tag_data = find_tag(name)
59
+ return nil if tag_data.nil?
60
+
61
+ tag = HaystackTag.find_or_create_by(name: name)
62
+ tag.update(description: tag_data["description"], haystack_marker: tag_data["marker"])
63
+ Rails.logger.info("Tag aangemaakt of gevonden: #{tag.name}")
64
+ tag
65
+ end
68
66
  end
@@ -1,69 +1,63 @@
1
- module NeedleInAHaystack
2
- class HaystackTag < ApplicationRecord
3
- self.table_name = "haystack_tags"
1
+ class HaystackTag < ApplicationRecord
2
+ belongs_to :parent_tag, class_name: "NeedleInAHaystack::HaystackTag", optional: true
3
+ has_many :children, class_name: "NeedleInAHaystack::HaystackTag", foreign_key: "parent_tag_id", dependent: :destroy, inverse_of: :parent_tag
4
+ has_many :haystack_taggings, dependent: :destroy
5
+ has_many :taggables, through: :haystack_taggings
4
6
 
5
- belongs_to :parent_tag, class_name: "NeedleInAHaystack::HaystackTag", optional: true
6
- has_many :children, class_name: "NeedleInAHaystack::HaystackTag", foreign_key: "parent_tag_id", dependent: :destroy, inverse_of: :parent_tag
7
- has_many :haystack_taggings, dependent: :destroy
8
- has_many :taggables, through: :haystack_taggings
9
-
10
- if NeedleInAHaystack.respond_to?(:configuration) && NeedleInAHaystack.configuration.taggable_models
11
- NeedleInAHaystack.configuration.taggable_models.each do |model|
12
- has_many "taggable_#{model.name.underscore.pluralize}".to_sym, through: :haystack_taggings, source: :taggable, source_type: model.name
13
- end
7
+ if NeedleInAHaystack.respond_to?(:configuration) && NeedleInAHaystack.configuration&.taggable_models
8
+ NeedleInAHaystack.configuration.taggable_models.each do |model|
9
+ has_many "taggable_#{model.name.underscore.pluralize}".to_sym, through: :haystack_taggings, source: :taggable, source_type: model.name
14
10
  end
11
+ end
15
12
 
16
- validates :name, presence: true, uniqueness: true
17
- validates :description, presence: true
18
- validate :prevent_circular_reference
19
-
20
- def ancestors
21
- ancestors = []
22
- current = self
23
- while current.parent_tag
24
- ancestors << current.parent_tag
25
- current = current.parent_tag
26
- end
27
- ancestors
28
- end
13
+ validates :name, presence: true
14
+ validates :description, presence: true
15
+ validate :prevent_circular_reference
29
16
 
30
- def self.find_by_path(path)
31
- keys = path.split(".")
32
- current = nil
33
- keys.each do |key|
34
- current = current ? current.child_tags.find_by(name: key) : find_by(name: key)
35
- return nil unless current
36
- end
37
- current
17
+ def ancestors
18
+ ancestors = []
19
+ current_tag = self
20
+ while current_tag.parent_tag
21
+ ancestors << current_tag.parent_tag
22
+ current_tag = current_tag.parent_tag
38
23
  end
24
+ ancestors
25
+ end
39
26
 
40
- def descendants
41
- children = child_tags
42
- children + children.flat_map(&:descendants)
27
+ def self.find_by_path(path)
28
+ keys = path.split(".")
29
+ current = nil
30
+ keys.each do |key|
31
+ current = current ? current.child_tags.find_by(name: key) : find_by(name: key)
32
+ return nil unless current
43
33
  end
34
+ current
35
+ end
44
36
 
45
- def siblings
46
- parent_tag ? parent_tag.child_tags.where.not(id: id) : self.class.where(parent_tag_id: nil).where.not(id: id)
47
- end
37
+ def descendants
38
+ children = child_tags
39
+ children + children.flat_map(&:descendants)
40
+ end
48
41
 
49
- def root?
50
- parent_tag.nil?
51
- end
42
+ def siblings
43
+ parent_tag ? parent_tag.child_tags.where.not(id: id) : self.class.where(parent_tag_id: nil).where.not(id: id)
44
+ end
52
45
 
53
- def leaf?
54
- child_tags.empty?
55
- end
46
+ def root?
47
+ parent_tag.nil?
48
+ end
56
49
 
57
- def depth
58
- ancestors.size
59
- end
50
+ def leaf?
51
+ child_tags.empty?
52
+ end
60
53
 
61
- private
54
+ def depth
55
+ ancestors.size
56
+ end
62
57
 
63
- def prevent_circular_reference
64
- return unless parent_tag == self || ancestors.include?(self)
58
+ def prevent_circular_reference
59
+ return unless parent_tag == self || ancestors.include?(self)
65
60
 
66
- errors.add(:parent_tag, "kan geen circulaire referentie bevatten")
67
- end
61
+ errors.add(:parent_tag, "kan geen circulaire referentie bevatten")
68
62
  end
69
63
  end
@@ -1,8 +1,4 @@
1
- module NeedleInAHaystack
2
- class HaystackTagging < ApplicationRecord
3
- self.table_name = "haystack_taggings"
4
-
5
- belongs_to :haystack_tag
6
- belongs_to :taggable, polymorphic: true
7
- end
1
+ class HaystackTagging < ApplicationRecord
2
+ belongs_to :haystack_tag
3
+ belongs_to :taggable, polymorphic: true
8
4
  end
@@ -1,3 +1 @@
1
- module NeedleInAHaystack
2
- VERSION = "1.0.0".freeze
3
- end
1
+ VERSION = "1.0.1".freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: needle_in_a_haystack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frans Verberne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-27 00:00:00.000000000 Z
11
+ date: 2024-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcrypt_pbkdf
@@ -270,14 +270,8 @@ extensions: []
270
270
  extra_rdoc_files: []
271
271
  files:
272
272
  - Rakefile
273
- - config/initializers/application_controller_renderer.rb
274
- - config/initializers/backtrace_silencers.rb
275
273
  - config/initializers/config.rb
276
- - config/initializers/cors.rb
277
274
  - config/initializers/filter_parameter_logging.rb
278
- - config/initializers/inflections.rb
279
- - config/initializers/lograge.rb
280
- - config/initializers/mime_types.rb
281
275
  - config/initializers/redis.rb
282
276
  - config/initializers/wrap_parameters.rb
283
277
  - config/locales/en.yml
@@ -1,8 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # ActiveSupport::Reloader.to_prepare do
4
- # ApplicationController.renderer.defaults.merge!(
5
- # http_host: 'example.org',
6
- # https: false
7
- # )
8
- # end
@@ -1,7 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
- # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
-
6
- # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
- # Rails.backtrace_cleaner.remove_silencers!
@@ -1,16 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Avoid CORS issues when API is called from the frontend app.
4
- # Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests.
5
-
6
- # Read more: https://github.com/cyu/rack-cors
7
-
8
- # Rails.application.config.middleware.insert_before 0, Rack::Cors do
9
- # allow do
10
- # origins 'example.com'
11
- #
12
- # resource '*',
13
- # headers: :any,
14
- # methods: [:get, :post, :put, :patch, :delete, :options, :head]
15
- # end
16
- # end
@@ -1,16 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Add new inflection rules using the following format. Inflections
4
- # are locale specific, and you may define rules for as many different
5
- # locales as you wish. All of these examples are active by default:
6
- # ActiveSupport::Inflector.inflections(:en) do |inflect|
7
- # inflect.plural /^(ox)$/i, '\1en'
8
- # inflect.singular /^(ox)en/i, '\1'
9
- # inflect.irregular 'person', 'people'
10
- # inflect.uncountable %w( fish sheep )
11
- # end
12
-
13
- # These inflection rules are supported but not enabled by default:
14
- # ActiveSupport::Inflector.inflections(:en) do |inflect|
15
- # inflect.acronym 'RESTful'
16
- # end
File without changes
@@ -1,4 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Add new mime types for use in respond_to blocks:
4
- # Mime::Type.register "text/richtext", :rtf