yiffspace 0.0.6 → 0.0.7
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6df835265036ddab2c96c9eee4f74e2d486ff5edcf6e08ea4ee245fd4d4860c4
|
|
4
|
+
data.tar.gz: 3f830fa81d6c083aff4f8b16d8f53a05d60ec2bee6cc7da16d97a5f9fb24a177
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a341d471f5e1aeb0d0226b7cd237927aa209f974d1b8a8c76642e7635629187714515e6051f8db78964c08dcffb90f6b52b913ae7f17e1baf4f52926e48361fc
|
|
7
|
+
data.tar.gz: d6d84c18eb1b40da513fe8dd8fb79c1e2719d9ffa23e17a3132cedd03e336a5cfc08429d3a3ecab8606baf963aaa1d0bdb33d3207617ac6e4a59c389582c412c
|
|
@@ -4,7 +4,8 @@ module YiffSpace
|
|
|
4
4
|
module Concerns
|
|
5
5
|
module UserResolvableMethods
|
|
6
6
|
def resolvable(ip_addr = nil)
|
|
7
|
-
|
|
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)
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
def resolve
|
|
@@ -28,6 +28,12 @@ module YiffSpace
|
|
|
28
28
|
# The default IP address assigned to Utils::Current when none is present.
|
|
29
29
|
attr_accessor(:default_ip_address)
|
|
30
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
|
+
|
|
31
37
|
# Override the proc used to fetch the anonymous user. Must respond to #call.
|
|
32
38
|
# Default: -> { (user_class || ::User).anonymous }
|
|
33
39
|
attr_writer(:anonymous_user_getter)
|
|
@@ -36,21 +42,16 @@ module YiffSpace
|
|
|
36
42
|
# Default: -> { (user_class || ::User).system }
|
|
37
43
|
attr_writer(:system_user_getter)
|
|
38
44
|
|
|
39
|
-
# The anonymous user's name, can be a proc
|
|
40
|
-
attr_reader(:anonymous_user_name)
|
|
41
|
-
|
|
42
|
-
# The `last_ip_addr` attribute of the User model, used by the UserResolvableMethods concern
|
|
43
|
-
attr_accessor(:last_ip_addr_attribute)
|
|
44
|
-
|
|
45
45
|
def initialize
|
|
46
|
-
@max_multi_count
|
|
47
|
-
@redis_url
|
|
48
|
-
@user_class
|
|
49
|
-
@user_like_class
|
|
50
|
-
@user_resolvable_class
|
|
51
|
-
@current_class
|
|
52
|
-
@default_ip_address
|
|
53
|
-
@
|
|
46
|
+
@max_multi_count = -> { 100 }
|
|
47
|
+
@redis_url = -> {}
|
|
48
|
+
@user_class = nil
|
|
49
|
+
@user_like_class = nil
|
|
50
|
+
@user_resolvable_class = nil
|
|
51
|
+
@current_class = nil
|
|
52
|
+
@default_ip_address = "127.0.0.1"
|
|
53
|
+
@last_ip_addr_attribute = :last_ip_addr
|
|
54
|
+
@anonymous_user_name = -> { "Anonymous" }
|
|
54
55
|
end
|
|
55
56
|
|
|
56
57
|
def user_class
|
|
@@ -10,7 +10,8 @@ module YiffSpace
|
|
|
10
10
|
class CloneError < StandardError; end
|
|
11
11
|
attr_reader(:klass, :attribute, :db, :ip, :optional, :clones, :overwrite, :aliases, :ignore_nil, :ar_options)
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
# noinspection RubyUnusedLocalVariable
|
|
14
|
+
def initialize(klass, attribute, db:, ip: !db, optional: !db, clones: [], clone: [], overwrite: false, aliases: [], alias: [], ignore_nil: false, **ar_options)
|
|
14
15
|
UserAttribute.class_setup(klass)
|
|
15
16
|
@klass = klass
|
|
16
17
|
@attribute = attribute.to_sym
|
|
@@ -18,9 +19,9 @@ module YiffSpace
|
|
|
18
19
|
# noinspection RubySimplifyBooleanInspection
|
|
19
20
|
@ip = ip == true ? :"#{attribute}_ip_addr" : ip
|
|
20
21
|
@optional = optional
|
|
21
|
-
@clones = Array(clones).map(&:to_sym)
|
|
22
|
+
@clones = Array(clones.presence || clone).map(&:to_sym)
|
|
22
23
|
@overwrite = overwrite
|
|
23
|
-
@aliases = Array(aliases).map(&:to_sym)
|
|
24
|
+
@aliases = Array(aliases.presence || binding.local_variable_get(:alias)).map(&:to_sym)
|
|
24
25
|
@ignore_nil = ignore_nil
|
|
25
26
|
@ar_options = ar_options
|
|
26
27
|
if ar_options.any? && !db # rubocop:disable Style/IfUnlessModifier
|
|
@@ -191,7 +192,7 @@ module YiffSpace
|
|
|
191
192
|
klass.instance_exec do
|
|
192
193
|
scope("for_#{ua.attribute}", ->(value) { where(ua.db && ua.ar_options.key?(:foreign_key) ? ua.ar_options[:foreign_key] : "#{ua.attribute}_id" => u2id(value)) }) unless respond_to?("for_#{ua.attribute}")
|
|
193
194
|
scope("for_#{ua.attribute}_id", ->(value) { where(ua.db && ua.ar_options.key?(:foreign_key) ? ua.ar_options[:foreign_key] : "#{ua.attribute}_id" => value) }) unless respond_to?("for_#{ua.attribute}_id")
|
|
194
|
-
scope("for_#{ua.attribute}_name", ->(value) { where(ua.db && ua.ar_options.key?(:foreign_key) ? ua.ar_options[:foreign_key] : "#{ua.attribute}_id" =>
|
|
195
|
+
scope("for_#{ua.attribute}_name", ->(value) { where(ua.db && ua.ar_options.key?(:foreign_key) ? ua.ar_options[:foreign_key] : "#{ua.attribute}_id" => YiffSpace.config.user_class.name_to_id(value)) }) unless respond_to?("for_#{ua.attribute}_name")
|
|
195
196
|
end
|
|
196
197
|
|
|
197
198
|
aliases.each do |alias_attr|
|
data/lib/yiffspace/version.rb
CHANGED