releaf-core 2.0.1 → 2.1.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: 24550823b36995857b4010fe0adfab5d436046b9fb8b865dff703aae8fa5d18e
4
- data.tar.gz: '0340851de16d3076de35a0993c4578c789ddee11ca51fca80b06105d83d50ca9'
3
+ metadata.gz: 2423ba1b1c8fb2daddb907defc0b31d60dc04e0921003588106cd2f47e517f97
4
+ data.tar.gz: b6141c254dbce6a61f069049b5b43f135751f74bbdfe8464b27bb3b7c725c471
5
5
  SHA512:
6
- metadata.gz: 60637a9594b76ebba5401ea3a6717373c55b8786eea8eae274617c6247d114dd83837697ae3e14aa3baaab7463b2c52b8307ac9f512deec395508982ae37cbfc
7
- data.tar.gz: bcec5f12fce19dde4f7229040811a1b44b4aa00182351d8a88a989b4b407b23ce594895c13ed73a96895461b9ad24cbdeb3ade8e4ed35277f4fb594724c0ec2c
6
+ metadata.gz: 14ec5b3914f8f94c4e743f90f230db77c09f34658e1b0353b64c670fa481d8c8e9fdb452e6585d8ad29764c41ee7a764b19854c7c2eccfea2d94e4a3591ad4fd
7
+ data.tar.gz: e676070bca61b17ddd1ebb31b362a6ec5de119328012b7ba09589b6095508be40d6b40edc4e6b5815aa387ed8f444b0390cf1d784386ebbc82cb2829a2345e48
@@ -59,7 +59,7 @@ module Releaf::Builders::Base
59
59
 
60
60
  def t(key, options = {})
61
61
  options[:scope] = default_translation_scope unless options.key? :scope
62
- I18n.t(key, options)
62
+ I18n.t(key, **options)
63
63
  end
64
64
 
65
65
  def translate_locale(locale)
@@ -19,7 +19,7 @@ module Releaf
19
19
  def translate(key, options = {})
20
20
  # prevent I18n from raising errors when translation is missing
21
21
  options.merge!(raise: false) unless options.key?(:raise)
22
- super(key, options)
22
+ super(key, **options)
23
23
  end
24
24
  alias :t :translate
25
25
 
@@ -30,7 +30,7 @@ module Releaf
30
30
 
31
31
  container.each do|element|
32
32
  text, value = i18n_option_text_and_value(element).map { |item| item.to_s }
33
- text = I18n.t("#{prefix}-#{text}", i18n_options.merge(default: text))
33
+ text = I18n.t("#{prefix}-#{text}", **i18n_options.merge(default: text))
34
34
  translated_container << [text, value]
35
35
  end
36
36
 
@@ -4,7 +4,7 @@ module Releaf::ActionController::Features
4
4
  included do
5
5
  before_action :verify_feature_availability!
6
6
  helper_method :feature_available?
7
- rescue_from Releaf::FeatureDisabled, with: :feature_disabled
7
+ rescue_from Releaf::FeatureDisabled, with: :access_denied
8
8
  end
9
9
 
10
10
  def verify_feature_availability!
@@ -33,11 +33,6 @@ module Releaf::ActionController::Features
33
33
  }
34
34
  end
35
35
 
36
- def feature_disabled(exception)
37
- @feature = exception.message
38
- respond_with(nil, responder: action_responder(:feature_disabled))
39
- end
40
-
41
36
  def feature_available?(feature)
42
37
  return false if feature.blank?
43
38
  return false if feature == :create_another && !feature_available?(:create)
@@ -8,30 +8,30 @@ module Releaf
8
8
  errors.inject({}) do |h, item|
9
9
  field_name = item.delete(:field_name)
10
10
  h[field_name] ||= []
11
- h[field_name] << item
11
+ # filter out nested item duplicate errors due to #nested_attribute_errors functionality
12
+ # that returns all errors on each objects
13
+ h[field_name] << item if h[field_name].none?{|error| error == item}
12
14
  h
13
15
  end
14
16
  end
15
17
 
16
18
  def errors
17
- resource.errors.map do |attribute, message|
18
- format_error(attribute, message)
19
- end.flatten
19
+ resource.errors.map{|error| format_error(error) }.flatten
20
20
  end
21
21
 
22
- def attribute_error(attribute, message)
22
+ def attribute_error(error)
23
23
  {
24
- field_name: field_name(attribute),
25
- error_code: message.error_code,
26
- message: message.to_s,
24
+ field_name: field_name(error.attribute),
25
+ error_code: error.type,
26
+ message: error.message.to_s,
27
27
  }
28
28
  end
29
29
 
