needle_in_a_haystack 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e365c25451da6fb9d1ab929ece76bfea7e5753544818eb5e8650642ed5d10b6
4
- data.tar.gz: d926c7e2ad775dc46d5c38a48b352dfd1ffd369196f3c3aab7aabe40c915d142
3
+ metadata.gz: 47f3b28b275f615fb0cbfabb20d76cf70ef0adbf63875c6a2aae2c0b19e27e39
4
+ data.tar.gz: 9807a09a01410b9f299a268c828880df1e5fbbcf9cf6c7c16769b29da1fbb366
5
5
  SHA512:
6
- metadata.gz: 6cfd26955113913e7ef3f5f24435485f45d83dac53f54b92d10cc7199f6c48358c1aa8072cdd911bc4e700acbd184ccdab808a987775addd438654e88218c363
7
- data.tar.gz: 20f66d4f920165380f95fd2f981207131034f96a14b86d6019e62f9c77cc83127669bae046ef02c599a7dd210c716d9a6510582d4f6157fb5b34317e0bd40796
6
+ metadata.gz: a940a2d003014274c368e4daf453f1ab35711057eaec59a465d61ff3b319395806486fa95d3d19c7e4071f6c2e0e49cc6514079ce14b7921df722345ba9c651b
7
+ data.tar.gz: 29b755d8403392d44cb9561d2a119b1c5b61bb3ebbb269ea4b7f78c241280e396c34c52bb4a1d895e5474d9cf90bae4a74945214f31803724d4734b318a28239
@@ -0,0 +1,11 @@
1
+ class BaseTag < ApplicationRecord
2
+ self.abstract_class = true
3
+
4
+ def name
5
+ raise NotImplementedError, "Subclasses must implement a name-method"
6
+ end
7
+
8
+ def description
9
+ raise NotImplementedError, "Subclasses must implement a description-method"
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class BaseTagging < ApplicationRecord
2
+ self.abstract_class = true
3
+
4
+ def tag
5
+ raise NotImplementedError, "Subclasses must implement a tag-method"
6
+ end
7
+
8
+ def taggable
9
+ raise NotImplementedError, "Subclasses must implement a taggable-method"
10
+ end
11
+ end
@@ -1,4 +1,3 @@
1
- # app/models/concerns/taggable.rb
2
1
  module Taggable
3
2
  extend ActiveSupport::Concern
4
3
 
@@ -1,25 +1,27 @@
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
1
+ class HaystackTag < BaseTag
2
+ belongs_to :parent_tag, class_name: "HaystackTag", optional: true
3
+ has_many :children, class_name: "HaystackTag", foreign_key: "parent_tag_id", dependent: :destroy, inverse_of: :parent_tag
4
4
  has_many :haystack_taggings, dependent: :destroy
5
5
  has_many :taggables, through: :haystack_taggings
6
6
 
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
10
- end
11
- end
12
-
13
- validates :name, presence: true
7
+ validates :name, presence: true, uniqueness: true
14
8
  validates :description, presence: true
15
9
  validate :prevent_circular_reference
16
10
 
11
+ def name
12
+ self[:name]
13
+ end
14
+
15
+ def description
16
+ self[:description]
17
+ end
18
+
17
19
  def ancestors
18
20
  ancestors = []
19
- current_tag = self
20
- while current_tag.parent_tag
21
- ancestors << current_tag.parent_tag
22
- current_tag = current_tag.parent_tag
21
+ current = self
22
+ while current.parent_tag
23
+ ancestors << current.parent_tag
24
+ current = current.parent_tag
23
25
  end
24
26
  ancestors
25
27
  end
@@ -0,0 +1,4 @@
1
+ class HaystackTagging < BaseTagging
2
+ belongs_to :haystack_tag, class_name: "HaystackTag"
3
+ belongs_to :taggable, polymorphic: true
4
+ end
@@ -1 +1 @@
1
- VERSION = "1.0.1".freeze
1
+ VERSION = "1.0.3".freeze
@@ -2,8 +2,12 @@ require "needle_in_a_haystack/version"
2
2
  require "needle_in_a_haystack/engine"
3
3
  require "needle_in_a_haystack/application_record"
4
4
  require "needle_in_a_haystack/configuration"
5
- require "needle_in_a_haystack/haystack_tag"
6
- require "needle_in_a_haystack/haystack_tagging"
5
+ require "needle_in_a_haystack/concerns/base_tagging"
6
+ require "needle_in_a_haystack/concerns/base_tag"
7
+
8
+ require "needle_in_a_haystack/models/haystack_ontology"
9
+ require "needle_in_a_haystack/models/haystack_tag"
10
+ require "needle_in_a_haystack/models/haystack_tagging"
7
11
 
8
12
  module NeedleInAHaystack
9
13
  class << self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: needle_in_a_haystack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frans Verberne
@@ -275,14 +275,16 @@ files:
275
275
  - config/initializers/redis.rb
276
276
  - config/initializers/wrap_parameters.rb
277
277
  - config/locales/en.yml
278
- - lib/concerns/taggable.rb
279
278
  - lib/needle_in_a_haystack.rb
280
279
  - lib/needle_in_a_haystack/application_record.rb
280
+ - lib/needle_in_a_haystack/concerns/base_tag.rb
281
+ - lib/needle_in_a_haystack/concerns/base_tagging.rb
282
+ - lib/needle_in_a_haystack/concerns/taggable.rb
281
283
  - lib/needle_in_a_haystack/configuration.rb
282
284
  - lib/needle_in_a_haystack/engine.rb
283
- - lib/needle_in_a_haystack/haystack_ontology.rb
284
- - lib/needle_in_a_haystack/haystack_tag.rb
285
- - lib/needle_in_a_haystack/haystack_tagging.rb
285
+ - lib/needle_in_a_haystack/models/haystack_ontology.rb
286
+ - lib/needle_in_a_haystack/models/haystack_tag.rb
287
+ - lib/needle_in_a_haystack/models/haystack_tagging.rb
286
288
  - lib/needle_in_a_haystack/version.rb
287
289
  - lib/tasks/location_create.rake
288
290
  - spec/factories/haystack_tags.rb
@@ -1,4 +0,0 @@
1
- class HaystackTagging < ApplicationRecord
2
- belongs_to :haystack_tag
3
- belongs_to :taggable, polymorphic: true
4
- end