effective_resources 1.4.11 → 1.5.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
  SHA256:
3
- metadata.gz: 32323055f3cf20452972cf11e64f696a64eb240bee54990e71a41a0179db8ce8
4
- data.tar.gz: 0f3612b1b220e6011c2d7094be638886a6689ab8273555cefc94552afb285361
3
+ metadata.gz: cbff7f74429b0acf21d35b75cb64e6fedcdb4b35c2e62080c530d7416dd1d05c
4
+ data.tar.gz: 392c8953a3cd59673d093c9fb8c8160951d54866c293e4f7f200d358503e0aab
5
5
  SHA512:
6
- metadata.gz: a8b4bfa9a2a682de256222b9e2961be1ba178f44731acba3860e41cd7a030dea93bcc920b863351335f35f05ab473ef613982c4182319e42b73fe9b699e43854
7
- data.tar.gz: 939a5f4e51b5865c4d70c0627edd747c0d2c7c5477d97b9b75ee05e60b3a0a3b304c6890892898302e70d96e860a4e986e3ebe53ff60f8817c3a68a4d5fee88c
6
+ metadata.gz: 24f6a3cc4b8ab73cfd180e79f45ab609fd6cb3af7ef76f24c07b272c82d6ee1087203e76e09f2113e217975f1d29cd550930a99cd82197ccd18985a5f1faa1b0
7
+ data.tar.gz: 1b3c4ef600b6aae43357764d6d908141f13453853fb7645ed11bf58f136dcb2265e16fadbaed9cfd627dd1a6d557fe4f14f1a24021e66491e072ad676e174a3e
@@ -63,9 +63,11 @@ module Effective
63
63
  self.resource ||= resource_scope.new
64
64
  action = (commit_action[:action] == :save ? :create : commit_action[:action])
65
65
 
66
- resource.assign_attributes(send(resource_params_method_name))
66
+ resource.current_user ||= current_user if resource.respond_to?(:current_user=)
67
67
  resource.created_by ||= current_user if resource.respond_to?(:created_by=)
68
68
 
69
+ resource.assign_attributes(send(resource_params_method_name))
70
+
69
71
  EffectiveResources.authorize!(self, action, resource)
70
72
  @page_title ||= "New #{resource_name.titleize}"
71
73
 
@@ -119,6 +121,9 @@ module Effective
119
121
  EffectiveResources.authorize!(self, action, resource)
120
122
  @page_title ||= "Edit #{resource}"
121
123
 
124
+ resource.current_user ||= current_user if resource.respond_to?(:current_user=)
125
+ resource.updated_by ||= current_user if resource.respond_to?(:updated_by=)
126
+
122
127
  resource.assign_attributes(send(resource_params_method_name))
123
128
 
124
129
  if save_resource(resource, action)
@@ -146,6 +146,30 @@ module EffectiveResourcesHelper
146
146
  end
147
147
  end
148
148
 
149
+ # Similar to render_resource_form
150
+ def render_resource_partial(resource, atts = {})
151
+ unless resource.kind_of?(ActiveRecord::Base) || resource.class.ancestors.include?(ActiveModel::Model)
152
+ raise 'expected first argument to be an ActiveRecord or ActiveModel object'
153
+ end
154
+
155
+ raise 'expected attributes to be a Hash' unless atts.kind_of?(Hash)
156
+
157
+ effective_resource = (atts.delete(:effective_resource) || find_effective_resource)
158
+
159
+ action = atts.delete(:action)
160
+ atts = { :namespace => (effective_resource.namespace.to_sym if effective_resource.namespace), effective_resource.name.to_sym => resource }.compact.merge(atts)
161
+
162
+ if lookup_context.template_exists?(effective_resource.name, controller._prefixes, :partial)
163
+ render(effective_resource.name, atts)
164
+ elsif lookup_context.template_exists?(effective_resource.name, [effective_resource.plural_name], :partial)
165
+ render(effective_resource.plural_name + '/' + effective_resource.name, atts)
166
+ elsif lookup_context.template_exists?(effective_resource.name, [effective_resource.name], :partial)
167
+ render(effective_resource.name + '/' + effective_resource.name, atts)
168
+ else
169
+ render(resource, atts) # Will raise the regular error
170
+ end
171
+ end
172
+
149
173
  # Tableize attributes
150
174
  # This is used by effective_orders, effective_logging, effective_trash and effective_mergery
151
175
  def tableize_hash(obj, table: 'table', th: true, sub_table: 'table', sub_th: true, flatten: true)
@@ -51,4 +51,3 @@ module ActsAsTokened
51
51
  end
52
52
 
53
53
  end
54
-
@@ -44,6 +44,7 @@ module Effective
44
44
  when :string ; :string
45
45
  when :text ; :string
46
46
  when :time ; :time
47
+ when :uuid ; :uuid
47
48
  when FalseClass ; :boolean
48
49
  when (defined?(Integer) ? Integer : Fixnum) ; :integer
49
50
  when Float ; :decimal
@@ -75,11 +76,11 @@ module Effective
75
76
  when :date, :datetime
76
77
  if (digits = value.to_s.scan(/(\d+)/).flatten).present?
77
78
  date = if digits.first.length == 4 # 2017-01-10
78
- Time.zone.local(*digits)
79
+ (Time.zone.local(*digits) rescue nil)
79
80
  else # 01/10/2016
80
81
  year = digits.find { |d| d.length == 4}
81
82
  digits = [year] + (digits - [year])
82
- Time.zone.local(*digits)
83
+ (Time.zone.local(*digits) rescue nil)
83
84
  end
84
85
 
85
86
  name.to_s.start_with?('end_') ? date.end_of_day : date
@@ -87,7 +88,7 @@ module Effective
87
88
  when :time
88
89
  if (digits = value.to_s.scan(/(\d+)/).flatten).present?
89
90
  now = Time.zone.now
90
- Time.zone.local(now.year, now.month, now.day, *digits)
91
+ (Time.zone.local(now.year, now.month, now.day, *digits) rescue nil)
91
92
  end
92
93
  when :decimal, :currency
93
94
  (value.kind_of?(String) ? value.gsub(/[^0-9|\-|\.]/, '') : value).to_f
@@ -139,6 +140,8 @@ module Effective
139
140
  value.to_s
140
141
  end
141
142
  end
143
+ when :uuid
144
+ value.to_s
142
145
  when :active_storage
143
146
  value.to_s
144
147
  else
@@ -1,6 +1,9 @@
1
1
  module Effective
2
2
  class ModelReader
3
- DATATYPES = [:binary, :boolean, :date, :datetime, :decimal, :float, :hstore, :inet, :integer, :string, :text, :permitted_param]
3
+ DATATYPES = [
4
+ :binary, :boolean, :date, :datetime, :decimal, :float, :hstore, :inet, :integer,
5
+ :string, :text, :uuid, :permitted_param
6
+ ]
4
7
 
5
8
  attr_reader :attributes
6
9
 
@@ -26,7 +26,10 @@ module Effective
26
26
 
27
27
  def has_ones
28
28
  return [] unless klass.respond_to?(:reflect_on_all_associations)
29
- klass.reflect_on_all_associations(:has_one).reject { |ass| ass.class_name.to_s.start_with?('ActiveStorage::') }
29
+
30
+ blacklist = ['ActiveStorage::', 'ActionText::']
31
+
32
+ klass.reflect_on_all_associations(:has_one).reject { |ass| blacklist.any? { |val| ass.class_name.start_with?(val) } }
30
33
  end
31
34
 
32
35
  def has_ones_ids
@@ -66,6 +69,14 @@ module Effective
66
69
  active_storage_has_ones.map { |ass| ass.name.to_s.gsub(/_attachment\z/, '').to_sym }
67
70
  end
68
71
 
72
+ def active_texts
73
+ klass.reflect_on_all_associations(:has_one).select { |ass| ass.class_name == 'ActionText::RichText' }
74
+ end
75
+
76
+ def active_texts_has_ones_ids
77
+ active_texts.map { |ass| ass.name.to_s.gsub(/\Arich_text_/, '').to_sym }
78
+ end
79
+
69
80
  def nested_resources
70
81
  return [] unless klass.respond_to?(:reflect_on_all_associations)
71
82
  klass.reflect_on_all_associations(:has_many).select { |ass| ass.options[:autosave] } +
@@ -153,7 +164,3 @@ module Effective
153
164
  end
154
165
  end
155
166
  end
156
-
157
-
158
-
159
-
@@ -52,6 +52,12 @@ module Effective
52
52
  end
53
53
  end
54
54
 
55
+ def active_text_attributes
56
+ {}.tap do |retval|
57
+ active_texts_has_ones_ids.each { |k, v| retval[k] = [:string] }
58
+ end
59
+ end
60
+
55
61
  # All will include primary_key, created_at, updated_at and belongs_tos
56
62
  # This is the attributes as defined by the effective_resources do .. end block
