effective_resources 1.18.6 → 1.18.9

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: 62921f58ed6ed86c3dc1fc8f08b78509170185d28ca302e8edaac034aee13c3a
4
- data.tar.gz: 984a86a6c60a73b257a771d3d805673c7d0ab2bc4b6009580fb81c25b6c0c10c
3
+ metadata.gz: 5cee67d7d1f8986997b77f0a8d4d2f50cd7b0344ec84522dea0980df07662098
4
+ data.tar.gz: 07bd05a2149368657239d5ed7abd4cce69a3d84b761f81f2653353c3cb4441d3
5
5
  SHA512:
6
- metadata.gz: 1209d346a9de8b331e2976578881b1308a12593ede050e2fb9964c10ccd9dbd24ec85ecc520d6d9e438589de4845692b162897967953f7c3076df54c9b43c631
7
- data.tar.gz: ab56820215894af275fa99a4de2ba66b8a1fc05e1acf43167936a9674bd3330b50de5fb4f35bc5da63d505aff84794e8404c848e1ccef06f327c796f3c128db9
6
+ metadata.gz: 395ca8155e668c86d1060901f9106f155d8202d0f235aac7ec8ef9e497b45b6b02386ec6e6e127615a3291640514508f2ccdbbc3696a1ff41c050ad83289b10e
7
+ data.tar.gz: 4d264db3c46fb74607fc31094a435e3b7c6db1895639f7a425ae65b971a0a051e0f09e1ad5ff059c38d3f5f36e243734302205a29fb6a703ac274847578da9e5
@@ -8,7 +8,11 @@ module Effective
8
8
  def flash_success(resource, action = nil, name: nil)
9
9
  raise 'expected an ActiveRecord resource' unless (name || resource.class.respond_to?(:model_name))
10
10
 
11
- name ||= resource_human_name
11
+ name ||= if resource.respond_to?(:destroyed?) && resource.destroyed?
12
+ resource_human_name
13
+ else
14
+ resource.to_s.presence || resource_human_name
15
+ end
12
16
 
13
17
  "Successfully #{action_verb(action)} #{name || 'resource'}".html_safe
14
18
  end
@@ -21,7 +25,12 @@ module Effective
21
25
  action = action.to_s.gsub('_', ' ')
22
26
 
23
27
  messages = flash_errors(resource, e: e)
24
- name ||= resource_human_name
28
+
29
+ name ||= if resource.respond_to?(:destroyed?) && resource.destroyed?
30
+ resource_human_name
31
+ else
32
+ resource.to_s.presence || resource_human_name
33
+ end
25
34
 
26
35
  ["Unable to #{action}", (" #{name}" if name), (": #{messages}" if messages)].compact.join.html_safe
27
36
  end
@@ -124,8 +124,32 @@ module Effective
124
124
  value.presence
125
125
  when :price # Integer * 100. Number of cents.
126
126
  value.kind_of?(Integer) ? value : (value.to_s.gsub(/[^0-9|\-|\.]/, '').to_f * 100.0).round
127
- when :string, :email
127
+ when :string
128
128
  value.to_s
129
+ when :email
130
+ return nil unless value.kind_of?(String)
131
+
132
+ if value.include?('<') && value.include?('>')
133
+ value = value.match(/<(.+)>/)[1].to_s # John Smith <john.smith@hotmail.com>
134
+ end
135
+
136
+ if value.include?(',')
137
+ value = value.split(',').find { |str| str.include?('@') }.to_s
138
+ end
139
+
140
+ if value.include?(' ')
141
+ value = value.split(' ').find { |str| str.include?('@') }.to_s
142
+ end
143
+
144
+ value = value.to_s.downcase.strip
145
+
146
+ return nil unless value.include?('@') && value.include?('.')
147
+
148
+ if defined?(Devise)
149
+ return nil unless Devise::email_regexp.match?(value)
150
+ end
151
+
152
+ value
129
153
  when :belongs_to_polymorphic
130
154
  value.to_s
131
155
  when :belongs_to, :has_many, :has_and_belongs_to_many, :has_one, :resource, :effective_addresses # Returns an Array of ints, an Int or String
@@ -64,7 +64,7 @@ module Effective
64
64
  :effective_obfuscation
65
65
  elsif name == 'roles' && defined?(EffectiveRoles) && klass.respond_to?(:with_role)
66
66
  :effective_roles
67
- elsif (name.include?('_address') || name.include?('_addresses')) && defined?(EffectiveAddresses) && (klass.new rescue nil).respond_to?(:effective_addresses)
67
+ elsif (name.ends_with?('_address') || name.ends_with?('_addresses')) && defined?(EffectiveAddresses) && (klass.new rescue nil).respond_to?(name)
68
68
  :effective_addresses
69
69
  elsif name.ends_with?('_id')
70
70
  :integer
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.18.6'.freeze
2
+ VERSION = '1.18.9'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.18.6
4
+ version: 1.18.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-15 00:00:00.000000000 Z
11
+ date: 2022-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails