yiffspace 0.1.7 → 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.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -10
  3. data/README.md +18 -1
  4. data/Rakefile +6 -7
  5. data/lib/yiffspace/version.rb +1 -1
  6. data/lib/yiffspace.rb +26 -27
  7. metadata +104 -139
  8. data/app/assets/config/yiffspace_manifest.js +0 -1
  9. data/app/assets/stylesheets/yiffspace/application.css +0 -30
  10. data/app/controllers/yiff_space/application_controller.rb +0 -6
  11. data/app/helpers/yiff_space/application_helper.rb +0 -6
  12. data/app/models/yiff_space/application_record.rb +0 -7
  13. data/app/views/layouts/yiff_space/application.html.erb +0 -17
  14. data/app/views/yiff_space/error.html.erb +0 -3
  15. data/lib/yiffspace/concerns/active_record_extensions.rb +0 -45
  16. data/lib/yiffspace/concerns/api_methods.rb +0 -101
  17. data/lib/yiffspace/concerns/attribute_matchers.rb +0 -100
  18. data/lib/yiffspace/concerns/attribute_methods.rb +0 -39
  19. data/lib/yiffspace/concerns/concurrency_methods.rb +0 -20
  20. data/lib/yiffspace/concerns/conditional_includes.rb +0 -43
  21. data/lib/yiffspace/concerns/current_methods.rb +0 -60
  22. data/lib/yiffspace/concerns/has_bit_flags.rb +0 -59
  23. data/lib/yiffspace/concerns/user_class_methods.rb +0 -32
  24. data/lib/yiffspace/concerns/user_methods.rb +0 -77
  25. data/lib/yiffspace/concerns/user_name_methods.rb +0 -53
  26. data/lib/yiffspace/concerns/user_resolvable_methods.rb +0 -38
  27. data/lib/yiffspace/config_builder.rb +0 -192
  28. data/lib/yiffspace/configuration/images.rb +0 -22
  29. data/lib/yiffspace/configuration.rb +0 -116
  30. data/lib/yiffspace/core_ext/active_record/all.rb +0 -8
  31. data/lib/yiffspace/core_ext/active_record/cross_join_lateral.rb +0 -7
  32. data/lib/yiffspace/core_ext/active_record/cross_unnest.rb +0 -7
  33. data/lib/yiffspace/core_ext/active_record/left_join_lateral.rb +0 -7
  34. data/lib/yiffspace/core_ext/active_record/left_unnest.rb +0 -7
  35. data/lib/yiffspace/core_ext/active_record/unnest.rb +0 -8
  36. data/lib/yiffspace/core_ext/active_record/where_chain.rb +0 -6
  37. data/lib/yiffspace/core_ext/all.rb +0 -8
  38. data/lib/yiffspace/core_ext/arel/all.rb +0 -4
  39. data/lib/yiffspace/core_ext/arel/cross_join_lateral.rb +0 -21
  40. data/lib/yiffspace/core_ext/arel/left_join_lateral.rb +0 -21
  41. data/lib/yiffspace/core_ext/enumerable/all.rb +0 -3
  42. data/lib/yiffspace/core_ext/enumerable/parallel.rb +0 -7
  43. data/lib/yiffspace/core_ext/hash/all.rb +0 -3
  44. data/lib/yiffspace/core_ext/hash/to_open_hash.rb +0 -7
  45. data/lib/yiffspace/core_ext/object/all.rb +0 -4
  46. data/lib/yiffspace/core_ext/object/to_b.rb +0 -7
  47. data/lib/yiffspace/core_ext/object/truthy_falsy.rb +0 -7
  48. data/lib/yiffspace/core_ext/string/all.rb +0 -3
  49. data/lib/yiffspace/core_ext/string/sql.rb +0 -7
  50. data/lib/yiffspace/engine.rb +0 -23
  51. data/lib/yiffspace/extensions/active_record/cross_join_lateral.rb +0 -23
  52. data/lib/yiffspace/extensions/active_record/cross_unnest.rb +0 -15
  53. data/lib/yiffspace/extensions/active_record/left_join_lateral.rb +0 -24
  54. data/lib/yiffspace/extensions/active_record/left_unnest.rb +0 -15
  55. data/lib/yiffspace/extensions/active_record/unnest.rb +0 -20
  56. data/lib/yiffspace/extensions/active_record/where_chain.rb +0 -107
  57. data/lib/yiffspace/extensions/arel/nodes/cross_join_lateral.rb +0 -17
  58. data/lib/yiffspace/extensions/arel/nodes/left_join_lateral.rb +0 -17
  59. data/lib/yiffspace/extensions/arel/table/cross_join_lateral.rb +0 -15
  60. data/lib/yiffspace/extensions/arel/table/left_join_lateral.rb +0 -15
  61. data/lib/yiffspace/extensions/arel/visitors/postgresql/cross_join_lateral.rb +0 -19
  62. data/lib/yiffspace/extensions/arel/visitors/postgresql/left_join_lateral.rb +0 -23
  63. data/lib/yiffspace/extensions/enumerable/parallel.rb +0 -39
  64. data/lib/yiffspace/extensions/hash/to_open_hash.rb +0 -15
  65. data/lib/yiffspace/extensions/object/to_b.rb +0 -22
  66. data/lib/yiffspace/extensions/object/truthy_falsy.rb +0 -35
  67. data/lib/yiffspace/extensions/string/sql.rb +0 -21
  68. data/lib/yiffspace/images/avatar/base.rb +0 -41
  69. data/lib/yiffspace/images/avatar/discord.rb +0 -37
  70. data/lib/yiffspace/images/avatar/gravatar.rb +0 -21
  71. data/lib/yiffspace/images/avatar.rb +0 -33
  72. data/lib/yiffspace/images/banner/base.rb +0 -41
  73. data/lib/yiffspace/images/banner/discord.rb +0 -37
  74. data/lib/yiffspace/images/banner.rb +0 -33
  75. data/lib/yiffspace/images.rb +0 -6
  76. data/lib/yiffspace/include/active_record_extensions.rb +0 -5
  77. data/lib/yiffspace/include/all.rb +0 -31
  78. data/lib/yiffspace/include/api_methods.rb +0 -5
  79. data/lib/yiffspace/include/attribute_matchers.rb +0 -5
  80. data/lib/yiffspace/include/attribute_methods.rb +0 -5
  81. data/lib/yiffspace/include/cache.rb +0 -5
  82. data/lib/yiffspace/include/concurrency_methods.rb +0 -5
  83. data/lib/yiffspace/include/conditional_includes.rb +0 -5
  84. data/lib/yiffspace/include/current.rb +0 -5
  85. data/lib/yiffspace/include/current_methods.rb +0 -5
  86. data/lib/yiffspace/include/duration_parser.rb +0 -5
  87. data/lib/yiffspace/include/has_bit_flags.rb +0 -5
  88. data/lib/yiffspace/include/helpers.rb +0 -5
  89. data/lib/yiffspace/include/open_hash.rb +0 -5
  90. data/lib/yiffspace/include/parameter_builder.rb +0 -5
  91. data/lib/yiffspace/include/parse_value.rb +0 -5
  92. data/lib/yiffspace/include/query_builder.rb +0 -5
  93. data/lib/yiffspace/include/query_dsl.rb +0 -5
  94. data/lib/yiffspace/include/query_helper.rb +0 -5
  95. data/lib/yiffspace/include/routes.rb +0 -5
  96. data/lib/yiffspace/include/table_builder.rb +0 -5
  97. data/lib/yiffspace/include/trace_logger.rb +0 -5
  98. data/lib/yiffspace/include/u2id.rb +0 -5
  99. data/lib/yiffspace/include/user_attribute.rb +0 -5
  100. data/lib/yiffspace/include/user_class_methods.rb +0 -5
  101. data/lib/yiffspace/include/user_like.rb +0 -5
  102. data/lib/yiffspace/include/user_methods.rb +0 -5
  103. data/lib/yiffspace/include/user_name_methods.rb +0 -5
  104. data/lib/yiffspace/include/user_resolvable.rb +0 -5
  105. data/lib/yiffspace/include/user_resolvable_methods.rb +0 -5
  106. data/lib/yiffspace/search/query_builder.rb +0 -83
  107. data/lib/yiffspace/search/query_dsl.rb +0 -119
  108. data/lib/yiffspace/search/query_helper.rb +0 -49
  109. data/lib/yiffspace/serializers/avatar_serializer.rb +0 -21
  110. data/lib/yiffspace/serializers/banner_serializer.rb +0 -21
  111. data/lib/yiffspace/serializers/user_resolvable_serializer.rb +0 -21
  112. data/lib/yiffspace/utils/cache.rb +0 -40
  113. data/lib/yiffspace/utils/current.rb +0 -43
  114. data/lib/yiffspace/utils/duration_parser.rb +0 -24
  115. data/lib/yiffspace/utils/helpers.rb +0 -25
  116. data/lib/yiffspace/utils/open_hash.rb +0 -63
  117. data/lib/yiffspace/utils/parameter_builder.rb +0 -121
  118. data/lib/yiffspace/utils/parse_value.rb +0 -174
  119. data/lib/yiffspace/utils/routes.rb +0 -28
  120. data/lib/yiffspace/utils/set_env_constraint.rb +0 -18
  121. data/lib/yiffspace/utils/table_builder.rb +0 -169
  122. data/lib/yiffspace/utils/trace_logger.rb +0 -91
  123. data/lib/yiffspace/utils/user_attribute.rb +0 -272
  124. data/lib/yiffspace/utils/user_like.rb +0 -8
  125. data/lib/yiffspace/utils/user_resolvable.rb +0 -61
  126. data/lib/yiffspace/utils/user_to_id.rb +0 -11
  127. data/lib/yiffspace/utils.rb +0 -6
