releaf-core 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2423ba1b1c8fb2daddb907defc0b31d60dc04e0921003588106cd2f47e517f97
4
- data.tar.gz: b6141c254dbce6a61f069049b5b43f135751f74bbdfe8464b27bb3b7c725c471
3
+ metadata.gz: cf0ce248be934f51e65b01bf42bf8fa3d46c82163f5dee629d42536e480c1dbf
4
+ data.tar.gz: 49b27b2b95128d445129d4c3d4fad7e1410ea750ef1c3235daecb0bb845ca95c
5
5
  SHA512:
6
- metadata.gz: 14ec5b3914f8f94c4e743f90f230db77c09f34658e1b0353b64c670fa481d8c8e9fdb452e6585d8ad29764c41ee7a764b19854c7c2eccfea2d94e4a3591ad4fd
7
- data.tar.gz: e676070bca61b17ddd1ebb31b362a6ec5de119328012b7ba09589b6095508be40d6b40edc4e6b5815aa387ed8f444b0390cf1d784386ebbc82cb2829a2345e48
6
+ metadata.gz: 886526531af17482e95918a74c28de9cc261d32543a6c0978556743a9bded4debbcebc1c1e420321b493dfb2124ac47e6aec03d9ec3fd9773ba3502774dbc3f7
7
+ data.tar.gz: e974d509669fe47308c49ddbbdb8c86d54a7c035af8dc1eb84e3dd16aa8261fe7a09d8484766d2c4c88d07f8f9bcbd15339da60cb7a13b92b829e4d43de97a04
@@ -174,7 +174,6 @@ class Releaf::Builders::TableBuilder
174
174
  I18n.l(value, format: format) unless value.nil?
175
175
  end
176
176
 
177
-
178
177
  def format_time_content(resource, column)
179
178
  value = column_value(resource, column)
180
179
  format = Releaf::Builders::Utilities::DateFields.date_or_time_default_format(:time)
@@ -7,10 +7,10 @@ module Releaf::ActionController::Exceptions
7
7
  end
8
8
 
9
9
  def page_not_found
10
- respond_with(nil, responder: action_responder(:page_not_found))
10
+ render "releaf/error_pages/page_not_found", status: :not_found, formats: :html
11
11
  end
12
12
 
13
13
  def access_denied
14
- respond_with(nil, responder: action_responder(:access_denied))
14
+ render "releaf/error_pages/forbidden", status: :forbidden, formats: :html
15
15
  end
16
16
  end
@@ -11,8 +11,6 @@ module Releaf::Responders
11
11
  update: Releaf::Responders::AfterSaveResponder,
12
12
  confirm_destroy: Releaf::Responders::ConfirmDestroyResponder,
13
13
  destroy: Releaf::Responders::DestroyResponder,
14
- access_denied: Releaf::Responders::AccessDeniedResponder,
15
- page_not_found: Releaf::Responders::PageNotFoundResponder,
16
14
  }
17
15
  end
18
16
 
@@ -1,4 +1,32 @@
1
- class Releaf::Settings < RailsSettings::Base
1
+ class Releaf::Settings < ActiveRecord::Base
2
+
3
+ self.table_name = table_name_prefix + "settings"
4
+
5
+ class SettingNotFound < RuntimeError; end
6
+
7
+ belongs_to :thing, polymorphic: true, optional: true
8
+
9
+ # get the value field, YAML decoded
10
+ def value
11
+ YAML.load(self[:value], permitted_classes: [DateTime, Time, Date]) if self[:value].present?
12
+ end
13
+
14
+ # set the value field, YAML encoded
15
+ def value=(new_value)
16
+ self[:value] = new_value.to_yaml
17
+ end
18
+
19
+ def rewrite_cache
20
+ Rails.cache.write(cache_key, value)
21
+ end
22
+
23
+ def expire_cache
24
+ Rails.cache.delete(cache_key)
25
+ end
26
+
27
+ def cache_key
28
+ self.class.cache_key(var, thing)
29
+ end
2
30
 
3
31
  scope :registered, -> { where(var: registered_keys, thing_type: nil, thing_id: nil).order(:var) }
4
32
 
@@ -36,4 +64,129 @@ class Releaf::Settings < RailsSettings::Base
36
64
  def self.supported_types
37
65
  [:boolean, :date, :time, :datetime, :integer, :float, :decimal, :email, :text, :textarea, :richtext]
38
66
  end
67
+
68
+ class << self
69
+ def cache_prefix(&block)
70
+ @cache_prefix = block
71
+ end
72
+
73
+ def cache_key(var_name, scope_object)
74
+ scope = ["rails_settings_cached"]
75
+ scope << @cache_prefix.call if @cache_prefix
76
+ scope << "#{scope_object.class.name}-#{scope_object.id}" if scope_object
77
+ scope << var_name.to_s
78
+ scope.join("/")
79
+ end
80
+
81
+ def [](key)
82
+ return super(key) unless rails_initialized?
83
+ val = Rails.cache.fetch(cache_key(key, @object)) do
84
+ super(key)
85
+ end
86
+ val
87
+ end
88
+
89
+ # set a setting value by [] notation
90
+ def []=(var_name, value)
91
+ super
92
+ Rails.cache.write(cache_key(var_name, @object), value)
93
+ value
94
+ end
95
+
96
+ # get or set a variable with the variable as the called method
97
+ # rubocop:disable Style/MethodMissing
98
+ def method_missing(method, *args)
99
+ method_name = method.to_s
100
+ super(method, *args)
101
+ rescue NoMethodError
102
+ # set a value for a variable
103
+ if method_name[-1] == "="
104
+ var_name = method_name.sub("=", "")
105
+ value = args.first
106
+ self[var_name] = value
107
+ else
108
+ # retrieve a value
109
+ self[method_name]
110
+ end
111
+ end
112
+
113
+ # destroy the specified settings record
114
+ def destroy(var_name)
115
+ var_name = var_name.to_s
116
+ obj = object(var_name)
117
+ raise SettingNotFound, "Setting variable \"#{var_name}\" not found" if obj.nil?
118
+
119
+ obj.destroy
120
+ true
121
+ end
122
+
123
+ # retrieve all settings as a hash (optionally starting with a given namespace)
124
+ def get_all(starting_with = nil)
125
+ vars = thing_scoped.select("var, value")
126
+ vars = vars.where("var LIKE '#{starting_with}%'") if starting_with
127
+ result = {}
128
+ vars.each { |record| result[record.var] = record.value }
129
+ result.reverse_merge!(default_settings(starting_with))
130
+ result.with_indifferent_access
131
+ end
132
+
133
+ def where(sql = nil)
134
+ vars = thing_scoped.where(sql) if sql
135
+ vars
136
+ end
137
+
138
+ # get a setting value by [] notation
139
+ def [](var_name)
140
+ val = object(var_name)
141
+ return val.value if val
142
+ end
143
+
144
+ # set a setting value by [] notation
145
+ def []=(var_name, value)
146
+ var_name = var_name.to_s
147
+
148
+ record = object(var_name) || thing_scoped.new(var: var_name)
149
+ record.value = value
150
+ record.save!
151
+
152
+ value
153
+ end
154
+
155
+ def merge!(var_name, hash_value)
156
+ raise ArgumentError unless hash_value.is_a?(Hash)
157
+
158
+ old_value = self[var_name] || {}
159
+ raise TypeError, "Existing value is not a hash, can't merge!" unless old_value.is_a?(Hash)
160
+
161
+ new_value = old_value.merge(hash_value)
162
+ self[var_name] = new_value if new_value != old_value
163
+
164
+ new_value
165
+ end
166
+
167
+ def object(var_name)
168
+ return nil unless table_exists?
169
+ thing_scoped.where(var: var_name.to_s).first
170
+ end
171
+
172
+ def thing_scoped
173
+ unscoped.where("thing_type is NULL and thing_id is NULL")
174
+ end
175
+
176
+ def source(filename)
177
+ Default.source(filename)
178
+ end
179
+
180
+ def rails_initialized?
181
+ Rails.application && Rails.application.initialized?
182
+ end
183
+
184
+ private
185
+
186
+ def default_settings(starting_with = nil)
187
+ return {} unless Default.enabled?
188
+ return Default.instance if starting_with.nil?
189
+ Default.instance.select { |key, _| key.to_s.start_with?(starting_with) }
190
+ end
191
+ end
39
192
  end
@@ -0,0 +1,3 @@
1
+ ---
2
+ # Custom Releaf settings should be added here
3
+ {}
@@ -1,8 +1,16 @@
1
1
  module Releaf::Root
2
2
  class SettingsManager
3
+ CAST_MAP = {
4
+ "false" => false,
5
+ "true" => true,
6
+ }
3
7
 
4
8
  def self.read(controller:, key:)
5
- controller.send(:cookies)[key]
9
+ value = controller.send(:cookies)[key]
10
+
11
+ return CAST_MAP[value] if CAST_MAP.key? value
12
+
13
+ value
6
14
  end
7
15
 
8
16
  def self.write(controller:, key:, value:)
data/lib/releaf-core.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'rails-settings-cached'
2
1
  require 'ckeditor_rails'
3
2
  require 'will_paginate'
4
3
  require 'font-awesome-rails'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: releaf-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - CubeSystems
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-24 00:00:00.000000000 Z
11
+ date: 2022-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -179,33 +179,33 @@ dependencies:
179
179
  - !ruby/object:Gem::Version
180
180
  version: '1.4'
181
181
  - !ruby/object:Gem::Dependency
182
- name: dragonfly
182
+ name: net-smtp
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: '1.0'
187
+ version: '0.3'
188
188
  type: :runtime
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: '1.0'
194
+ version: '0.3'
195
195
  - !ruby/object:Gem::Dependency
196
- name: rails-settings-cached
196
+ name: dragonfly
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: '0.4'
201
+ version: '1.0'
202
202
  type: :runtime
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
- version: '0.4'
208
+ version: '1.0'
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: ckeditor_rails
211
211
  requirement: !ruby/object:Gem::Requirement
@@ -254,14 +254,14 @@ dependencies:
254
254
  requirements:
255
255
  - - "~>"
256
256
  - !ruby/object:Gem::Version
257
- version: '4.6'
257
+ version: '4.0'
258
258
  type: :runtime
259
259
  prerelease: false
260
260
  version_requirements: !ruby/object:Gem::Requirement
261
261
  requirements:
262
262
  - - "~>"
263
263
  - !ruby/object:Gem::Version
264
- version: '4.6'
264
+ version: '4.0'
265
265
  - !ruby/object:Gem::Dependency
266
266
  name: globalize
267
267
  requirement: !ruby/object:Gem::Requirement
@@ -801,12 +801,9 @@ files:
801
801
  - app/lib/releaf/resource_table_fields.rb
802
802
  - app/lib/releaf/resource_utilities.rb
803
803
  - app/lib/releaf/responders.rb
804
- - app/lib/releaf/responders/access_denied_responder.rb
805
804
  - app/lib/releaf/responders/after_save_responder.rb
806
805
  - app/lib/releaf/responders/confirm_destroy_responder.rb
807
806
  - app/lib/releaf/responders/destroy_responder.rb
808
- - app/lib/releaf/responders/error_responder.rb
809
- - app/lib/releaf/responders/page_not_found_responder.rb
810
807
  - app/lib/releaf/search.rb
811
808
  - app/lib/releaf/settings/normalize_value.rb
812
809
  - app/lib/releaf/settings/register.rb
@@ -823,7 +820,7 @@ files:
823
820
  - app/views/releaf/action/show.ruby
824
821
  - app/views/releaf/action/toolbox.ruby
825
822
  - app/views/releaf/error_pages/_error.html.haml
826
- - app/views/releaf/error_pages/access_denied.html.haml
823
+ - app/views/releaf/error_pages/forbidden.html.haml
827
824
  - app/views/releaf/error_pages/page_not_found.html.haml
828
825
  - lib/generators/dummy/install_generator.rb
829
826
  - lib/generators/dummy/templates/assets/config/manifest.js
@@ -883,6 +880,7 @@ files:
883
880
  - lib/generators/dummy/templates/views/layouts/application.html.haml
884
881
  - lib/generators/dummy/templates/views/text_pages/show.haml
885
882
  - lib/generators/releaf/install_generator.rb
883
+ - lib/generators/releaf/templates/config/app.yml
886
884
  - lib/generators/releaf/templates/initializers/haml.rb
887
885
  - lib/generators/releaf/templates/initializers/releaf.rb
888
886
  - lib/generators/releaf/templates/migrations/create_releaf_nodes.rb
@@ -931,7 +929,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
931
929
  - !ruby/object:Gem::Version
932
930
  version: '0'
933
931
  requirements: []
934
- rubygems_version: 3.1.4
932
+ rubygems_version: 3.3.7
935
933
  signing_key:
936
934
  specification_version: 4
937
935
  summary: core gem for releaf
@@ -1,9 +0,0 @@
1
- module Releaf::Responders
2
- class AccessDeniedResponder < ActionController::Responder
3
- include Releaf::Responders::ErrorResponder
4
-
5
- def status_code
6
- 403
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module Releaf::Responders::ErrorResponder
2
- def template
3
- self.class.name.split("::").last.gsub(/Responder$/, "").underscore
4
- end
5
-
6
- def to_html
7
- render "releaf/error_pages/#{template}", status: status_code
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module Releaf::Responders
2
- class PageNotFoundResponder < ActionController::Responder
3
- include Releaf::Responders::ErrorResponder
4
-
5
- def status_code
6
- 404
7
- end
8
- end
9
- end