no_fly_list 0.7.0 → 0.7.2
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/lib/generators/no_fly_list/install_generator.rb +7 -2
- data/lib/generators/no_fly_list/models_generator.rb +6 -7
- data/lib/generators/no_fly_list/tagging_generator.rb +1 -0
- data/lib/generators/no_fly_list/transformer_generator.rb +8 -9
- data/lib/no_fly_list/default_transformer.rb +25 -0
- data/lib/no_fly_list/taggable_record/config.rb +1 -1
- data/lib/no_fly_list/taggable_record/tag_setup.rb +1 -1
- data/lib/no_fly_list/tagging_proxy.rb +15 -2
- data/lib/no_fly_list/version.rb +1 -1
- data/lib/no_fly_list.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fb7865780acd9586b0ff700686a1546a4c294f9fc3d7a71fe47f2fb7a6def0c
|
4
|
+
data.tar.gz: be5186e8116c5db42c4aa4e3536ab4343b95967f5cd05dcfb64c8f99ebb85270
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 630d2aa00cc4b2465321d1040697cff6c54124247275a0b75677d70653fe347ec1c0ad7e9c573dea060de07be1de02977f1ff6f467bfe1465299a1f764e35325
|
7
|
+
data.tar.gz: 1201844673a3893a3c760ab1fc88ed6826839d799bca6a93b17c2c3e802fa4e9df4d485bdc5511cec4c7cbf2bdcc3cba9cfd1280970d58b5eaa93492f7ece67a
|
@@ -39,14 +39,19 @@ module NoFlyList
|
|
39
39
|
|
40
40
|
def connection_abstract_class_name
|
41
41
|
# should be abstract class name
|
42
|
-
ActiveRecord::Base.descendants.find do |klass|
|
42
|
+
klass = ActiveRecord::Base.descendants.find do |klass|
|
43
43
|
klass.abstract_class? && klass.connection_db_config.name == connection_name
|
44
|
-
end
|
44
|
+
end
|
45
|
+
klass&.name || "ApplicationRecord"
|
45
46
|
end
|
46
47
|
|
47
48
|
def migration_version
|
48
49
|
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
49
50
|
end
|
51
|
+
|
52
|
+
def migration_class_name
|
53
|
+
"CreateApplicationTaggingTable"
|
54
|
+
end
|
50
55
|
end
|
51
56
|
end
|
52
57
|
end
|
@@ -36,18 +36,17 @@ module NoFlyList
|
|
36
36
|
if model_class < ActiveRecord::Base
|
37
37
|
true
|
38
38
|
else
|
39
|
-
|
40
|
-
false
|
39
|
+
raise ArgumentError, "#{class_name} is not an ActiveRecord model. Aborting generator."
|
41
40
|
end
|
42
41
|
rescue NameError
|
43
|
-
|
44
|
-
false
|
42
|
+
raise ArgumentError, "#{class_name} is not a valid constant. Aborting generator."
|
45
43
|
end
|
46
44
|
|
47
45
|
def model_abstract_class_name
|
48
|
-
model_class.ancestors.find do |
|
49
|
-
|
50
|
-
end
|
46
|
+
klass = model_class.ancestors.find do |ancestor|
|
47
|
+
ancestor.is_a?(Class) && ancestor.abstract_class?
|
48
|
+
end
|
49
|
+
klass&.name || "ApplicationRecord"
|
51
50
|
end
|
52
51
|
end
|
53
52
|
end
|
@@ -9,6 +9,7 @@ module NoFlyList
|
|
9
9
|
module Generators
|
10
10
|
class TaggingGenerator < Rails::Generators::NamedBase
|
11
11
|
include ActiveRecord::Generators::Migration
|
12
|
+
source_root File.expand_path("templates", __dir__)
|
12
13
|
|
13
14
|
class_option :database, type: :string, default: "primary",
|
14
15
|
desc: "Use different database for migration"
|
@@ -5,15 +5,14 @@ require "rails/generators"
|
|
5
5
|
require "rails/generators/active_record"
|
6
6
|
require "rails/generators/named_base"
|
7
7
|
|
8
|
-
|
9
|
-
module
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
8
|
+
module NoFlyList
|
9
|
+
module Generators
|
10
|
+
# bin/rails g no_fly_list:transformer
|
11
|
+
class TransformerGenerator < Rails::Generators::Base
|
12
|
+
source_root File.expand_path("templates", __dir__)
|
13
|
+
|
14
|
+
def create_tag_transformer_file
|
15
|
+
template "tag_transformer.rb", File.join("app/transformers", "application_tag_transformer.rb")
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NoFlyList
|
4
|
+
module DefaultTransformer
|
5
|
+
module_function
|
6
|
+
|
7
|
+
# @param [String, Array<String>] tags
|
8
|
+
def parse_tags(tags)
|
9
|
+
tags = recreate_string(tags) if tags.is_a?(Array)
|
10
|
+
tags.split(separator).map(&:strip)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Recreate a string from an array of tags
|
14
|
+
# @param [Array<String>] tags
|
15
|
+
# @return [String]
|
16
|
+
def recreate_string(tags)
|
17
|
+
tags.join(separator)
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [String]
|
21
|
+
def separator
|
22
|
+
","
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -19,7 +19,7 @@ module NoFlyList
|
|
19
19
|
taggable_class: @taggable_class.to_s,
|
20
20
|
tag_class_name: tag_class_name,
|
21
21
|
tagging_class_name: tagging_class_name,
|
22
|
-
transformer: options.fetch(:transformer, ApplicationTagTransformer).to_s,
|
22
|
+
transformer: options.fetch(:transformer, "ApplicationTagTransformer").to_s,
|
23
23
|
polymorphic: options.fetch(:polymorphic, false),
|
24
24
|
restrict_to_existing: options.fetch(:restrict_to_existing, false),
|
25
25
|
limit: options.fetch(:limit, nil),
|
@@ -41,7 +41,7 @@ module NoFlyList
|
|
41
41
|
def initialize(taggable_klass, context, options = {})
|
42
42
|
@taggable_klass = taggable_klass
|
43
43
|
@context = context
|
44
|
-
@transformer = options.fetch(:transformer, ApplicationTagTransformer)
|
44
|
+
@transformer = options.fetch(:transformer, "ApplicationTagTransformer")
|
45
45
|
@polymorphic = options.fetch(:polymorphic, false)
|
46
46
|
@restrict_to_existing = options.fetch(:restrict_to_existing, false)
|
47
47
|
@counter_cache = options.fetch(:counter_cache, false)
|
@@ -19,19 +19,32 @@ module NoFlyList
|
|
19
19
|
# @param restrict_to_existing [Boolean] Only allow existing tags
|
20
20
|
# @param limit [Integer, nil] Maximum number of tags allowed
|
21
21
|
def initialize(model, tag_model, context,
|
22
|
-
transformer: ApplicationTagTransformer,
|
22
|
+
transformer: "ApplicationTagTransformer",
|
23
23
|
restrict_to_existing: false,
|
24
24
|
limit: nil)
|
25
25
|
@model = model
|
26
26
|
@tag_model = tag_model
|
27
27
|
@context = context
|
28
|
-
@transformer = transformer
|
28
|
+
@transformer = resolve_transformer(transformer)
|
29
29
|
@restrict_to_existing = restrict_to_existing
|
30
30
|
@limit = limit
|
31
31
|
@pending_changes = nil # Use nil to indicate no changes yet
|
32
32
|
@clear_operation = false
|
33
33
|
end
|
34
34
|
|
35
|
+
def resolve_transformer(trans)
|
36
|
+
const = trans
|
37
|
+
const = const.constantize if const.is_a?(String)
|
38
|
+
unless const.respond_to?(:parse_tags) && const.respond_to?(:recreate_string)
|
39
|
+
warn "NoFlyList: transformer #{trans.inspect} is invalid. Falling back to DefaultTransformer"
|
40
|
+
const = NoFlyList::DefaultTransformer
|
41
|
+
end
|
42
|
+
const
|
43
|
+
rescue NameError
|
44
|
+
warn "NoFlyList: transformer #{trans.inspect} not found. Falling back to DefaultTransformer"
|
45
|
+
NoFlyList::DefaultTransformer
|
46
|
+
end
|
47
|
+
|
35
48
|
# Determines if tags have changed from database state
|
36
49
|
# @return [Boolean] True if pending changes differ from database
|
37
50
|
# @api private
|
data/lib/no_fly_list/version.rb
CHANGED
data/lib/no_fly_list.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: no_fly_list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abdelkader Boudih
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activerecord
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/no_fly_list.rb
|
45
45
|
- lib/no_fly_list/application_tag.rb
|
46
46
|
- lib/no_fly_list/application_tagging.rb
|
47
|
+
- lib/no_fly_list/default_transformer.rb
|
47
48
|
- lib/no_fly_list/railtie.rb
|
48
49
|
- lib/no_fly_list/railties/tasks.rake
|
49
50
|
- lib/no_fly_list/tag_record.rb
|
@@ -80,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
81
|
- !ruby/object:Gem::Version
|
81
82
|
version: '0'
|
82
83
|
requirements: []
|
83
|
-
rubygems_version: 3.6.
|
84
|
+
rubygems_version: 3.6.9
|
84
85
|
specification_version: 4
|
85
86
|
summary: Tagging system for ActiveRecord models
|
86
87
|
test_files: []
|