@@ -1,107 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module YiffSpace
4
- module Extensions
5
- module ActiveRecord
6
- module WhereChain
7
- %i[
8
- lt lteq gt gteq
9
- between not_between in not_in like
10
- ilike not_like not_ilike
11
- like_all ilike_all not_like_all not_ilike_all
12
- like_any ilike_any not_like_any not_ilike_any
13
- has_bits not_has_bits
14
- ].each do |method|
15
- define_method(method) do |conditions|
16
- build(conditions, method)
17
- end
18
- end
19
-
20
- alias lte lteq
21
- alias gte gteq
22
-
23
- # https://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP
24
- # "(?e)" means force use of ERE syntax; see sections 9.7.3.1 and 9.7.3.4.
25
- def regex(conditions = {}, flags: "e", **kwargs)
26
- conditions.merge!(kwargs) if conditions.is_a?(::Hash)
27
- build(conditions, :regex, flags)
28
- end
29
-
30
- def not_regex(conditions = {}, flags: "e", **kwargs)
31
- conditions.merge!(kwargs) if conditions.is_a?(::Hash)
32
- build(conditions, :not_regex, flags)
33
- end
34
-
35
- def tsquery(conditions = {}, ts_config: "english", **kwargs)
36
- conditions.merge!(kwargs) if conditions.is_a?(::Hash)
37
- build(conditions, :tsquery, ts_config)
38
- end
39
-
40
- METHODS = {
41
- lt: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].lt(value) },
42
- lteq: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].lteq(value) },
43
- gt: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].gt(value) },
44
- gteq: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].gteq(value) },
45
- between: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].between(value) },
46
- not_between: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].not_between(value) },
47
- in: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].in(value) },
48
- not_in: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].not_in(value) },
49
- like: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].matches(value.to_escaped_for_sql_like, ::Arel.sql("E'\\\\'"), true) },
50
- ilike: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].matches(value.to_escaped_for_sql_like, ::Arel.sql("E'\\\\'"), false) },
51
- not_like: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].does_not_match(value.to_escaped_for_sql_like, ::Arel.sql("E'\\\\'"), true) },
52
- not_ilike: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].does_not_match(value.to_escaped_for_sql_like, ::Arel.sql("E'\\\\'"), false) },
53
- like_all: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].matches_all(value.map(&:to_escaped_for_sql_like), ::Arel.sql("E'\\\\'"), true) },
54
- ilike_all: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].matches_all(value.map(&:to_escaped_for_sql_like), ::Arel.sql("E'\\\\'"), false) },
55
- not_like_all: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].does_not_match_all(value.map(&:to_escaped_for_sql_like), ::Arel.sql("E'\\\\'"), true) },
56
- not_ilike_all: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].does_not_match_all(value.map(&:to_escaped_for_sql_like), ::Arel.sql("E'\\\\'"), false) },
57
- like_any: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].matches_any(value.map(&:to_escaped_for_sql_like), ::Arel.sql("E'\\\\'"), true) },
58
- ilike_any: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].matches_any(value.map(&:to_escaped_for_sql_like), ::Arel.sql("E'\\\\'"), false) },
59
- not_like_any: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].does_not_match_any(value.map(&:to_escaped_for_sql_like), ::Arel.sql("E'\\\\'"), true) },
60
- not_ilike_any: ->(table_name, column, value) { ::Arel::Table.new(table_name)[column].does_not_match_any(value.map(&:to_escaped_for_sql_like), ::Arel.sql("E'\\\\'"), false) },
61
- regex: ->(table_name, column, value, flags) { ::Arel::Table.new(table_name)[column].matches_regexp("(?#{flags})#{value.is_a?(Regexp) ? value.source : value}") },
62
- not_regex: ->(table_name, column, value, flags) { ::Arel::Table.new(table_name)[column].does_not_match_regexp("(?#{flags})#{value.is_a?(Regexp) ? value.source : value}") },
63
- tsquery: ->(table_name, column, value, ts_config) { ::Arel.sql("to_tsvector(:ts_config, :table) @@ plainto_tsquery(:ts_config, :value)", ts_config: ts_config, value: value, table: ::Arel.sql("#{table_name}.#{column}")) },
64
- has_bits: ->(table_name, column, value) { ::Arel.sql("(#{table_name}.#{column} & #{::Arel::Nodes.build_quoted(value).to_sql}) = #{::Arel::Nodes.build_quoted(value).to_sql}") },
65
- not_has_bits: ->(table_name, column, value) { ::Arel.sql("(#{table_name}.#{column} & #{::Arel::Nodes.build_quoted(value).to_sql}) != #{::Arel::Nodes.build_quoted(value).to_sql}") },
66
- }.freeze
67
-
68
- private
69
-
70
- def build(conditions, method, *extra)
71
- model = @scope.klass
72
-
73
- parsed_conditions = normalize_conditions(conditions, model)
74
-
75
- arel_conditions = parsed_conditions.map do |(table_name, column), value|
76
- METHODS.fetch(method).call(table_name, column, value, *extra)
77
- end.reduce(:and)
78
-
79
- @scope.where(arel_conditions)
80
- end
81
-
82
- def normalize_conditions(conditions, model, table_name = nil)
83
- pairs = []
84
-
85
- conditions.each do |key, value|
86
- case key
87
- when ::String, ::Symbol
88
- key = key.to_s
89
- if value.is_a?(::Hash)
90
- pairs.concat(normalize_conditions(value, model, key))
91
- elsif key.include?(".")
92
- table, col = key.split(".", 2)
93
- pairs << [[table, col], value]
94
- else
95
- pairs << [[table_name || model.table_name, key], value]
96
- end
97
- else
98
- raise(ArgumentError, "Unsupported key type: #{key.class}")
99
- end
100
- end
101
-
102
- pairs
103
- end
104
- end
105
- end
106
- end
107
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require("arel")
4
-
5
- module YiffSpace
6
- module Extensions
7
- module Arel
8
- module Nodes
9
- class CrossJoinLateral < ::Arel::Nodes::Join
10
- def initialize(left, right = nil)
11
- super
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require("arel")
4
-
5
- module YiffSpace
6
- module Extensions
7
- module Arel
8
- module Nodes
9
- class LeftJoinLateral < ::Arel::Nodes::Join
10
- def initialize(left, right = nil)
11
- super
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module YiffSpace
4
- module Extensions
5
- module Arel
6
- module Table
7
- module CrossJoinLateral
8
- def cross_join_lateral(relation)
9
- join(relation, ::Arel::Nodes::CrossJoinLateral)
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module YiffSpace
4
- module Extensions
5
- module Arel
6
- module Table
7
- module LeftJoinLateral
8
- def left_join_lateral(relation)
9
- join(relation, ::Arel::Nodes::LeftJoinLateral)
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module YiffSpace
4
- module Extensions
5
- module Arel
6
- module Visitors
7
- module PostgreSQL
8
- module CrossJoinLateral
9
- # noinspection RubyInstanceMethodNamingConvention
10
- def visit_YiffSpace_Extensions_Arel_Nodes_CrossJoinLateral(o, collector)
11
- collector << "CROSS JOIN LATERAL "
12
- visit(o.left, collector)
13
- end
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module YiffSpace
4
- module Extensions
5
- module Arel
6
- module Visitors
7
- module PostgreSQL
8
- module LeftJoinLateral
9
- # noinspection RubyInstanceMethodNamingConvention
10
- def visit_YiffSpace_Extensions_Arel_Nodes_LeftJoinLateral(o, collector)
11
- collector << "LEFT JOIN LATERAL "
12
- visit(o.left, collector)
13
- return unless o.right
14
-
15
- collector << " ON "
16
- visit(o.right.expr, collector)
17
- end
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require("active_support/core_ext/module/attribute_accessors")
4
-
5
- module YiffSpace
6
- module Extensions
7
- module Enumerable
8
- module Parallel
9
- mattr_accessor(:usable)
10
- # Like `#each`, but perform the block on each item in parallel. Note that items aren't processed in order, so things
11
- # like `parallel_each.map` that rely on ordering won't work.
12
- def parallel_each(executor = :io, &)
13
- return enum_for(:parallel_each, executor) unless block_given?
14
-
15
- parallel_map(executor, &)
16
- self
17
- end
18
-
19
- # Like `#map`, but in parallel.
20
- def parallel_map(executor = :io, &)
21
- return enum_for(:parallel_map, executor) unless block_given?
22
-
23
- promises = map do |item|
24
- Concurrent::Promises.future_on(executor, item, &)
25
- end
26
-
27
- Concurrent::Promises.zip_futures_on(executor, *promises).value!
28
- end
29
- end
30
- end
31
- end
32
- end
33
-
34
- begin
35
- require("concurrent-ruby")
36
- YiffSpace::Extensions::Enumerable::Parallel.usable = true
37
- rescue LoadError
38
- YiffSpace::Extensions::Enumerable::Parallel.usable = false
39
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module YiffSpace
4
- module Extensions
5
- module Hash
6
- module ToOpenHash
7
- def to_open_hash
8
- ::YiffSpace::Utils::OpenHash.from(self)
9
- end
10
-
11
- alias with_open_access to_open_hash
12
- end
13
- end
14
- end
15
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module YiffSpace
4
- module Extensions
5
- module Object
6
- module ToB
7
- def to_b
8
- case self
9
- when ::String
10
- !match?(/\A(false|f|no|n|off|0)\z/i)
11
- when ::TrueClass
12
- true
13
- when ::FalseClass
14
- false
15
- else
16
- to_s.to_b
17
- end
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module YiffSpace
4
- module Extensions
5
- module Object
6
- module TruthyFalsy
7
- def truthy?
8
- case self
9
- when ::String
10
- match?(/\A(true|t|yes|y|on|1)\z/i)
11
- when ::TrueClass
12
- true
13
- when ::FalseClass
14
- false
15
- else
16
- to_s.truthy?
17
- end
18
- end
19
-
20
- def falsy?
21
- case self
22
- when ::String
23
- match?(/\A(false|f|no|n|off|0)\z/i)
24
- when ::TrueClass
25
- false
26
- when ::FalseClass
27
- true
28
- else
29
- to_s.falsy?
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module YiffSpace
4
- module Extensions
5
- module String
6
- module Sql
7
- def to_escaped_for_sql_like
8
- gsub(/%|_|\*|\\\*|\\\\|\\/) do |str|
9
- case str
10
- when "%" then '\%'
11
- when "_" then '\_'
12
- when "*" then "%"
13
- when '\*' then "*"
14
- when "\\\\", "\\" then "\\\\"
15
- end
16
- end
17
- end
18
- end
19
- end
20
- end
21
- 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
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module YiffSpace
4
- module Images
5
- end
6
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative("../concerns/active_record_extensions")
4
-
5
- ActiveRecordExtensions = YiffSpace::Concerns::ActiveRecordExtensions
@@ -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")
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative("../concerns/api_methods")
4
-
5
- ApiMethods = YiffSpace::Concerns::ApiMethods
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative("../concerns/attribute_matchers")
4
-
5
- AttributeMatchers = YiffSpace::Concerns::AttributeMatchers
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative("../concerns/attribute_methods")
4
-
5
- AttributeMethods = YiffSpace::Concerns::AttributeMethods