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,95 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module YiffSpace
|
|
4
|
-
# Tracks which db/fixes/*.rb scripts a host app has applied, in a `fixes` table (see
|
|
5
|
-
# db/migrate/*_create_fixes.rb) the same way ActiveRecord's own schema_migrations table
|
|
6
|
-
# tracks migrations. Used by the `fixes:*` rake tasks (lib/tasks/fixes.rake).
|
|
7
|
-
module FixTracker
|
|
8
|
-
module_function
|
|
9
|
-
|
|
10
|
-
def fix_path(name)
|
|
11
|
-
Rails.root.glob("db/fixes/#{name}.rb").first
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# db/fixes filenames are "<id>_description.rb", occasionally "<id>_<index>_description.rb"
|
|
15
|
-
# (e.g. 1_1_..., 1_2_...) for a handful of fixes split into ordered steps - the `fixes`
|
|
16
|
-
# table mirrors this as an (id, index) pair, with index null for fixes with no subtype.
|
|
17
|
-
def key_for(name)
|
|
18
|
-
id, maybe_index = name.split("_", 3)
|
|
19
|
-
index = maybe_index =~ /\A\d+\z/ ? maybe_index.to_i : nil
|
|
20
|
-
[id.to_i, index]
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# Sort on the (id, index) parts, not the filename string, so 12 doesn't sort before 2_2.
|
|
24
|
-
def sort_key(name)
|
|
25
|
-
id, index = key_for(name)
|
|
26
|
-
[id, index || 0]
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# Only numbered one-time fixes are tracked/auto-applied - a host app's db/fixes may also hold
|
|
30
|
-
# reusable on-demand maintenance scripts that aren't meant to run automatically as part of
|
|
31
|
-
# `fixes:migrate`. Those stay reachable via `fixes:run[name]`.
|
|
32
|
-
def all_fixes
|
|
33
|
-
Rails.root.glob("db/fixes/*.rb").map { |path| File.basename(path, ".rb") }.grep(/\A\d/).sort_by { |name| sort_key(name) }
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def applied
|
|
37
|
-
ActiveRecord::Base.connection.select_rows('SELECT id, "index" FROM fixes').to_set
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def applied?(name)
|
|
41
|
-
id, index = key_for(name)
|
|
42
|
-
conn = ActiveRecord::Base.connection
|
|
43
|
-
index_clause = index.nil? ? '"index" IS NULL' : %("index" = #{index})
|
|
44
|
-
conn.select_value("SELECT 1 FROM fixes WHERE id = #{id} AND #{index_clause}").present?
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def pending
|
|
48
|
-
applied_keys = applied
|
|
49
|
-
all_fixes.reject { |name| applied_keys.include?(key_for(name)) }
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def record!(name)
|
|
53
|
-
id, index = key_for(name)
|
|
54
|
-
conn = ActiveRecord::Base.connection
|
|
55
|
-
conn.execute(<<~SQL.squish)
|
|
56
|
-
INSERT INTO fixes (id, "index") VALUES (#{id}, #{index || 'NULL'})
|
|
57
|
-
ON CONFLICT (id, "index") DO NOTHING
|
|
58
|
-
SQL
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def run!(path)
|
|
62
|
-
name = File.basename(path, ".rb")
|
|
63
|
-
load(File.expand_path(path))
|
|
64
|
-
record!(name)
|
|
65
|
-
name
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
# Mirrors how ActiveRecord appends `INSERT INTO "schema_migrations"` to structure.sql after
|
|
69
|
-
# a schema dump (see Connection#dump_schema_versions) - appends the currently-applied fixes
|
|
70
|
-
# the same way, so loading structure.sql into a fresh database marks them applied too instead
|
|
71
|
-
# of leaving `fixes:migrate` to re-run every historical fix. Hooked into `db:schema:dump` in
|
|
72
|
-
# lib/tasks/fixes.rake, so it runs on every schema dump, not just `fixes:migrate`.
|
|
73
|
-
def dump_structure_sql!
|
|
74
|
-
db_config = ActiveRecord::Base.connection_db_config
|
|
75
|
-
return unless db_config.schema_format == :sql
|
|
76
|
-
|
|
77
|
-
filename = ActiveRecord::Tasks::DatabaseTasks.schema_dump_path(db_config)
|
|
78
|
-
return unless filename && File.exist?(filename)
|
|
79
|
-
|
|
80
|
-
conn = ActiveRecord::Base.connection
|
|
81
|
-
return unless conn.table_exists?(:fixes)
|
|
82
|
-
|
|
83
|
-
rows = conn.select_rows('SELECT id, "index" FROM fixes ORDER BY id DESC, "index" DESC NULLS LAST')
|
|
84
|
-
return if rows.empty?
|
|
85
|
-
|
|
86
|
-
values = rows.map { |id, index| "(#{id}, #{index || 'NULL'})" }.join(",\n")
|
|
87
|
-
File.open(filename, "a") do |f|
|
|
88
|
-
f.puts(<<~TEXT)
|
|
89
|
-
INSERT INTO "fixes" (id, "index") VALUES
|
|
90
|
-
#{values};
|
|
91
|
-
TEXT
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module YiffSpace
|
|
4
|
-
# Base class for a `bin/rails generate yiffspace:fixer` template, auto-discovered from *.rb
|
|
5
|
-
# files in YiffSpace.config.fixer_templates_path (default db/fixer_templates) - no explicit
|
|
6
|
-
# registration needed, just define a subclass:
|
|
7
|
-
#
|
|
8
|
-
# class ElasticsearchTemplate < YiffSpace::FixerTemplate
|
|
9
|
-
# short("e")
|
|
10
|
-
#
|
|
11
|
-
# step { "..." }
|
|
12
|
-
# step { "..." }
|
|
13
|
-
# end
|
|
14
|
-
#
|
|
15
|
-
# The template's name comes from the class name with a trailing "Template" dropped and
|
|
16
|
-
# kebab-cased (ElasticsearchTemplate -> "elasticsearch", OpenSearchTemplate -> "open-search"),
|
|
17
|
-
# reachable as `--template <name>` (see Yiffspace::FixerGenerator). Its step count is the
|
|
18
|
-
# number of `step` blocks - each one's return value becomes that step's fix file content,
|
|
19
|
-
# instead of the generic fixer.rb template a plain `--steps N` copies for every step.
|
|
20
|
-
class FixerTemplate
|
|
21
|
-
class << self
|
|
22
|
-
# Optional - a template is always reachable via `--template <name>`, a registered
|
|
23
|
-
# shortname flag (e.g. `-e`) is just a convenient alias for it.
|
|
24
|
-
def short(value = nil)
|
|
25
|
-
@short = value.to_s.delete_prefix("-") unless value.nil?
|
|
26
|
-
@short
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def step(&block)
|
|
30
|
-
raise(ArgumentError, "#{name}.step requires a block") unless block
|
|
31
|
-
|
|
32
|
-
steps << block
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def steps
|
|
36
|
-
@steps ||= []
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def template_name
|
|
40
|
-
name.demodulize.delete_suffix("Template").underscore.dasherize
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module YiffSpace
|
|
4
|
-
module Images
|
|
5
|
-
module Avatar
|
|
6
|
-
class Base
|
|
7
|
-
def self.type = nil
|
|
8
|
-
|
|
9
|
-
attr_reader(:id, :type)
|
|
10
|
-
|
|
11
|
-
def initialize(id, type)
|
|
12
|
-
@id = id
|
|
13
|
-
@type = type
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def url
|
|
17
|
-
raise(NotImplementedError)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def update(*)
|
|
21
|
-
raise(NotImplementedError)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def serializable_hash(*)
|
|
25
|
-
{ "id" => @id, "type" => @type }
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def self.from_json(data)
|
|
29
|
-
raise(ArgumentError, "invalid data") if data.blank?
|
|
30
|
-
|
|
31
|
-
data = JSON.parse(data) if data.is_a?(String)
|
|
32
|
-
data = ::YiffSpace::Utils::OpenHash.from(data)
|
|
33
|
-
|
|
34
|
-
return Avatar.find_type(data.type).from_json(data) if self == Base
|
|
35
|
-
|
|
36
|
-
new(data.id)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require("httparty")
|
|
4
|
-
|
|
5
|
-
module YiffSpace
|
|
6
|
-
module Images
|
|
7
|
-
module Avatar
|
|
8
|
-
class Discord < Base
|
|
9
|
-
def self.type = :discord
|
|
10
|
-
|
|
11
|
-
def initialize(id)
|
|
12
|
-
super(id, self.class.type)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def url
|
|
16
|
-
"#{YiffSpace.config.images.server_url}/avatar/discord/#{id}"
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def update(hash)
|
|
20
|
-
raise(StandardError, "images.update_token config option must be set to use avatar update") if YiffSpace.config.images.update_token.blank?
|
|
21
|
-
|
|
22
|
-
response = HTTParty.post("#{YiffSpace.config.images.server_url}/avatar/discord/update/#{id}",
|
|
23
|
-
YiffSpace.config.images.httparty_options.deep_merge(
|
|
24
|
-
headers: {
|
|
25
|
-
"Authorization" => "Bearer #{YiffSpace.config.images.update_token}",
|
|
26
|
-
"Content-Type" => "application/json",
|
|
27
|
-
},
|
|
28
|
-
body: { hash: hash }.to_json,
|
|
29
|
-
))
|
|
30
|
-
Rails.logger.error("avatar update failed: #{response.to_json}") unless response.key?("updated")
|
|
31
|
-
|
|
32
|
-
response.fetch("updated", false)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require("httparty")
|
|
4
|
-
|
|
5
|
-
module YiffSpace
|
|
6
|
-
module Images
|
|
7
|
-
module Avatar
|
|
8
|
-
class Gravatar < Base
|
|
9
|
-
def self.type = :gravatar
|
|
10
|
-
|
|
11
|
-
def initialize(id)
|
|
12
|
-
super(id, self.class.type)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def url
|
|
16
|
-
"#{YiffSpace.config.images.server_url}/avatar/gravatar/#{id}"
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module YiffSpace
|
|
4
|
-
module Images
|
|
5
|
-
module Avatar
|
|
6
|
-
module_function
|
|
7
|
-
|
|
8
|
-
def default_for(id)
|
|
9
|
-
type = YiffSpace.config.images.default_avatar_type
|
|
10
|
-
get_for(id, type)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def get_for(id, type)
|
|
14
|
-
klass = find_type(type)
|
|
15
|
-
raise(StandardError, "No avatar class for type: #{type}") if klass.nil?
|
|
16
|
-
|
|
17
|
-
klass.new(id)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def find_type(type)
|
|
21
|
-
constants.map { |c| [c, const_get(c)] }.find do |_const, value|
|
|
22
|
-
next unless value < Base
|
|
23
|
-
|
|
24
|
-
value.try(:type)&.to_sym == type.to_sym
|
|
25
|
-
end&.second
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def find_type!(type)
|
|
29
|
-
find_type(type) || raise(StandardError, "No avatar class for type: #{type}")
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module YiffSpace
|
|
4
|
-
module Images
|
|
5
|
-
module Banner
|
|
6
|
-
class Base
|
|
7
|
-
def self.type = nil
|
|
8
|
-
|
|
9
|
-
attr_reader(:id, :type)
|
|
10
|
-
|
|
11
|
-
def initialize(id, type)
|
|
12
|
-
@id = id
|
|
13
|
-
@type = type
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def url
|
|
17
|
-
raise(NotImplementedError)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def update(*)
|
|
21
|
-
raise(NotImplementedError)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def serializable_hash(*)
|
|
25
|
-
{ "id" => @id, "type" => @type }
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def self.from_json(data)
|
|
29
|
-
raise(ArgumentError, "invalid data") if data.blank?
|
|
30
|
-
|
|
31
|
-
data = JSON.parse(data) if data.is_a?(String)
|
|
32
|
-
data = ::YiffSpace::Utils::OpenHash.from(data)
|
|
33
|
-
|
|
34
|
-
return Banner.find_type(data.type).from_json(data) if self == Base
|
|
35
|
-
|
|
36
|
-
new(data.id)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require("httparty")
|
|
4
|
-
|
|
5
|
-
module YiffSpace
|
|
6
|
-
module Images
|
|
7
|
-
module Banner
|
|
8
|
-
class Discord < Base
|
|
9
|
-
def self.type = :discord
|
|
10
|
-
|
|
11
|
-
def initialize(id)
|
|
12
|
-
super(id, self.class.type)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def url
|
|
16
|
-
"#{YiffSpace.config.images.server_url}/banner/discord/#{id}"
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def update(hash)
|
|
20
|
-
raise(StandardError, "images.update_token config option must be set to use banner update") if YiffSpace.config.images.update_token.blank?
|
|
21
|
-
|
|
22
|
-
response = HTTParty.post("#{YiffSpace.config.images.server_url}/banner/discord/update/#{id}",
|
|
23
|
-
YiffSpace.config.images.httparty_options.deep_merge(
|
|
24
|
-
headers: {
|
|
25
|
-
"Authorization" => "Bearer #{YiffSpace.config.images.update_token}",
|
|
26
|
-
"Content-Type" => "application/json",
|
|
27
|
-
},
|
|
28
|
-
body: { hash: hash }.to_json,
|
|
29
|
-
))
|
|
30
|
-
Rails.logger.error("banner update failed: #{response.to_json}") unless response.key?("updated")
|
|
31
|
-
|
|
32
|
-
response.fetch("updated", false)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module YiffSpace
|
|
4
|
-
module Images
|
|
5
|
-
module Banner
|
|
6
|
-
module_function
|
|
7
|
-
|
|
8
|
-
def default_for(id)
|
|
9
|
-
type = YiffSpace.config.images.default_banner_type
|
|
10
|
-
get_for(id, type)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def get_for(id, type)
|
|
14
|
-
klass = find_type(type)
|
|
15
|
-
raise(StandardError, "No banner class for type: #{type}") if klass.nil?
|
|
16
|
-
|
|
17
|
-
klass.new(id)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def find_type(type)
|
|
21
|
-
constants.map { |c| [c, const_get(c)] }.find do |_const, value|
|
|
22
|
-
next unless value < Base
|
|
23
|
-
|
|
24
|
-
value.try(:type)&.to_sym == type.to_sym
|
|
25
|
-
end&.second
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def find_type!(type)
|
|
29
|
-
find_type(type) || raise(StandardError, "No banner class for type: #{type}")
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
data/lib/yiffspace/images.rb
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative("active_record_extensions")
|
|
4
|
-
require_relative("api_methods")
|
|
5
|
-
require_relative("attribute_matchers")
|
|
6
|
-
require_relative("attribute_methods")
|
|
7
|
-
require_relative("cache")
|
|
8
|
-
require_relative("concurrency_methods")
|
|
9
|
-
require_relative("conditional_includes")
|
|
10
|
-
require_relative("current")
|
|
11
|
-
require_relative("current_methods")
|
|
12
|
-
require_relative("duration_parser")
|
|
13
|
-
require_relative("has_bit_flags")
|
|
14
|
-
require_relative("helpers")
|
|
15
|
-
require_relative("open_hash")
|
|
16
|
-
require_relative("parameter_builder")
|
|
17
|
-
require_relative("parse_value")
|
|
18
|
-
require_relative("query_builder")
|
|
19
|
-
require_relative("query_dsl")
|
|
20
|
-
require_relative("query_helper")
|
|
21
|
-
require_relative("routes")
|
|
22
|
-
require_relative("table_builder")
|
|
23
|
-
require_relative("trace_logger")
|
|
24
|
-
require_relative("u2id")
|
|
25
|
-
require_relative("user_attribute")
|
|
26
|
-
require_relative("user_class_methods")
|
|
27
|
-
require_relative("user_like")
|
|
28
|
-
require_relative("user_methods")
|
|
29
|
-
require_relative("user_name_methods")
|
|
30
|
-
require_relative("user_resolvable")
|
|
31
|
-
require_relative("user_resolvable_methods")
|