57
63
  # { :name => [:string, { permitted: false }], ... }
@@ -66,6 +72,7 @@ module Effective
66
72
  .merge(effective_addresses_attributes)
67
73
  .merge(effective_assets_attributes)
68
74
  .merge(active_storage_attributes)
75
+ .merge(active_text_attributes)
69
76
  .merge(atts)
70
77
  else # This is the migrator. This should match table_attributes
71
78
  belong_tos_attributes.merge(atts.reject { |_, v| v[0] == :permitted_param })
@@ -137,7 +144,3 @@ module Effective
137
144
  end
138
145
  end
139
146
  end
140
-
141
-
142
-
143
-
@@ -158,6 +158,12 @@ module Effective
158
158
  else
159
159
  relation.where("#{sql_column} = ?", term)
160
160
  end
161
+ when :uuid
162
+ if fuzzy
163
+ relation.where("#{sql_column}::text #{ilike} ?", "%#{term}%")
164
+ else
165
+ relation.where("#{sql_column}::text = ?", term)
166
+ end
161
167
  else
162
168
  raise "unsupported sql type #{sql_type}"
163
169
  end
@@ -8,7 +8,7 @@
8
8
  .col-4.text-right
9
9
  = render_resource_buttons(@resource, show: false)
10
10
 
11
- = render @resource
11
+ = render_resource_partial(@resource)
12
12
 
13
13
  .form-actions
14
14
  = link_to 'Continue', (resource.action_path(:index) || root_path), class: 'btn btn-primary'
@@ -1,6 +1,6 @@
1
1
  <% resource = (@_effective_resource || Effective::Resource.new(controller_path)) %>
2
2
  <% @resource = instance_variable_get('@' + resource.name) if resource.name %>
3
3
 
4
- EffectiveForm.remote_form_payload = "<%= j render(@resource) %>";
4
+ EffectiveForm.remote_form_payload = "<%= j render_resource_partial(@resource) %>";
5
5
  EffectiveForm.remote_form_commit = "<%= params[:commit] %>";
6
6
  EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
@@ -1,5 +1,4 @@
1
1
  require 'effective_resources/engine'
2
- require 'effective_resources/version'
3
2
 
4
3
  module EffectiveResources
5
4
 
@@ -3,9 +3,14 @@ module EffectiveResources
3
3
  engine_name 'effective_resources'
4
4
 
5
5
  config.autoload_paths += Dir[
6
- "#{config.root}/lib/",
7
6
  "#{config.root}/jobs/",
8
- "#{config.root}/app/models/validators/",
7
+ "#{config.root}/lib/validators/",
8
+ "#{config.root}/app/controllers/concerns/"
9
+ ]
10
+
11
+ config.eager_load_paths += Dir[
12
+ "#{config.root}/jobs/",
13
+ "#{config.root}/lib/validators/",
9
14
  "#{config.root}/app/controllers/concerns/"
10
15
  ]
11
16
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.4.11'.freeze
2
+ VERSION = '1.5.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.4.11
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-11 00:00:00.000000000 Z
11
+ date: 2020-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -71,9 +71,6 @@ files:
71
71
  - app/models/effective/resources/paths.rb
72
72
  - app/models/effective/resources/relation.rb
73
73
  - app/models/effective/resources/sql.rb
74
- - app/models/validators/email_cc_validator.rb
75
- - app/models/validators/email_validator.rb
76
- - app/models/validators/url_validator.rb
77
74
  - app/views/application/_flash.html.haml
78
75
  - app/views/application/create.js.erb
79
76
  - app/views/application/destroy.js.erb
@@ -94,11 +91,14 @@ files:
94
91
  - lib/effective_resources/engine.rb
95
92
  - lib/effective_resources/version.rb
96
93
  - lib/generators/effective_resources/install_generator.rb
94
+ - lib/validators/email_cc_validator.rb
95
+ - lib/validators/email_validator.rb
96
+ - lib/validators/url_validator.rb
97
97
  homepage: https://github.com/code-and-effect/effective_resources
98
98
  licenses:
99
99
  - MIT
100
100
  metadata: {}
101
- post_install_message:
101
+ post_install_message:
102
102
  rdoc_options: []
103
103
  require_paths:
104
104
  - lib
@@ -113,8 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  requirements: []
116
- rubygems_version: 3.0.3
117
- signing_key:
116
+ rubygems_version: 3.1.4
117
+ signing_key:
118
118
  specification_version: 4
119
119
  summary: Make any controller an effective resource controller.
120
120
  test_files: []