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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20165a6e28e50bf2343b3616f440fe581c249b4d
4
- data.tar.gz: 6f50638cdade6f465fc5d92372c4181f877d3718
3
+ metadata.gz: 6a40eaa94d306a370aa849c79ee0103357b5efbc
4
+ data.tar.gz: 6f3bf1251c6cd42617194b69e5b98327dc85949e
5
5
  SHA512:
6
- metadata.gz: a67cfdbec3d95464d2c551420582fc65d7bad6083dd03b2602b04db2c12a9f0335b802c0a686b3a06fd88513184423bbafd07cf9339d918d6151afd29db1d699
7
- data.tar.gz: 34f0a721a49c5e7cad13e9673b9767251f516b3a050b186b79c002e72fe4cc00f89b6b335f7454b073f0090cfbee06721033ad47043bef380e0539000a494a8b
6
+ metadata.gz: 21de19a13a1bda04e843bc16db4c31a23b38a60e363c2a841aae78cd61286f7f050f535f8e8672eba85bb48b94818c7cf43817d99d0d6c3a8d5c9e7af1f1dcf7
7
+ data.tar.gz: 7881d51694c1db6a20b3cad4bb9593288a0b0ad482d6ff89c15fdeb0d4ae99c954a7086f5ce07357661618bde11de56ce31b047b6dac8b2aecedda217310b6e9
@@ -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
- class_name = options[:class_name] || assoc.singularize.camelize
97
- foreign_key = options[:foreign_key] || 'user_id'
96
+ if through = options[:through]
97
+ source = options[:source] || assoc
98
98
 
99
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
100
- def #{assoc}
101
- #{class_name}.where(#{foreign_key}: id)
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
- RUBY
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
- !@current_user.nil?
90
+ !!current_user
85
91
  end
86
92
 
87
93
  # -- url uelpers --
@@ -1,5 +1,5 @@
1
1
  module Softwear
2
2
  module Lib
3
- VERSION = "1.5.9"
3
+ VERSION = "1.5.13"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: softwear-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.9
4
+ version: 1.5.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nigel Baillie