effective_resources 0.2.3 → 0.2.4

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: a75f5adcc4a20f0f1a18cd2496657b439934e596
4
- data.tar.gz: c72e11e7e702d75cafa264dab8c538f6e61962b1
3
+ metadata.gz: b55e4948a32a2526cc0ce43230a6bee620c09a14
4
+ data.tar.gz: d0b8bf59119514d156e4b63428cc068960cb779e
5
5
  SHA512:
6
- metadata.gz: 5027571db1c5f1ebad0870f99a1606dc7bd8cc4e5282d472656f2aaf4d9d010a71d26ff7dadb55fd7386906d8eedb67fd1ee24e08e8133c07b8ec18045caf2cb
7
- data.tar.gz: 96ed7d36303ad72394afa8dc2c7c6533500abca4e85fbdb56d3868b91897446f1fb36f9af4653bb6ca610c78f159a2568cb95a76cfb79248a07c027255d27808
6
+ metadata.gz: 508301a27e166a14290d8085066c773d584ab2e39c294106b7361d973219712f359e227178904f7f58f9849e551204d317d042d49de594f85c2417e896f818e4
7
+ data.tar.gz: c96b6875d7685e62b288fef2e8892eb7a1c664cfd6839ac0e491e876e103224e75d1fcced5ba2c83d427ec98322767f61fb99915ebc4f3bfd18b0da0aee9cfe5
@@ -35,10 +35,10 @@
35
35
  formGroup.find('abbr').remove();
36
36
  input.parent().find('abbr').remove();
37
37
 
38
- if(input.parent().is('label')) {
38
+ if(input.parent().is('label') && input.parent().parent().hasClass('radio') == false) {
39
39
  input.after("<abbr title='required'>*</abbr> ");
40
40
  } else if(formGroup.length > 0) {
41
- formGroup.find('label').prepend("<abbr title='required'>*</abbr> ");
41
+ formGroup.find('label').first().prepend("<abbr title='required'>*</abbr> ");
42
42
  } else {
43
43
  input.parent().find('label').prepend("<abbr title='required'>*</abbr> ");
44
44
  }
@@ -43,10 +43,10 @@ module Effective
43
43
  EffectiveResources.authorized?(self, :create, resource)
44
44
 
45
45
  if resource.save
46
- flash[:success] = "Successfully created #{resource_name}"
46
+ flash[:success] = "Successfully created #{resource_human_name}"
47
47
  redirect_to(resource_redirect_path)
48
48
  else
49
- flash.now[:danger] = "Unable to create #{resource_name}: #{resource.errors.full_messages.to_sentence}"
49
+ flash.now[:danger] = "Unable to create #{resource_human_name}: #{resource.errors.full_messages.to_sentence}"
50
50
  render :new
51
51
  end
52
52
  end
@@ -72,10 +72,10 @@ module Effective
72
72
  EffectiveResources.authorized?(self, :update, resource)
73
73
 
74
74
  if resource.update_attributes(send(resource_params_method_name))
75
- flash[:success] = "Successfully updated #{resource_name}"
75
+ flash[:success] = "Successfully updated #{resource_human_name}"
76
76
  redirect_to(resource_redirect_path)
77
77
  else
78
- flash.now[:danger] = "Unable to update #{resource_name}: #{resource.errors.full_messages.to_sentence}"
78
+ flash.now[:danger] = "Unable to update #{resource_human_name}: #{resource.errors.full_messages.to_sentence}"
79
79
  render :edit
80
80
  end
81
81
  end
@@ -87,9 +87,9 @@ module Effective
87
87
  EffectiveResources.authorized?(self, :destroy, resource)
88
88
 
89
89
  if resource.destroy
90
- flash[:success] = "Successfully deleted #{resource_name}"
90
+ flash[:success] = "Successfully deleted #{resource_human_name}"
91
91
  else
92
- flash[:danger] = "Unable to delete #{resource_name}: #{resource.errors.full_messages.to_sentence}"
92
+ flash[:danger] = "Unable to delete #{resource_human_name}: #{resource.errors.full_messages.to_sentence}"
93
93
  end
94
94
 
95
95
  request.referer.present? ? redirect_to(request.referer) : redirect_to(send(resource_index_path))
@@ -132,6 +132,10 @@ module Effective
132
132
  effective_resource.name
133
133
  end
134
134
 
135
+ def resource_human_name
136
+ effective_resource.human_name
137
+ end
138
+
135
139
  def resource_plural_name # 'things'
136
140
  effective_resource.plural_name
137
141
  end
@@ -8,10 +8,6 @@ module Effective
8
8
 
9
9
  if (scanned = input.scan(/^\W*(\w+)\W*:(\w+)/).first).present?
10
10
  new(*scanned)
11
- elsif input.start_with?('#')
12
- new(nil)
13
- else
14
- new(input)
15
11
  end
16
12
  end
17
13
 
@@ -28,7 +28,7 @@ module Effective
28
28
 
29
29
  def nested_resources
30
30
  return [] unless klass.respond_to?(:reflect_on_all_associations)
31
- @nested_resources ||= klass.reflect_on_all_associations(:has_many).select { |ass| ass.options[:autosave] }
31
+ @nested_resources ||= klass.reflect_on_all_associations(:has_many).select { |ass| ass.options[:autosave] && ass.options[:class_name] != 'Effective::Attachment' }
32
32
  end
33
33
 
34
34
  def scopes
@@ -15,9 +15,13 @@ module Effective
15
15
  when String ; input
16
16
  when Symbol ; input
17
17
  when Class ; input.name
18
- when ActiveRecord::Relation ; input.klass
19
- when ActiveRecord::Reflection::AbstractReflection ; input.name
20
- when ActionDispatch::Journey::Route ; input.defaults[:controller]
18
+ when ActiveRecord::Relation
19
+ input.klass
20
+ when ActiveRecord::Reflection::AbstractReflection
21
+ @model_klass = input.klass
22
+ input.name
23
+ when ActionDispatch::Journey::Route
24
+ input.defaults[:controller]
21
25
  when nil ; raise 'expected a string or class'
22
26
  else ; input.class.name
23
27
  end.to_s.underscore
@@ -48,6 +52,7 @@ module Effective
48
52
 
49
53
  if first && last
50
54
  @written_attributes = reader.select(from: first+1, to: last-1).map do |line|
55
+
51
56
  Effective::Attribute.parse_written(line).presence
52
57
  end.compact
53
58
  end
@@ -32,7 +32,7 @@ module Effective
32
32
  end
33
33
 
34
34
  def human_name
35
- class_name.gsub('::', ' ')
35
+ class_name.gsub('::', ' ').underscore.gsub('_', ' ')
36
36
  end
37
37
 
38
38
  end
@@ -3,24 +3,41 @@ module Effective
3
3
  module Paths
4
4
 
5
5
  # Controller REST helper paths
6
- def index_path
7
- [namespace, plural_name, 'path'].compact * '_'
6
+ def index_path(check: false)
7
+ path = [namespace, plural_name, 'path'].compact * '_'
8
+ path if (!check || path_exists?(path))
8
9
  end
9
10
 
10
- def new_path
11
- ['new', namespace, name, 'path'].compact * '_'
11
+ def new_path(check: false)
12
+ path = ['new', namespace, name, 'path'].compact * '_'
13
+ path if (!check || path_exists?(path))
12
14
  end
13
15
 
14
- def show_path
15
- [namespace, name, 'path'].compact * '_'
16
+ def show_path(check: false)
17
+ path = [namespace, name, 'path'].compact * '_'
18
+ path if (!check || path_exists?(path, 1))
16
19
  end
17
20
 
18
- def edit_path
19
- ['edit', namespace, name, 'path'].compact * '_'
21
+ def destroy_path(check: false)
22
+ path = [namespace, name, 'path'].compact * '_'
23
+ path if (!check || path_exists?(path, 1, :delete))
20
24
  end
21
25
 
22
- def action_path(action)
23
- [action, namespace, name, 'path'].compact * '_'
26
+ def edit_path(check: false)
27
+ path = ['edit', namespace, name, 'path'].compact * '_'
28
+ path if (!check || path_exists?(path, 1))
29
+ end
30
+
31
+ def action_path(action, check: false)
32
+ path = [action, namespace, name, 'path'].compact * '_'
33
+ path if (!check || path_exists?(path, 1))
34
+ end
35
+
36
+ def path_exists?(path, param = nil, verb = :get)
37
+ routes = Rails.application.routes
38
+
39
+ return false unless routes.url_helpers.respond_to?(path)
40
+ (routes.recognize_path(routes.url_helpers.send(path, param), method: verb).present? rescue false)
24
41
  end
25
42
 
26
43
  # _helper methods also put in the (@thing)
@@ -34,7 +34,8 @@ module Effective
34
34
  when :effective_roles
35
35
  relation.order("#{sql_column(:roles_mask)} #{sql_direction}")
36
36
  else
37
- relation.order("#{sql_column} #{sql_direction}")
37
+ relation
38
+ .order("#{sql_column} #{sql_direction}")
38
39
  end
39
40
  end
40
41
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '0.2.3'.freeze
2
+ VERSION = '0.2.4'.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: 0.2.3
4
+ version: 0.2.4
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: 2017-02-21 00:00:00.000000000 Z
11
+ date: 2017-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails