effective_resources 1.1.1 → 1.1.2

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: 31a59a4d537c8d4f363e2a5bb86758f2d0ad2b01
4
- data.tar.gz: 9ce2460bcb27b1afe0d204f9d3528c6e92cbc6a5
3
+ metadata.gz: d09ead4e73ed9c1e6f9064c616de93aafe3b3cf8
4
+ data.tar.gz: 1ba9303908b33ef1ab90b1653063a42f95afbaaa
5
5
  SHA512:
6
- metadata.gz: 33394fcfcde825f6383a5d74a19ae2349ab2d94e7bcff15e9f9ac80fdaa4ae583636b5424982695d3384283eddb538f9ce02df93f06b94a72105ee532badfa59
7
- data.tar.gz: 1efe1addab462d093e0e25f52a5d08a90299ff8a48c5402a192fa9acb5317aa5bcd49d8d360365992bc081af3037286a66bea9694b0c5ba0b2cf80a2ae15b015
6
+ metadata.gz: c61d0ad9c674066d6ba6cabe188f82b24c213bda9a59cdb4e0252aa96acc65a8dd46ab24109f7af00149099debea5bf4b42217f9956da86a3fe84979c0429e55
7
+ data.tar.gz: 31ebc6075403542fb13f578ae8f2af58a3db4c2cd90d341f74f71d6c3a87cc2399c310ebeafe1489cde4107339630e539ed943152c06d00bdc4214b65ab5b3df
@@ -8,7 +8,7 @@ module Effective
8
8
  EffectiveResources.authorize!(self, :index, resource_klass)
9
9
  @page_title ||= resource_plural_name.titleize
10
10
 
11
- self.resources ||= resource_scope.all
11
+ self.resources ||= resource_scope.all if resource_scope.respond_to?(:all)
12
12
  @datatable = resource_datatable(:index)
13
13
 
14
14
  run_callbacks(:resource_render)
@@ -45,8 +45,7 @@ module Effective
45
45
  resource.restore_attributes(['status', 'state'])
46
46
  end
47
47
 
48
- flash.delete(:success)
49
- flash.now[:danger] = flash_danger(resource, action, e: e)
48
+ flash.now[:danger] = resource_flash(:danger, resource, action, e: e)
50
49
  raise ActiveRecord::Rollback
51
50
  end
52
51
  end
@@ -55,14 +54,14 @@ module Effective
55
54
  false
56
55
  end
57
56
 
58
- def resource_flash(status, resource, action)
57
+ def resource_flash(status, resource, action, e: nil)
59
58
  submit = commit_action(action)
60
59
  message = submit[status].respond_to?(:call) ? instance_exec(&submit[status]) : submit[status]
61
- return message if message.present?
60
+ return message.gsub('@resource', resource.to_s) if message.present?
62
61
 
63
62
  case status
64
63
  when :success then flash_success(resource, action)
65
- when :danger then flash_danger(resource, action)
64
+ when :danger then flash_danger(resource, action, e: e)
66
65
  else
67
66
  raise "unknown resource flash status: #{status}"
68
67
  end
@@ -6,9 +6,7 @@ module Effective
6
6
  def flash_success(resource, action = nil, name: nil)
7
7
  raise 'expected an ActiveRecord resource' unless (name || resource.class.respond_to?(:model_name))
8
8
 
9
- name ||= resource.class.model_name.human.downcase
10
-
11
- "Successfully #{action_verb(action)} #{name}"
9
+ "Successfully #{action_verb(action)} #{name || resource}".html_safe
12
10
  end
13
11
 
14
12
  # flash.now[:danger] = flash_danger(@post)
@@ -18,10 +16,11 @@ module Effective
18
16
  action ||= resource.respond_to?(:new_record?) ? (resource.new_record? ? :create : :update) : :save
19
17
  action = action.to_s.gsub('_', ' ')
20
18
 
21
- name ||= resource.class.model_name.human.downcase
22
19
  messages = flash_errors(resource, e: e)
23
20
 
24
- ["Unable to #{action} #{name}", (": #{messages}." if messages)].compact.join.html_safe
21
+ name ||= resource.to_s.presence
22
+
23
+ ["Unable to #{action}", (" #{name}" if name), (": #{messages}." if messages)].compact.join.html_safe
25
24
  end
26
25
 
27
26
  # flash.now[:danger] = "Unable to accept: #{flash_errors(@post)}"
@@ -32,7 +31,7 @@ module Effective
32
31
  if message[0] == message[0].upcase # If the error begins with a capital letter
33
32
  message
34
33
  elsif attribute == :base
35
- "#{resource.class.model_name.human.downcase} #{message}"
34
+ message
36
35
  elsif attribute.to_s.end_with?('_ids')
37
36
  "#{resource.class.human_attribute_name(attribute.to_s[0..-5].pluralize).downcase} #{message}"
38
37
  else
@@ -100,7 +100,10 @@ module EffectiveResourcesHelper
100
100
 
101
101
  # When called from /admin/things/new.html.haml this will render 'admin/things/form', or 'things/form', or 'thing/form'
102
102
  def render_resource_form(resource, atts = {})
103
- raise 'expected first argument to be an ActiveRecord::Base object' unless resource.kind_of?(ActiveRecord::Base)
103
+ unless resource.kind_of?(ActiveRecord::Base) || resource.class.ancestors.include?(ActiveModel::Model)
104
+ raise 'expected first argument to be an ActiveRecord or ActiveModel object'
105
+ end
106
+
104
107
  raise 'expected attributes to be a Hash' unless atts.kind_of?(Hash)
105
108
 
106
109
  effective_resource = (atts.delete(:effective_resource) || find_effective_resource)
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.1.2'.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.1.1
4
+ version: 1.1.2
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: 2018-12-16 00:00:00.000000000 Z
11
+ date: 2018-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails