yiffspace 0.1.8 → 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/CHANGELOG.md +4 -10
- data/README.md +18 -1
- data/Rakefile +6 -7
- data/lib/yiffspace/version.rb +1 -1
- data/lib/yiffspace.rb +26 -28
- metadata +104 -148
- data/app/assets/config/yiffspace_manifest.js +0 -1
- data/app/assets/stylesheets/yiffspace/application.css +0 -30
- data/app/controllers/yiff_space/application_controller.rb +0 -6
- data/app/helpers/yiff_space/application_helper.rb +0 -6
- data/app/models/yiff_space/application_record.rb +0 -7
- data/app/views/layouts/yiff_space/application.html.erb +0 -17
- data/app/views/yiff_space/error.html.erb +0 -3
- data/lib/generators/yiffspace/fixer/USAGE +0 -40
- data/lib/generators/yiffspace/fixer/fixer_generator.rb +0 -86
- data/lib/generators/yiffspace/fixer/templates/fixer.rb +0 -4
- data/lib/generators/yiffspace/install/fixes_generator.rb +0 -21
- data/lib/generators/yiffspace/install/templates/create_fixes.rb.erb +0 -18
- data/lib/tasks/fixes.rake +0 -66
- data/lib/yiffspace/concerns/active_record_extensions.rb +0 -45
- data/lib/yiffspace/concerns/api_methods.rb +0 -101
- data/lib/yiffspace/concerns/attribute_matchers.rb +0 -100
- data/lib/yiffspace/concerns/attribute_methods.rb +0 -39
- data/lib/yiffspace/concerns/concurrency_methods.rb +0 -20
- data/lib/yiffspace/concerns/conditional_includes.rb +0 -43
- data/lib/yiffspace/concerns/current_methods.rb +0 -60
- data/lib/yiffspace/concerns/has_bit_flags.rb +0 -59
- data/lib/yiffspace/concerns/user_class_methods.rb +0 -32
- data/lib/yiffspace/concerns/user_methods.rb +0 -77
- data/lib/yiffspace/concerns/user_name_methods.rb +0 -53
- data/lib/yiffspace/concerns/user_resolvable_methods.rb +0 -38
- data/lib/yiffspace/config_builder.rb +0 -192
- data/lib/yiffspace/configuration/fixer_templates.rb +0 -87
- data/lib/yiffspace/configuration/images.rb +0 -22
- data/lib/yiffspace/configuration.rb +0 -130
- data/lib/yiffspace/core_ext/active_record/all.rb +0 -8
- data/lib/yiffspace/core_ext/active_record/cross_join_lateral.rb +0 -7
- data/lib/yiffspace/core_ext/active_record/cross_unnest.rb +0 -7
- data/lib/yiffspace/core_ext/active_record/left_join_lateral.rb +0 -7
- data/lib/yiffspace/core_ext/active_record/left_unnest.rb +0 -7
- data/lib/yiffspace/core_ext/active_record/unnest.rb +0 -8
- data/lib/yiffspace/core_ext/active_record/where_chain.rb +0 -6
- data/lib/yiffspace/core_ext/all.rb +0 -8
- data/lib/yiffspace/core_ext/arel/all.rb +0 -4
- data/lib/yiffspace/core_ext/arel/cross_join_lateral.rb +0 -21
- data/lib/yiffspace/core_ext/arel/left_join_lateral.rb +0 -21
- data/lib/yiffspace/core_ext/enumerable/all.rb +0 -3
- data/lib/yiffspace/core_ext/enumerable/parallel.rb +0 -7
- data/lib/yiffspace/core_ext/hash/all.rb +0 -3
- data/lib/yiffspace/core_ext/hash/to_open_hash.rb +0 -7
- data/lib/yiffspace/core_ext/object/all.rb +0 -4
- data/lib/yiffspace/core_ext/object/to_b.rb +0 -7
- data/lib/yiffspace/core_ext/object/truthy_falsy.rb +0 -7
- data/lib/yiffspace/core_ext/string/all.rb +0 -3
- data/lib/yiffspace/core_ext/string/sql.rb +0 -7
- data/lib/yiffspace/engine.rb +0 -23
- data/lib/yiffspace/extensions/active_record/cross_join_lateral.rb +0 -23
- data/lib/yiffspace/extensions/active_record/cross_unnest.rb +0 -15
- data/lib/yiffspace/extensions/active_record/left_join_lateral.rb +0 -24
- data/lib/yiffspace/extensions/active_record/left_unnest.rb +0 -15
- data/lib/yiffspace/extensions/active_record/unnest.rb +0 -20
- data/lib/yiffspace/extensions/active_record/where_chain.rb +0 -107
- data/lib/yiffspace/extensions/arel/nodes/cross_join_lateral.rb +0 -17
- data/lib/yiffspace/extensions/arel/nodes/left_join_lateral.rb +0 -17
- data/lib/yiffspace/extensions/arel/table/cross_join_lateral.rb +0 -15
- data/lib/yiffspace/extensions/arel/table/left_join_lateral.rb +0 -15
- data/lib/yiffspace/extensions/arel/visitors/postgresql/cross_join_lateral.rb +0 -19
- data/lib/yiffspace/extensions/arel/visitors/postgresql/left_join_lateral.rb +0 -23
- data/lib/yiffspace/extensions/enumerable/parallel.rb +0 -39
- data/lib/yiffspace/extensions/hash/to_open_hash.rb +0 -15
- data/lib/yiffspace/extensions/object/to_b.rb +0 -22
- data/lib/yiffspace/extensions/object/truthy_falsy.rb +0 -35
- data/lib/yiffspace/extensions/string/sql.rb +0 -21
- data/lib/yiffspace/fix_tracker.rb +0 -95
- data/lib/yiffspace/fixer_template.rb +0 -44
- data/lib/yiffspace/images/avatar/base.rb +0 -41
- data/lib/yiffspace/images/avatar/discord.rb +0 -37
- data/lib/yiffspace/images/avatar/gravatar.rb +0 -21
- data/lib/yiffspace/images/avatar.rb +0 -33
- data/lib/yiffspace/images/banner/base.rb +0 -41
- data/lib/yiffspace/images/banner/discord.rb +0 -37
- data/lib/yiffspace/images/banner.rb +0 -33
- data/lib/yiffspace/images.rb +0 -6
- data/lib/yiffspace/include/active_record_extensions.rb +0 -5
- data/lib/yiffspace/include/all.rb +0 -31
- data/lib/yiffspace/include/api_methods.rb +0 -5
- data/lib/yiffspace/include/attribute_matchers.rb +0 -5
- data/lib/yiffspace/include/attribute_methods.rb +0 -5
- data/lib/yiffspace/include/cache.rb +0 -5
- data/lib/yiffspace/include/concurrency_methods.rb +0 -5
- data/lib/yiffspace/include/conditional_includes.rb +0 -5
- data/lib/yiffspace/include/current.rb +0 -5
- data/lib/yiffspace/include/current_methods.rb +0 -5
- data/lib/yiffspace/include/duration_parser.rb +0 -5
- data/lib/yiffspace/include/has_bit_flags.rb +0 -5
- data/lib/yiffspace/include/helpers.rb +0 -5
- data/lib/yiffspace/include/open_hash.rb +0 -5
- data/lib/yiffspace/include/parameter_builder.rb +0 -5
- data/lib/yiffspace/include/parse_value.rb +0 -5
- data/lib/yiffspace/include/query_builder.rb +0 -5
- data/lib/yiffspace/include/query_dsl.rb +0 -5
- data/lib/yiffspace/include/query_helper.rb +0 -5
- data/lib/yiffspace/include/routes.rb +0 -5
- data/lib/yiffspace/include/table_builder.rb +0 -5
- data/lib/yiffspace/include/trace_logger.rb +0 -5
- data/lib/yiffspace/include/u2id.rb +0 -5
- data/lib/yiffspace/include/user_attribute.rb +0 -5
- data/lib/yiffspace/include/user_class_methods.rb +0 -5
- data/lib/yiffspace/include/user_like.rb +0 -5
- data/lib/yiffspace/include/user_methods.rb +0 -5
- data/lib/yiffspace/include/user_name_methods.rb +0 -5
- data/lib/yiffspace/include/user_resolvable.rb +0 -5
- data/lib/yiffspace/include/user_resolvable_methods.rb +0 -5
- data/lib/yiffspace/search/query_builder.rb +0 -83
- data/lib/yiffspace/search/query_dsl.rb +0 -119
- data/lib/yiffspace/search/query_helper.rb +0 -49
- data/lib/yiffspace/serializers/avatar_serializer.rb +0 -21
- data/lib/yiffspace/serializers/banner_serializer.rb +0 -21
- data/lib/yiffspace/serializers/user_resolvable_serializer.rb +0 -21
- data/lib/yiffspace/utils/cache.rb +0 -40
- data/lib/yiffspace/utils/current.rb +0 -43
- data/lib/yiffspace/utils/duration_parser.rb +0 -24
- data/lib/yiffspace/utils/helpers.rb +0 -25
- data/lib/yiffspace/utils/open_hash.rb +0 -63
- data/lib/yiffspace/utils/parameter_builder.rb +0 -121
- data/lib/yiffspace/utils/parse_value.rb +0 -174
- data/lib/yiffspace/utils/routes.rb +0 -28
- data/lib/yiffspace/utils/set_env_constraint.rb +0 -18
- data/lib/yiffspace/utils/table_builder.rb +0 -169
- data/lib/yiffspace/utils/trace_logger.rb +0 -91
- data/lib/yiffspace/utils/user_attribute.rb +0 -272
- data/lib/yiffspace/utils/user_like.rb +0 -8
- data/lib/yiffspace/utils/user_resolvable.rb +0 -61
- data/lib/yiffspace/utils/user_to_id.rb +0 -11
- data/lib/yiffspace/utils.rb +0 -6
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module YiffSpace
|
|
4
|
-
module Concerns
|
|
5
|
-
# methods to include into the user class for use with the like/resolvable classes
|
|
6
|
-
module UserClassMethods
|
|
7
|
-
extend(ActiveSupport::Concern)
|
|
8
|
-
|
|
9
|
-
def resolvable(ip_addr = nil)
|
|
10
|
-
YiffSpace.config.user_resolvable_class.new(self, ip_addr || "127.0.0.1")
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def resolve
|
|
14
|
-
self
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def ==(other)
|
|
18
|
-
return super if other.is_a?(YiffSpace.config.user_class)
|
|
19
|
-
|
|
20
|
-
other.is_a?(YiffSpace.config.user_resolvable_class) && super(other.user)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def ===(other)
|
|
24
|
-
other == YiffSpace.config.user_like_class || super
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def is_a?(other)
|
|
28
|
-
other == YiffSpace.config.user_like_class || super
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module YiffSpace
|
|
4
|
-
module Concerns
|
|
5
|
-
module UserMethods
|
|
6
|
-
extend(ActiveSupport::Concern)
|
|
7
|
-
|
|
8
|
-
module ClassMethods
|
|
9
|
-
def belongs_to_user(*, **)
|
|
10
|
-
UserAttribute.new(self, *, **, db: true)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def resolvable(*, **)
|
|
14
|
-
UserAttribute.new(self, *, **, db: false)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def with_user(instance, method, user, *args, **, &)
|
|
18
|
-
default = { new: :creator, create: :creator, create!: :creator, update: :updater, update!: :updater, destroy: :destroyer, destroy!: :destroyer }.fetch(method)
|
|
19
|
-
attrs = args.grep(Symbol)
|
|
20
|
-
attrs = [default] if default && attrs.empty?
|
|
21
|
-
other = args - attrs
|
|
22
|
-
hashes = other.grep(Hash)
|
|
23
|
-
params = other.grep(ActionController::Parameters)
|
|
24
|
-
other -= hashes + params
|
|
25
|
-
other.compact_blank!
|
|
26
|
-
options = [attrs.index_with(user), *hashes, *params.map(&:to_hash)].inject(:merge)
|
|
27
|
-
if %i[destroy destroy!].include?(method)
|
|
28
|
-
options.each do |attr, value|
|
|
29
|
-
instance.send("#{attr}=", value)
|
|
30
|
-
end
|
|
31
|
-
instance.send(method)
|
|
32
|
-
else
|
|
33
|
-
instance.send(method, *other, **options, **, &)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def new_with(...)
|
|
38
|
-
with_user(self, :new, ...)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def create_with(...)
|
|
42
|
-
new_with(...).tap(&:save)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def create_with!(...)
|
|
46
|
-
new_with(...).tap(&:save!)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def update_with(...)
|
|
51
|
-
self.class.with_user(self, :update, ...)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def update_with!(...)
|
|
55
|
-
self.class.with_user(self, :update!, ...)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def destroy_with(...)
|
|
59
|
-
self.class.with_user(self, :destroy, ...)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def destroy_with!(...)
|
|
63
|
-
self.class.with_user(self, :destroy!, ...)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
private
|
|
67
|
-
|
|
68
|
-
def put(attr, value, overwrite: false)
|
|
69
|
-
if respond_to?(:"#{attr}_id")
|
|
70
|
-
send(:"#{attr}=", value) if overwrite || send(:"#{attr}_id").blank?
|
|
71
|
-
elsif respond_to?(attr)
|
|
72
|
-
send(:"#{attr}=", value) if overwrite || send(attr).blank?
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module YiffSpace
|
|
4
|
-
module Concerns
|
|
5
|
-
module UserNameMethods
|
|
6
|
-
extend(ActiveSupport::Concern)
|
|
7
|
-
|
|
8
|
-
module ClassMethods
|
|
9
|
-
def name_to_id(name)
|
|
10
|
-
normalized_name = normalize_name(name)
|
|
11
|
-
Cache.fetch("uni:#{normalized_name}", expires_in: 4.hours) do
|
|
12
|
-
::User.where("lower(name) = ?", normalized_name).pick(:id)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# @param arguments [Array<String, Array<String>>] a list of names
|
|
17
|
-
# @return [Hash{String => Integer, nil}] a hash of normalized names to user IDs
|
|
18
|
-
def bulk_name_to_id(*arguments)
|
|
19
|
-
names = arguments.flatten.map { |n| normalize_name(n) }
|
|
20
|
-
results = names.index_with { |name| Utils::Cache.fetch("uni:#{name}") }.compact_blank
|
|
21
|
-
missing = names - results.keys
|
|
22
|
-
fetched = ::User.where("lower(name) IN (?)", missing).select(:id, :name).to_h { |u| [normalize_name(u.name), u.id] }
|
|
23
|
-
not_found = (missing - fetched.keys).index_with { nil }
|
|
24
|
-
fetched.each { |name, id| Utils::Cache.write("uni:#{name}", id, expires_in: 4.hours) }
|
|
25
|
-
{ **results, **fetched, **not_found }
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def name_or_id_to_id(name)
|
|
29
|
-
return name[1..].to_i if name =~ /\A!\d+\z/
|
|
30
|
-
|
|
31
|
-
::User.name_to_id(name)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def name_or_id_to_id_forced(name)
|
|
35
|
-
return name.to_i if name =~ /\A\d+\z/
|
|
36
|
-
|
|
37
|
-
::User.name_to_id(name)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def id_to_name(user_id)
|
|
41
|
-
RequestStore[:id_name_cache] ||= {}
|
|
42
|
-
return RequestStore[:id_name_cache][user_id] if RequestStore[:id_name_cache].key?(user_id)
|
|
43
|
-
|
|
44
|
-
name = Cache.fetch("uin:#{user_id}", expires_in: 4.hours) do
|
|
45
|
-
::User.where(id: user_id).pick(:name) || YiffSpace.config.anonymous_user_name.call
|
|
46
|
-
end
|
|
47
|
-
RequestStore[:id_name_cache][user_id] = name
|
|
48
|
-
name
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module YiffSpace
|
|
4
|
-
module Concerns
|
|
5
|
-
module UserResolvableMethods
|
|
6
|
-
def resolvable(ip_addr = nil)
|
|
7
|
-
attr = YiffSpace.config.last_ip_addr_attribute
|
|
8
|
-
UserResolvable.new(self, ip_addr || (attr && respond_to?(attr) ? send(attr) : nil) || YiffSpace.config.default_ip_address)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def resolve
|
|
12
|
-
self
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def is?(user_or_id)
|
|
16
|
-
id == u2id(user_or_id)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def ==(other)
|
|
20
|
-
return super if other.is_a?(YiffSpace.config.user_class)
|
|
21
|
-
|
|
22
|
-
other.is_a?(YiffSpace.config.user_resolvable_class) && super(other.user)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def ===(other)
|
|
26
|
-
other == YiffSpace.config.user_like_class || super
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def is_a?(other)
|
|
30
|
-
other == YiffSpace.config.user_like_class || super
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
include(YiffSpace::Utils::UserToId)
|
|
34
|
-
|
|
35
|
-
private(:u2id)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require("active_support/hash_with_indifferent_access")
|
|
4
|
-
|
|
5
|
-
# This is intended to only be used externally, it is NOT reusable, do not use it within this project, or attempt to use it multiple times!!
|
|
6
|
-
module YiffSpace
|
|
7
|
-
class ConfigBuilder
|
|
8
|
-
include(Singleton)
|
|
9
|
-
|
|
10
|
-
cattr_accessor(:list, default: [])
|
|
11
|
-
cattr_accessor(:env_set, default: ActiveSupport::HashWithIndifferentAccess.new)
|
|
12
|
-
cattr_accessor(:unset, default: [])
|
|
13
|
-
cattr_accessor(:required, default: [])
|
|
14
|
-
cattr_accessor(:reviver_map, default: ActiveSupport::HashWithIndifferentAccess.new)
|
|
15
|
-
cattr_accessor(:subconfigs, default: ActiveSupport::HashWithIndifferentAccess.new { |h, k| h[k] = {} })
|
|
16
|
-
cattr_accessor(:env_name, default: "CONFIG")
|
|
17
|
-
|
|
18
|
-
def self.config(name, type = :string, env: true, required: false, blank: false, &block)
|
|
19
|
-
name = name.to_sym
|
|
20
|
-
remove_config(name) if list.include?(name)
|
|
21
|
-
list << name
|
|
22
|
-
self.required << name if required
|
|
23
|
-
if block.nil?
|
|
24
|
-
unset << name
|
|
25
|
-
block = -> { raise(NotImplementedError, "Config option #{name} is not set") }
|
|
26
|
-
end
|
|
27
|
-
define_method(name) do |*args|
|
|
28
|
-
env_or_value(name, args, blank: blank, &block)
|
|
29
|
-
end
|
|
30
|
-
if type == :boolean
|
|
31
|
-
define_method("#{name}?") do |*args|
|
|
32
|
-
public_send(name, *args)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
reviver(name, type) if type && type != :string
|
|
36
|
-
env_set[name] = env
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def self.remove_config(name, reviver: false)
|
|
40
|
-
name = name.to_sym
|
|
41
|
-
list.delete(name)
|
|
42
|
-
required.delete(name)
|
|
43
|
-
unset.delete(name)
|
|
44
|
-
reviver_map.delete(name) if reviver
|
|
45
|
-
env_set.delete(name)
|
|
46
|
-
remove_method(name)
|
|
47
|
-
remove_method("#{name}?") if method_defined?("#{name}?")
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def env_or_value(name, args, blank: false, &)
|
|
51
|
-
value = env(name)
|
|
52
|
-
value = nil if !value.nil? && value.blank? && !blank
|
|
53
|
-
if value.nil?
|
|
54
|
-
instance_exec(*args, &)
|
|
55
|
-
else
|
|
56
|
-
reviver = reviver_map.fetch(name, proc(&:itself))
|
|
57
|
-
instance_exec(value, *args, &reviver)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def env(name)
|
|
62
|
-
ENV.fetch("#{self.class.env_name}_#{name.to_s.upcase}", nil)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def self.reviver(name, type = nil, &block)
|
|
66
|
-
name = name.to_sym
|
|
67
|
-
if block
|
|
68
|
-
reviver_map[name] = block
|
|
69
|
-
return
|
|
70
|
-
end
|
|
71
|
-
method = case type
|
|
72
|
-
when :boolean
|
|
73
|
-
->(v) { !v.match?(/\A(false|f|no|n|off|0)\z/i) }
|
|
74
|
-
when :integer, :number
|
|
75
|
-
->(v) { v.to_i }
|
|
76
|
-
when :symbol
|
|
77
|
-
->(v) { v.to_sym }
|
|
78
|
-
when :array
|
|
79
|
-
->(v) { v.split(/\s*,\s*/) }
|
|
80
|
-
else
|
|
81
|
-
raise(ArgumentError, "not sure how to revive #{type} for #{method}")
|
|
82
|
-
end
|
|
83
|
-
reviver_map[name] = method
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def self.subconfig(prefix, parent: [], &block)
|
|
87
|
-
raise(ArgumentError, "block required") unless block
|
|
88
|
-
|
|
89
|
-
prefix = prefix.to_sym
|
|
90
|
-
path = parent + [prefix]
|
|
91
|
-
|
|
92
|
-
node = subconfigs
|
|
93
|
-
path.each do |p|
|
|
94
|
-
node[p] ||= {}
|
|
95
|
-
node = node[p]
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
define_method(prefix) { SubconfigProxy.new(self, path) } unless method_defined?(prefix)
|
|
99
|
-
|
|
100
|
-
collector = Module.new do
|
|
101
|
-
def self.collected
|
|
102
|
-
@collected ||= []
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def self.config(name, type = :string, env: true, required: false, blank: false, &block)
|
|
106
|
-
collected << [:config, name, type, env, required, blank, block]
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def self.reviver(name, type = nil, &block)
|
|
110
|
-
collected << [:reviver, name, type, block]
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def self.subconfig(name, &block)
|
|
114
|
-
collected << [:subconfig, name, block]
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
collector.module_eval(&block)
|
|
119
|
-
|
|
120
|
-
collector.collected.each do |kind, name, *args|
|
|
121
|
-
case kind
|
|
122
|
-
when :config
|
|
123
|
-
full = (path + [name]).join("_").to_sym
|
|
124
|
-
config(full, args[0], env: args[1], required: args[2], blank: args[3], &args[4])
|
|
125
|
-
when :reviver
|
|
126
|
-
full = (path + [name]).join("_").to_sym
|
|
127
|
-
reviver(full, args[0], &args[1])
|
|
128
|
-
when :subconfig
|
|
129
|
-
subconfig(name, parent: path, &args[0])
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def self.ensure_required_set!
|
|
135
|
-
unset = []
|
|
136
|
-
required.each do |name|
|
|
137
|
-
value = begin
|
|
138
|
-
instance.public_send(name)
|
|
139
|
-
rescue StandardError
|
|
140
|
-
nil
|
|
141
|
-
end
|
|
142
|
-
unset << name if value.blank?
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
raise("Missing required configuration options: #{unset.join(', ')}") if unset.any?
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
def present?(*names)
|
|
149
|
-
names.flatten.all? { |name| public_send(name).present? }
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
class SubconfigProxy
|
|
153
|
-
def initialize(owner, path)
|
|
154
|
-
@owner = owner
|
|
155
|
-
@path = path
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
def method_missing(name, *, &)
|
|
159
|
-
name = name.to_sym
|
|
160
|
-
full_path = @path + [name]
|
|
161
|
-
|
|
162
|
-
flat = full_path.join("_").to_sym
|
|
163
|
-
return @owner.public_send(flat, *, &) if @owner.respond_to?(flat)
|
|
164
|
-
|
|
165
|
-
return SubconfigProxy.new(@owner, full_path) if subconfig_path?(full_path)
|
|
166
|
-
|
|
167
|
-
super
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
def respond_to_missing?(name, include_private = false)
|
|
171
|
-
name = name.to_sym
|
|
172
|
-
flat = (@path + [name]).join("_").to_sym
|
|
173
|
-
|
|
174
|
-
@owner.respond_to?(flat, include_private) ||
|
|
175
|
-
subconfig_path?(@path + [name]) ||
|
|
176
|
-
super
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
private
|
|
180
|
-
|
|
181
|
-
def subconfig_path?(path)
|
|
182
|
-
node = ConfigBuilder.subconfigs
|
|
183
|
-
path.each do |p|
|
|
184
|
-
return false unless node.key?(p)
|
|
185
|
-
|
|
186
|
-
node = node[p]
|
|
187
|
-
end
|
|
188
|
-
true
|
|
189
|
-
end
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
end
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module YiffSpace
|
|
4
|
-
class Configuration
|
|
5
|
-
# Named presets for `bin/rails generate yiffspace:fixer`, so `--template <name>` (or a
|
|
6
|
-
# registered shortname flag) can stand in for `--steps N`. Populated two ways:
|
|
7
|
-
#
|
|
8
|
-
# - Automatically, from YiffSpace::FixerTemplate subclasses found in
|
|
9
|
-
# YiffSpace.config.fixer_templates_path (the common case - see FixerTemplate).
|
|
10
|
-
# - Manually, via #register, for a preset that just needs a step count and no per-step
|
|
11
|
-
# content (every step falls back to the generic fixer.rb template).
|
|
12
|
-
#
|
|
13
|
-
# See YiffSpace::Configuration#fixer_templates and Yiffspace::FixerGenerator.
|
|
14
|
-
class FixerTemplates
|
|
15
|
-
include(Enumerable)
|
|
16
|
-
|
|
17
|
-
Template = Struct.new(:name, :short, :content_blocks, keyword_init: true) do
|
|
18
|
-
def steps
|
|
19
|
-
content_blocks.size
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# -t is yiffspace:fixer's own --template flag; -f/-p/-q/-s are Rails::Generators::Base's
|
|
24
|
-
# built-in runtime options (--force/--pretend/--quiet/--skip).
|
|
25
|
-
RESERVED_SHORTS = %w[t f p q s].freeze
|
|
26
|
-
|
|
27
|
-
def initialize
|
|
28
|
-
@templates = {}
|
|
29
|
-
@discovered = false
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# short is optional - a template is always reachable via `--template <name>`, a shortname
|
|
33
|
-
# flag (e.g. `-e`) is just a convenient alias for it.
|
|
34
|
-
def register(name, steps:, short: nil)
|
|
35
|
-
raise(ArgumentError, "steps must be a positive integer, got #{steps.inspect}") unless steps.is_a?(Integer) && steps.positive?
|
|
36
|
-
|
|
37
|
-
add(name.to_s, short: short, content_blocks: Array.new(steps))
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def [](name)
|
|
41
|
-
discover!
|
|
42
|
-
@templates[name.to_s]
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def each(&)
|
|
46
|
-
discover!
|
|
47
|
-
@templates.each_value(&)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
private
|
|
51
|
-
|
|
52
|
-
def add(name, short:, content_blocks:)
|
|
53
|
-
raise(ArgumentError, "a fixer template named #{name.inspect} is already registered") if @templates.key?(name)
|
|
54
|
-
|
|
55
|
-
short = short.to_s.delete_prefix("-") if short
|
|
56
|
-
if short
|
|
57
|
-
raise(ArgumentError, "\"-#{short}\" is reserved by yiffspace:fixer's own options") if RESERVED_SHORTS.include?(short)
|
|
58
|
-
|
|
59
|
-
existing = @templates.values.find { |template| template.short == short }
|
|
60
|
-
raise(ArgumentError, "\"-#{short}\" is already registered to the #{existing.name.inspect} fixer template") if existing
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
@templates[name] = Template.new(name: name, short: short, content_blocks: content_blocks)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# Scans YiffSpace.config.fixer_templates_path for YiffSpace::FixerTemplate subclasses and
|
|
67
|
-
# registers each one - runs once, the first time a template is looked up (#[] or #each),
|
|
68
|
-
# so it sees whatever the host app registered manually beforehand.
|
|
69
|
-
def discover!
|
|
70
|
-
return if @discovered
|
|
71
|
-
|
|
72
|
-
@discovered = true
|
|
73
|
-
path = YiffSpace.config.fixer_templates_path
|
|
74
|
-
return unless path && Dir.exist?(path)
|
|
75
|
-
|
|
76
|
-
before = FixerTemplate.subclasses
|
|
77
|
-
Dir[File.join(path, "*.rb")].each { |file| require(file) }
|
|
78
|
-
|
|
79
|
-
(FixerTemplate.subclasses - before).each do |klass|
|
|
80
|
-
raise(ArgumentError, "#{klass.name} has no step blocks - add at least one `step { ... }`") if klass.steps.empty?
|
|
81
|
-
|
|
82
|
-
add(klass.template_name, short: klass.short, content_blocks: klass.steps)
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module YiffSpace
|
|
4
|
-
class Configuration
|
|
5
|
-
class Images
|
|
6
|
-
attr_accessor(:server_url, :update_token, :default_avatar_type, :default_banner_type, :httparty_options)
|
|
7
|
-
|
|
8
|
-
def initialize
|
|
9
|
-
@server_url = "https://images.yiff.space"
|
|
10
|
-
@default_avatar_type = :discord
|
|
11
|
-
@default_banner_type = :discord
|
|
12
|
-
@httparty_options = {
|
|
13
|
-
timeout: 10,
|
|
14
|
-
open_timeout: 5,
|
|
15
|
-
headers: {
|
|
16
|
-
"User-Agent" => "YiffSpaceRuby/#{YiffSpace::VERSION} (https://yiff.space)",
|
|
17
|
-
},
|
|
18
|
-
}
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module YiffSpace
|
|
4
|
-
class Configuration
|
|
5
|
-
# Maximum number of comma-separated values allowed in a multi-value query parameter.
|
|
6
|
-
# Used by ParseValue.range and QueryBuilder.
|
|
7
|
-
attr_reader(:max_multi_count)
|
|
8
|
-
|
|
9
|
-
# Redis URL used by Utils::Cache for direct Redis connections.
|
|
10
|
-
attr_reader(:redis_url)
|
|
11
|
-
|
|
12
|
-
# The application's User model class. Used by Utils::Current, Search::QueryDSL, etc.
|
|
13
|
-
# Falls back to ::User at call time when nil.
|
|
14
|
-
attr_writer(:user_class)
|
|
15
|
-
|
|
16
|
-
# The application's User model class. Used by Utils::UserResolvable
|
|
17
|
-
# Falls back to ::UserLike at call time when nil.
|
|
18
|
-
attr_writer(:user_like_class)
|
|
19
|
-
|
|
20
|
-
# The application's UserResolvable class. Used by Utils::Current.
|
|
21
|
-
# Falls back to ::UserResolvable at call time when nil.
|
|
22
|
-
attr_writer(:user_resolvable_class)
|
|
23
|
-
|
|
24
|
-
# The CurrentAttributes class used to access the current user in model concerns.
|
|
25
|
-
# Defaults to YiffSpace::Utils::Current.
|
|
26
|
-
attr_writer(:current_class)
|
|
27
|
-
|
|
28
|
-
# The default IP address assigned to Utils::Current when none is present.
|
|
29
|
-
attr_accessor(:default_ip_address)
|
|
30
|
-
|
|
31
|
-
# The `last_ip_addr` attribute of the User model, used by the UserResolvableMethods concern
|
|
32
|
-
attr_accessor(:last_ip_addr_attribute)
|
|
33
|
-
|
|
34
|
-
# The anonymous user's name, can be a proc
|
|
35
|
-
attr_reader(:anonymous_user_name)
|
|
36
|
-
|
|
37
|
-
# Override the proc used to fetch the anonymous user. Must respond to #call.
|
|
38
|
-
# Default: -> { (user_class || ::User).anonymous }
|
|
39
|
-
attr_writer(:anonymous_user_getter)
|
|
40
|
-
|
|
41
|
-
# Override the proc used to fetch the system user. Must respond to #call.
|
|
42
|
-
# Default: -> { (user_class || ::User).system }
|
|
43
|
-
attr_writer(:system_user_getter)
|
|
44
|
-
|
|
45
|
-
# The application's ApplicationRecord class. Used by Concerns::ActiveRecordExtensions & Utils::TableBuilder.
|
|
46
|
-
# Falls back to ::ApplicationRecord at call time when nil.
|
|
47
|
-
attr_writer(:application_record_class)
|
|
48
|
-
|
|
49
|
-
# The application's ApplicationController class. Used by Utils::Helpers & Utils::TableBuilder.
|
|
50
|
-
# Falls back to ::ApplicationController at call time when nil.
|
|
51
|
-
attr_writer(:application_controller_class)
|
|
52
|
-
|
|
53
|
-
def initialize
|
|
54
|
-
@max_multi_count = -> { 100 }
|
|
55
|
-
@redis_url = -> {}
|
|
56
|
-
@user_class = nil
|
|
57
|
-
@user_like_class = nil
|
|
58
|
-
@user_resolvable_class = nil
|
|
59
|
-
@current_class = nil
|
|
60
|
-
@default_ip_address = "127.0.0.1"
|
|
61
|
-
@last_ip_addr_attribute = :last_ip_addr
|
|
62
|
-
@anonymous_user_name = -> { "Anonymous" }
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def user_class
|
|
66
|
-
@user_class || ::User
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def user_like_class
|
|
70
|
-
@user_like_class || Utils::UserLike
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def user_resolvable_class
|
|
74
|
-
@user_resolvable_class || Utils::UserResolvable
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# Returns the configured current class, defaulting to YiffSpace::Utils::Current.
|
|
78
|
-
def current_class
|
|
79
|
-
@current_class || Utils::Current
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# Lazily built: calls user_class (or ::User) at invocation time, not config time.
|
|
83
|
-
def anonymous_user_getter
|
|
84
|
-
@anonymous_user_getter ||= -> { user_class.anonymous }
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# Lazily built: calls user_class (or ::User) at invocation time, not config time.
|
|
88
|
-
def system_user_getter
|
|
89
|
-
@system_user_getter ||= -> { user_class.system }
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def redis_url=(value)
|
|
93
|
-
@redis_url = value.is_a?(Proc) ? value : -> { value }
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def max_multi_count=(value)
|
|
97
|
-
@max_multi_count = value.is_a?(Proc) ? value : -> { value }
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
def anonymous_user_name=(value)
|
|
101
|
-
@anonymous_user_name = value.is_a?(Proc) ? value : -> { value }
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def application_record_class
|
|
105
|
-
@application_record_class || ::ApplicationRecord
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
def application_controller_class
|
|
109
|
-
@application_controller_class || ::ApplicationController
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def images
|
|
113
|
-
@images ||= Images.new
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
# Named `--steps` presets for `bin/rails generate yiffspace:fixer`. See
|
|
117
|
-
# YiffSpace::Configuration::FixerTemplates.
|
|
118
|
-
def fixer_templates
|
|
119
|
-
@fixer_templates ||= FixerTemplates.new
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
# Directory scanned for YiffSpace::FixerTemplate subclasses (see FixerTemplate) - defaults to
|
|
123
|
-
# db/fixer_templates in the host app.
|
|
124
|
-
attr_writer(:fixer_templates_path)
|
|
125
|
-
|
|
126
|
-
def fixer_templates_path
|
|
127
|
-
@fixer_templates_path ||= Rails.root.join("db/fixer_templates")
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
end
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require("active_record/relation")
|
|
4
|
-
require_relative("../arel/cross_join_lateral")
|
|
5
|
-
require_relative("../../extensions/active_record/cross_join_lateral")
|
|
6
|
-
|
|
7
|
-
ActiveRecord::Relation.include(YiffSpace::Extensions::ActiveRecord::CrossJoinLateral)
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require("active_record/relation")
|
|
4
|
-
require_relative("../arel/left_join_lateral")
|
|
5
|
-
require_relative("../../extensions/active_record/left_join_lateral")
|
|
6
|
-
|
|
7
|
-
ActiveRecord::Relation.include(YiffSpace::Extensions::ActiveRecord::LeftJoinLateral)
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require("active_record/relation")
|
|
4
|
-
require_relative("cross_join_lateral")
|
|
5
|
-
require_relative("left_join_lateral")
|
|
6
|
-
require_relative("../../extensions/active_record/unnest")
|
|
7
|
-
|
|
8
|
-
ActiveRecord::Relation.include(YiffSpace::Extensions::ActiveRecord::Unnest)
|