30
- def format_error(attribute, message)
31
- if resource_attribute?(attribute)
32
- attribute_error(attribute, message)
30
+ def format_error(error)
31
+ if resource_attribute?(error.attribute)
32
+ attribute_error(error)
33
33
  else
34
- nested_attribute_errors(attribute)
34
+ nested_attribute_errors(error.attribute)
35
35
  end
36
36
  end
37
37
 
@@ -12,7 +12,6 @@ module Releaf::Responders
12
12
  confirm_destroy: Releaf::Responders::ConfirmDestroyResponder,
13
13
  destroy: Releaf::Responders::DestroyResponder,
14
14
  access_denied: Releaf::Responders::AccessDeniedResponder,
15
- feature_disabled: Releaf::Responders::FeatureDisabledResponder,
16
15
  page_not_found: Releaf::Responders::PageNotFoundResponder,
17
16
  }
18
17
  end
@@ -1 +1 @@
1
- = render 'releaf/error_pages/error', message: t('You are not authorized to access %{controller}', controller: controller_name, default: 'You are not authorized to access %{controller}', scope: controller_scope_name)
1
+ = render 'releaf/error_pages/error', message: t('You are not authorized to view this page', scope: controller_scope_name)
@@ -11,7 +11,6 @@ require 'acts_as_list'
11
11
  require 'dragonfly'
12
12
  require 'globalize'
13
13
  require 'virtus'
14
- require 'globalize-accessors'
15
14
 
16
15
  module Releaf
17
16
  module Core
@@ -30,7 +29,7 @@ module Releaf
30
29
  require 'releaf/route_mapper'
31
30
  require 'releaf/exceptions'
32
31
  require 'releaf/core_ext/array/reorder'
33
- require 'releaf/rails_ext/validation_error_codes'
32
+ require 'releaf/rails_ext/globalize-accessors'
34
33
 
35
34
  def self.components
36
35
  [Releaf::SettingsUI, Releaf::Root]
@@ -0,0 +1,64 @@
1
+ require 'globalize'
2
+
3
+ module Globalize::Accessors
4
+ def globalize_accessors(options = {})
5
+ options.reverse_merge!(:locales => I18n.available_locales, :attributes => translated_attribute_names)
6
+ class_attribute :globalize_locales, :globalize_attribute_names, :instance_writer => false
7
+
8
+ self.globalize_locales = options[:locales]
9
+ self.globalize_attribute_names = []
10
+
11
+ each_attribute_and_locale(options) do |attr_name, locale|
12
+ define_accessors(attr_name, locale)
13
+ end
14
+
15
+ include InstanceMethods
16
+ end
17
+
18
+ def localized_attr_name_for(attr_name, locale)
19
+ "#{attr_name}_#{locale.to_s.underscore}"
20
+ end
21
+
22
+ private
23
+
24
+ def define_accessors(attr_name, locale)
25
+ define_getter(attr_name, locale)
26
+ define_setter(attr_name, locale)
27
+ end
28
+
29
+ def define_getter(attr_name, locale)
30
+ define_method localized_attr_name_for(attr_name, locale) do
31
+ globalize.stash.contains?(locale, attr_name) ? globalize.send(:fetch_stash, locale, attr_name) : globalize.send(:fetch_attribute, locale, attr_name)
32
+ end
33
+ end
34
+
35
+ def define_setter(attr_name, locale)
36
+ localized_attr_name = localized_attr_name_for(attr_name, locale)
37
+
38
+ define_method :"#{localized_attr_name}=" do |value|
39
+ attribute_will_change!(localized_attr_name) if value != send(localized_attr_name)
40
+ write_attribute(attr_name, value, :locale => locale)
41
+ translation_for(locale)[attr_name] = value
42
+ end
43
+ if respond_to?(:accessible_attributes) && accessible_attributes.include?(attr_name)
44
+ attr_accessible :"#{localized_attr_name}"
45
+ end
46
+ self.globalize_attribute_names << localized_attr_name.to_sym
47
+ end
48
+
49
+ def each_attribute_and_locale(options)
50
+ options[:attributes].each do |attr_name|
51
+ options[:locales].each do |locale|
52
+ yield attr_name, locale
53
+ end
54
+ end
55
+ end
56
+
57
+ module InstanceMethods
58
+ def localized_attr_name_for(attr_name, locale)
59
+ self.class.localized_attr_name_for(attr_name, locale)
60
+ end
61
+ end
62
+ end
63
+
64
+ ActiveRecord::Base.extend Globalize::Accessors
@@ -1,36 +0,0 @@
1
- module ActiveModel
2
- class ErrorMessage < String
3
- attr_accessor :error_code, :data
4
-
5
- def initialize(message, error_code = nil, data = nil)
6
- super message
7
- @error_code = error_code
8
- @data = data
9
- end
10
- end
11
-
12
- class Errors
13
- def add(attribute, message = nil, options = {})
14
- # build error code from message symbol
15
- error_code = normalize_error_code(attribute, message, options)
16
- message = normalize_message(attribute, message, options)
17
- if exception = options[:strict]
18
- exception = ActiveModel::StrictValidationFailed if exception == true
19
- raise exception, full_message(attribute, message)
20
- end
21
-
22
- # use customized String subclass with "error_code" attribute
23
- self[attribute] << ErrorMessage.new(message, error_code, options[:data])
24
- end
25
-
26
- def normalize_error_code(_attribute, message, options)
27
- if !options[:error_code].blank?
28
- options[:error_code]
29
- elsif message.class == Symbol
30
- message
31
- else
32
- :invalid
33
- end
34
- end
35
- end
36
- end
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.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - CubeSystems
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-14 00:00:00.000000000 Z
11
+ date: 2021-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '6.0'
19
+ version: '6.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '6.0'
26
+ version: '6.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '6.0'
33
+ version: '6.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '6.0'
40
+ version: '6.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activerecord
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '6.0'
47
+ version: '6.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '6.0'
54
+ version: '6.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: i18n
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -268,28 +268,14 @@ dependencies:
268
268
  requirements:
269
269
  - - "~>"
270
270
  - !ruby/object:Gem::Version
271
- version: '5.3'
272
- type: :runtime
273
- prerelease: false
274
- version_requirements: !ruby/object:Gem::Requirement
275
- requirements:
276
- - - "~>"
277
- - !ruby/object:Gem::Version
278
- version: '5.3'
279
- - !ruby/object:Gem::Dependency
280
- name: globalize-accessors
281
- requirement: !ruby/object:Gem::Requirement
282
- requirements:
283
- - - "~>"
284
- - !ruby/object:Gem::Version
285
- version: 0.2.1
271
+ version: '6.0'
286
272
  type: :runtime
287
273
  prerelease: false
288
274
  version_requirements: !ruby/object:Gem::Requirement
289
275
  requirements:
290
276
  - - "~>"
291
277
  - !ruby/object:Gem::Version
292
- version: 0.2.1
278
+ version: '6.0'
293
279
  - !ruby/object:Gem::Dependency
294
280
  name: rack-cache
295
281
  requirement: !ruby/object:Gem::Requirement
@@ -820,7 +806,6 @@ files:
820
806
  - app/lib/releaf/responders/confirm_destroy_responder.rb
821
807
  - app/lib/releaf/responders/destroy_responder.rb
822
808
  - app/lib/releaf/responders/error_responder.rb
823
- - app/lib/releaf/responders/feature_disabled_responder.rb
824
809
  - app/lib/releaf/responders/page_not_found_responder.rb
825
810
  - app/lib/releaf/search.rb
826
811
  - app/lib/releaf/settings/normalize_value.rb
@@ -839,7 +824,6 @@ files:
839
824
  - app/views/releaf/action/toolbox.ruby
840
825
  - app/views/releaf/error_pages/_error.html.haml
841
826
  - app/views/releaf/error_pages/access_denied.html.haml
842
- - app/views/releaf/error_pages/feature_disabled.html.haml
843
827
  - app/views/releaf/error_pages/page_not_found.html.haml
844
828
  - lib/generators/dummy/install_generator.rb
845
829
  - lib/generators/dummy/templates/assets/config/manifest.js
@@ -918,6 +902,7 @@ files:
918
902
  - lib/releaf/engine.rb
919
903
  - lib/releaf/exceptions.rb
920
904
  - lib/releaf/instance_cache.rb
905
+ - lib/releaf/rails_ext/globalize-accessors.rb
921
906
  - lib/releaf/rails_ext/validation_error_codes.rb
922
907
  - lib/releaf/root.rb
923
908
  - lib/releaf/root/configuration.rb
@@ -946,7 +931,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
946
931
  - !ruby/object:Gem::Version
947
932
  version: '0'
948
933
  requirements: []
949
- rubygems_version: 3.0.8
934
+ rubygems_version: 3.1.4
950
935
  signing_key:
951
936
  specification_version: 4
952
937
  summary: core gem for releaf
@@ -1,9 +0,0 @@
1
- module Releaf::Responders
2
- class FeatureDisabledResponder < ActionController::Responder
3
- include Releaf::Responders::ErrorResponder
4
-
5
- def status_code
6
- 403
7
- end
8
- end
9
- end
@@ -1 +0,0 @@
1
- = render 'releaf/error_pages/error', message: t('%{feature} feature disabled for %{controller}', feature: @feature, controller: controller_name, scope: controller_scope_name, default: '%{feature} feature disabled for %{controller}')