softwear-lib 1.5.9 → 1.5.13
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/softwear/auth/model.rb +33 -7
- data/lib/softwear/lib/controller_authentication.rb +8 -2
- data/lib/softwear/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a40eaa94d306a370aa849c79ee0103357b5efbc
|
4
|
+
data.tar.gz: 6f3bf1251c6cd42617194b69e5b98327dc85949e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21de19a13a1bda04e843bc16db4c31a23b38a60e363c2a841aae78cd61286f7f050f535f8e8672eba85bb48b94818c7cf43817d99d0d6c3a8d5c9e7af1f1dcf7
|
7
|
+
data.tar.gz: 7881d51694c1db6a20b3cad4bb9593288a0b0ad482d6ff89c15fdeb0d4ae99c954a7086f5ce07357661618bde11de56ce31b047b6dac8b2aecedda217310b6e9
|
data/lib/softwear/auth/model.rb
CHANGED
@@ -88,19 +88,45 @@ module Softwear
|
|
88
88
|
|
89
89
|
# ====================
|
90
90
|
# Not a fully featured has_many - must specify foreign_key if the association doesn't match
|
91
|
-
# the model name.
|
91
|
+
# the model name, through is inefficient.
|
92
92
|
# ====================
|
93
93
|
def has_many(assoc, options = {})
|
94
94
|
assoc = assoc.to_s
|
95
95
|
|
96
|
-
|
97
|
-
|
96
|
+
if through = options[:through]
|
97
|
+
source = options[:source] || assoc
|
98
98
|
|
99
|
-
|
100
|
-
|
101
|
-
|
99
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
100
|
+
def #{assoc}
|
101
|
+
#{through}.flat_map(&:#{source})
|
102
|
+
end
|
103
|
+
RUBY
|
104
|
+
|
105
|
+
else
|
106
|
+
class_name = options[:class_name] || assoc.singularize.camelize
|
107
|
+
foreign_key = options[:foreign_key] || 'user_id'
|
108
|
+
|
109
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
110
|
+
def #{assoc}
|
111
|
+
#{class_name}.where(#{foreign_key}: id)
|
112
|
+
end
|
113
|
+
RUBY
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# ====================
|
118
|
+
# Pretty much a map function - for activerecord compatibility.
|
119
|
+
# ====================
|
120
|
+
def pluck(*attrs)
|
121
|
+
if attrs.size == 1
|
122
|
+
all.map do |user|
|
123
|
+
user.send(attrs.first)
|
102
124
|
end
|
103
|
-
|
125
|
+
else
|
126
|
+
all.map do |user|
|
127
|
+
attrs.map { |a| user.send(a) }
|
128
|
+
end
|
129
|
+
end
|
104
130
|
end
|
105
131
|
|
106
132
|
def arel_table
|
@@ -77,11 +77,17 @@ module Softwear
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def current_user
|
80
|
-
@current_user
|
80
|
+
return @current_user if @current_user
|
81
|
+
|
82
|
+
if @current_user.nil? && !user_token.blank?
|
83
|
+
@current_user = user_class.auth(user_token)
|
84
|
+
else
|
85
|
+
nil
|
86
|
+
end
|
81
87
|
end
|
82
88
|
|
83
89
|
def user_signed_in?
|
84
|
-
|
90
|
+
!!current_user
|
85
91
|
end
|
86
92
|
|
87
93
|
# -- url uelpers --
|
data/lib/softwear/lib/version.rb
CHANGED