rails_admin_settings 1.4.0 → 1.4.1

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: 2c3a2cc5a5dd0c4e77f1e05ef1447698edde1ba25344fc2e5baea2dc7c686427
4
- data.tar.gz: 753783ad33100ef2d26891da3ecb909768f2b4c9e86242d1fedd44b388ee02ec
3
+ metadata.gz: 29fd0a6b9da6e78369f829515f98217818eee87ca05f4dfc6223265f8f1f177d
4
+ data.tar.gz: bd6b04c0cdc0ba33004138e24d7ab082e020cffaa61b2efa4f28c1168ee8cd6b
5
5
  SHA512:
6
- metadata.gz: b8b2f3ac4d7218bd0840aba1965f499f5b56d4a0bb0f30a1e36cdb3ac411ab19e620cfc7c769989d66eab63fd7efd06c1a7356e21e1a3bd96e5f441ebd492ad0
7
- data.tar.gz: 306df770d677bee42028699ded628aed3339aad936837383aefa2257cfe79badbdcbcfde7c618f745dd692b2d4a1d78c2254c2622f5dcca2f3596194f98a2f78
6
+ metadata.gz: a46ecf577c6f31320bf286d48a280717ae2a199e71fbd379edd11b18eda0a364b806e247485d26660e54836254c46f4b22a44f59722d46c5fac8cdc26129f6dc
7
+ data.tar.gz: 1fc1c269cbfea981a88305204ed5b12ec9d00bd631b9687e1b42c516cddc5c5de63e91e9149bfe5c909b5965689cad12c05e5873a1206f6c7d41f17e7785bb18
data/.travis.yml CHANGED
@@ -9,12 +9,21 @@ rvm:
9
9
  - 2.5.0
10
10
 
11
11
  env:
12
- - "UPLOADS=paperclip"
13
- - "UPLOADS=carrierwave"
14
- - "RAILS=1 UPLOADS=paperclip"
15
- - "RAILS=1 UPLOADS=carrierwave"
12
+ global:
13
+ - CC_TEST_REPORTER_ID=f23ba257d0a12c588551991b4377e3eb218c1ff80050bc48c6b18c49ca16cb62
14
+ matrix:
15
+ - "UPLOADS=paperclip"
16
+ - "UPLOADS=carrierwave"
17
+ - "RAILS=1 UPLOADS=paperclip"
18
+ - "RAILS=1 UPLOADS=carrierwave"
16
19
 
17
20
  gemfile:
18
21
  - gemfiles/mongoid-6.0.gemfile
19
22
  - gemfiles/mongoid-6.3.gemfile
20
23
 
24
+ before_script:
25
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
26
+ - chmod +x ./cc-test-reporter
27
+ - ./cc-test-reporter before-build
28
+ after_script:
29
+ - ./cc-test-reporter after-build --debug --exit-code $TRAVIS_TEST_RESULT
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.4.1 (2018-03-07)
2
+
3
+ Fix activerecord + paperclip uploads
4
+ Minor code cleanup
5
+
1
6
  ## 1.4.0
2
7
 
3
8
  Add new kinds
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_admin_settings (1.4.0)
4
+ rails_admin_settings (1.4.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/rs-pro/rails_admin_settings.png?branch=master)](http://travis-ci.org/rs-pro/rails_admin_settings)
4
4
  [![Dependency Status](https://gemnasium.com/rs-pro/rails_admin_settings.svg)](https://gemnasium.com/rs-pro/rails_admin_settings)
5
+ [![Gem Version](https://badge.fury.io/rb/rails_admin_settings.svg)](https://badge.fury.io/rb/rails_admin_settings)
6
+ [![security](https://hakiri.io/github/rs-pro/rails_admin_settings/master.svg)](https://hakiri.io/github/rs-pro/rails_admin_settings/master)
7
+ [![Maintainability](https://api.codeclimate.com/v1/badges/de00cbec10559ebd2b4b/maintainability)](https://codeclimate.com/github/rs-pro/rails_admin_settings/maintainability)
8
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/de00cbec10559ebd2b4b/test_coverage)](https://codeclimate.com/github/rs-pro/rails_admin_settings/test_coverage)
5
9
 
6
10
  App settings editable via RailsAdmin with support for ActiveRecord and Mongoid.
7
11
 
@@ -134,6 +138,13 @@ Simple format types are stored in db as-is.
134
138
 
135
139
  Rails admin management for settings is supported out of the box
136
140
 
141
+ It is recommended to disable new/create page (it is not supported by design, settings are defined in ruby code).
142
+ Disable via cancan:
143
+
144
+ ```
145
+ cannot :create, RailsAdminSettings::Setting
146
+ ```
147
+
137
148
  ## Contributing
138
149
 
139
150
  1. Fork it
@@ -6,6 +6,20 @@ module RailsAdminSettings
6
6
  end
7
7
  cattr_accessor :scrubber
8
8
 
9
+ class PersistenceException < Exception
10
+ end
11
+
12
+ autoload :Mongoid, "rails_admin_settings/mongoid"
13
+ autoload :Fallback, "rails_admin_settings/fallback"
14
+ autoload :Namespaced, "rails_admin_settings/namespaced"
15
+ autoload :Processing, "rails_admin_settings/processing"
16
+ autoload :Validation, "rails_admin_settings/validation"
17
+ autoload :RequireHelpers, "rails_admin_settings/require_helpers"
18
+ autoload :RailsAdminConfig, "rails_admin_settings/rails_admin_config"
19
+ autoload :Uploads, "rails_admin_settings/uploads"
20
+ autoload :HexColorValidator, "rails_admin_settings/hex_color_validator"
21
+ autoload :Dumper, "rails_admin_settings/dumper"
22
+
9
23
  class << self
10
24
  def orm
11
25
  if defined?(::Mongoid)
@@ -22,55 +36,74 @@ module RailsAdminSettings
22
36
  def active_record?
23
37
  orm == :active_record
24
38
  end
25
- end
26
-
27
- class PersistenceException < Exception
28
- end
29
-
30
- autoload :Mongoid, "rails_admin_settings/mongoid"
31
- autoload :Fallback, "rails_admin_settings/fallback"
32
- autoload :Namespaced, "rails_admin_settings/namespaced"
33
- autoload :Processing, "rails_admin_settings/processing"
34
- autoload :Validation, "rails_admin_settings/validation"
35
- autoload :RequireHelpers, "rails_admin_settings/require_helpers"
36
- autoload :RailsAdminConfig, "rails_admin_settings/rails_admin_config"
37
- autoload :Uploads, "rails_admin_settings/uploads"
38
- autoload :HexColorValidator, "rails_admin_settings/hex_color_validator"
39
- autoload :Dumper, "rails_admin_settings/dumper"
40
39
 
41
- def self.migrate!
42
- if RailsAdminSettings.mongoid?
43
- RailsAdminSettings::Setting.where(:ns.exists => false).update_all(ns: 'main')
44
- RailsAdminSettings::Setting.all.each do |s|
45
- s.kind = s.read_attribute(:type) if !s.read_attribute(:type).blank? && s.kind != s.read_attribute(:type)
46
- s.save! if s.changed?
47
- s.unset(:type)
48
- end
49
- else
50
- if Settings.table_exists?
51
- RailsAdminSettings::Setting.where("ns IS NULL").update_all(ns: 'main')
40
+ def apply_defaults!(file, verbose = false)
41
+ if File.file?(file)
42
+ puts "[settings] Loading from #{file}" if verbose
43
+ if defined?(Psych) && Psych.respond_to?(:safe_load)
44
+ yaml = Psych.safe_load(File.read(file))
45
+ else
46
+ yaml = YAML.load(File.read(file), safe: true)
47
+ end
48
+ yaml.each_pair do |namespace, vals|
49
+ process_defaults(namespace, vals, verbose)
50
+ end
52
51
  end
53
52
  end
54
- end
55
-
56
- def self.track_history!
57
- return false unless Settings.table_exists?
58
53
 
59
- if mongoid?
60
- if ::Mongoid.const_defined?('History')
61
- RailsAdminSettings::Setting.send(:include, ::Mongoid::History::Trackable)
62
- RailsAdminSettings::Setting.send(:track_history, {track_create: true, track_destroy: true})
63
- else
64
- puts "[rails_admin_settings] WARN unable to track_history: Mongoid::History not loaded!"
54
+ def process_defaults(namespace, vals, verbose = false)
55
+ vals.symbolize_keys!
56
+ n = Settings.ns(namespace)
57
+ vals.each_pair do |key, val|
58
+ val.symbolize_keys!
59
+ if !val[:kind].nil? && (val[:kind] == 'file' || val[:kind] == 'image')
60
+ unless Settings.file_uploads_supported
61
+ raise PersistenceException, "Fatal: setting #{key} is #{val[:type]} but file upload engine is not detected"
62
+ end
63
+ value = File.open(Settings.root_file_path.join(val.delete(:value)))
64
+ else
65
+ value = val.delete(:value)
66
+ end
67
+ puts "#{key} - default '#{value}' current '#{Settings.get(key).raw}'" if verbose
68
+ n.set(key, value, val.merge(overwrite: false))
65
69
  end
66
- if ::Mongoid.const_defined?('Userstamp')
67
- RailsAdminSettings::Setting.send(:include, ::Mongoid::Userstamp)
70
+ n.unload!
71
+ end
72
+
73
+ def migrate!
74
+ if RailsAdminSettings.mongoid?
75
+ RailsAdminSettings::Setting.where(:ns.exists => false).update_all(ns: 'main')
76
+ RailsAdminSettings::Setting.all.each do |s|
77
+ s.kind = s.read_attribute(:type) if !s.read_attribute(:type).blank? && s.kind != s.read_attribute(:type)
78
+ s.save! if s.changed?
79
+ s.unset(:type)
80
+ end
68
81
  else
69
- puts "[rails_admin_settings] WARN unable to track_history: Mongoid::Userstamp not loaded!"
82
+ if Settings.table_exists?
83
+ RailsAdminSettings::Setting.where("ns IS NULL").update_all(ns: 'main')
84
+ end
70
85
  end
71
- elsif active_record?
72
- if defined?(PaperTrail) && PaperTrail::Version.table_exists?
73
- RailsAdminSettings::Setting.send(:has_paper_trail)
86
+ end
87
+
88
+ def track_history!
89
+ return false unless Settings.table_exists?
90
+
91
+ if mongoid?
92
+ if ::Mongoid.const_defined?('History')
93
+ RailsAdminSettings::Setting.send(:include, ::Mongoid::History::Trackable)
94
+ RailsAdminSettings::Setting.send(:track_history, {track_create: true, track_destroy: true})
95
+ else
96
+ puts "[rails_admin_settings] WARN unable to track_history: Mongoid::History not loaded!"
97
+ end
98
+ if ::Mongoid.const_defined?('Userstamp')
99
+ RailsAdminSettings::Setting.send(:include, ::Mongoid::Userstamp)
100
+ else
101
+ puts "[rails_admin_settings] WARN unable to track_history: Mongoid::Userstamp not loaded!"
102
+ end
103
+ elsif active_record?
104
+ if defined?(PaperTrail) && PaperTrail::Version.table_exists?
105
+ RailsAdminSettings::Setting.send(:has_paper_trail)
106
+ end
74
107
  end
75
108
  end
76
109
  end
@@ -64,32 +64,7 @@ class Settings < BasicObject
64
64
  end
65
65
 
66
66
  def apply_defaults!(file, verbose = false)
67
- if File.file?(file)
68
- puts "[settings] Loading from #{file}" if verbose
69
- if defined?(Psych) && Psych.respond_to?(:safe_load)
70
- yaml = Psych.safe_load(File.read(file))
71
- else
72
- yaml = YAML.load(File.read(file), safe: true)
73
- end
74
- yaml.each_pair do |namespace, vals|
75
- vals.symbolize_keys!
76
- n = ns(namespace)
77
- vals.each_pair do |key, val|
78
- val.symbolize_keys!
79
- if !val[:kind].nil? && (val[:kind] == 'file' || val[:kind] == 'image')
80
- unless @@file_uploads_supported
81
- ::Kernel.raise ::RailsAdminSettings::PersistenceException, "Fatal: setting #{key} is #{val[:type]} but file upload engine is not detected"
82
- end
83
- value = File.open(root_file_path.join(val.delete(:value)))
84
- else
85
- value = val.delete(:value)
86
- end
87
- puts "#{key} - default '#{value}' current '#{Settings.get(key).raw}'" if verbose
88
- n.set(key, value, val.merge(overwrite: false))
89
- end
90
- n.unload!
91
- end
92
- end
67
+ RailsAdminSettings.apply_defaults!(file, verbose)
93
68
  end
94
69
 
95
70
  def get(key, options = {})
@@ -31,7 +31,7 @@ module RailsAdminSettings
31
31
  Settings.file_uploads_supported = true
32
32
  Settings.file_uploads_engine = :paperclip
33
33
  elsif RailsAdminSettings.active_record? && defined?(Paperclip)
34
- base.has_mongoid_attached_file(:file, self.paperclip_options)
34
+ base.has_attached_file(:file, self.paperclip_options)
35
35
  if base.respond_to?(:do_not_validate_attachment_file_type)
36
36
  base.do_not_validate_attachment_file_type :file
37
37
  end
@@ -1,91 +1,122 @@
1
1
  module RailsAdminSettings
2
2
  module Validation
3
- def self.included(base)
4
- base.before_validation do
5
- self.raw = default_serializable_value if raw.blank?
3
+ class << self
4
+ def included(base)
5
+ base.before_validation do
6
+ self.raw = default_serializable_value if raw.blank?
7
+ end
8
+ base.before_validation :preprocess_value, if: :preprocessed_kind?
9
+ base.validates_uniqueness_of :key, scope: :ns
10
+ base.validates_inclusion_of :kind, in: RailsAdminSettings.kinds
11
+ base.validates_numericality_of :raw, if: :integer_kind?
12
+
13
+ add_validators(base)
6
14
  end
7
- base.before_validation :preprocess_value, if: :preprocessed_kind?
8
- base.validates_uniqueness_of :key, scope: :ns
9
- base.validates_inclusion_of :kind, in: RailsAdminSettings.kinds
10
- base.validates_numericality_of :raw, if: :integer_kind?
11
15
 
12
- base.validate if: :phone_kind? do
13
- require_russian_phone do
14
- errors.add(:raw, I18n.t('admin.settings.phone_invalid')) unless raw.blank? || RussianPhone::Number.new(raw).valid?
15
- end
16
+ def add_validators(base)
17
+ add_color_validator(base)
18
+ add_file_validator(base)
19
+ add_email_validator(base)
20
+ add_url_validator(base)
21
+ add_phone_validator(base)
22
+ add_geo_validator(base)
23
+ add_yaml_validator(base)
24
+ add_json_validator(base)
16
25
  end
17
26
 
18
- base.validate if: :phones_kind? do
19
- require_russian_phone do
20
- unless raw.blank?
21
- invalid_phones = raw.gsub("\r", '').split("\n").inject([]) do |memo, value|
22
- memo << value unless RussianPhone::Number.new(value).valid?
23
- memo
24
- end
25
- errors.add(:raw, I18n.t('admin.settings.phones_invalid', phones: invalid_phones * ', ')) unless invalid_phones.empty?
27
+ def add_color_validator(base)
28
+ base.validates_with(RailsAdminSettings::HexColorValidator, attributes: :raw, if: :color_kind?)
29
+ end
30
+
31
+ def add_file_validator(base)
32
+ base.validate if: :file_kind? do
33
+ unless Settings.file_uploads_supported
34
+ raise '[rails_admin_settings] File kind requires either CarrierWave or Paperclip. Check that rails_admin_settings is below them in Gemfile'
26
35
  end
27
36
  end
28
37
  end
29
38
 
30
- base.validate if: :email_kind? do
31
- require_validates_email_format_of do
32
- errors.add(:raw, I18n.t('admin.settings.email_invalid')) unless raw.blank? || ValidatesEmailFormatOf.validate_email_format(raw).nil?
39
+ def add_email_validator(base)
40
+ base.validate if: :email_kind? do
41
+ require_validates_email_format_of do
42
+ errors.add(:raw, I18n.t('admin.settings.email_invalid')) unless raw.blank? || ValidatesEmailFormatOf.validate_email_format(raw).nil?
43
+ end
33
44
  end
34
45
  end
35
46
 
36
- base.validate if: :address_kind? do
37
- require_geocoder do
38
- # just raise error if we are trying to use address kind without geocoder
47
+ def add_url_validator(base)
48
+ base.before_validation if: :url_kind? do
49
+ require_addressable do
50
+ self.raw = Addressable::URI.heuristic_parse(self.raw) unless self.raw.blank?
51
+ end
39
52
  end
40
- end
41
53
 
42
- base.validate if: :file_kind? do
43
- unless Settings.file_uploads_supported
44
- raise '[rails_admin_settings] File kind requires either CarrierWave or Paperclip. Check that rails_admin_settings is below them in Gemfile'
54
+ base.before_validation if: :domain_kind? do
55
+ require_addressable do
56
+ self.raw = Addressable::URI.heuristic_parse(self.raw).host unless self.raw.blank?
57
+ end
45
58
  end
46
59
  end
47
60
 
48
- base.before_validation if: :url_kind? do
49
- require_addressable do
50
- self.raw = Addressable::URI.heuristic_parse(self.raw) unless self.raw.blank?
61
+ def add_phone_validator(base)
62
+ base.validate if: :phone_kind? do
63
+ require_russian_phone do
64
+ errors.add(:raw, I18n.t('admin.settings.phone_invalid')) unless raw.blank? || RussianPhone::Number.new(raw).valid?
65
+ end
51
66
  end
52
- end
53
67
 
54
- base.before_validation if: :domain_kind? do
55
- require_addressable do
56
- self.raw = Addressable::URI.heuristic_parse(self.raw).host unless self.raw.blank?
68
+ base.validate if: :phones_kind? do
69
+ require_russian_phone do
70
+ unless raw.blank?
71
+ invalid_phones = raw.gsub("\r", '').split("\n").inject([]) do |memo, value|
72
+ memo << value unless RussianPhone::Number.new(value).valid?
73
+ memo
74
+ end
75
+ errors.add(:raw, I18n.t('admin.settings.phones_invalid', phones: invalid_phones * ', ')) unless invalid_phones.empty?
76
+ end
77
+ end
57
78
  end
79
+
58
80
  end
59
81
 
60
- if Object.const_defined?('Geocoder')
61
- if RailsAdminSettings.mongoid?
62
- base.field(:coordinates, type: Array)
63
- base.send(:include, Geocoder::Model::Mongoid)
82
+ def add_geo_validator(base)
83
+ base.validate if: :address_kind? do
84
+ require_geocoder do
85
+ # just raise error if we are trying to use address kind without geocoder
86
+ end
87
+ end
88
+ if Object.const_defined?('Geocoder')
89
+ if RailsAdminSettings.mongoid?
90
+ base.field(:coordinates, type: Array)
91
+ base.send(:include, Geocoder::Model::Mongoid)
92
+ end
93
+ base.geocoded_by(:raw)
94
+ base.after_validation(:geocode, if: :address_kind?)
64
95
  end
65
- base.geocoded_by(:raw)
66
- base.after_validation(:geocode, if: :address_kind?)
67
96
  end
68
97
 
69
- base.validates_with(RailsAdminSettings::HexColorValidator, attributes: :raw, if: :color_kind?)
70
-
71
- base.validate if: :yaml_kind? do
72
- require_safe_yaml do
73
- unless raw.blank?
74
- begin
75
- YAML.safe_load(raw)
76
- rescue Psych::SyntaxError => e
77
- errors.add(:raw, I18n.t('admin.settings.yaml_invalid'))
98
+ def add_yaml_validator(base)
99
+ base.validate if: :yaml_kind? do
100
+ require_safe_yaml do
101
+ unless raw.blank?
102
+ begin
103
+ YAML.safe_load(raw)
104
+ rescue Psych::SyntaxError => e
105
+ errors.add(:raw, I18n.t('admin.settings.yaml_invalid'))
106
+ end
78
107
  end
79
108
  end
80
109
  end
81
110
  end
82
111
 
83
- base.validate if: :json_kind? do
84
- unless raw.blank?
85
- begin
86
- JSON.load(raw)
87
- rescue JSON::ParserError => e
88
- errors.add(:raw, I18n.t('admin.settings.json_invalid'))
112
+ def add_json_validator(base)
113
+ base.validate if: :json_kind? do
114
+ unless raw.blank?
115
+ begin
116
+ JSON.load(raw)
117
+ rescue JSON::ParserError => e
118
+ errors.add(:raw, I18n.t('admin.settings.json_invalid'))
119
+ end
89
120
  end
90
121
  end
91
122
  end
@@ -1,3 +1,3 @@
1
1
  module RailsAdminSettings
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gleb Tv
@@ -271,8 +271,6 @@ extra_rdoc_files: []
271
271
  files:
272
272
  - ".gitignore"
273
273
  - ".rspec"
274
- - ".ruby-gemset"
275
- - ".ruby-version"
276
274
  - ".travis.yml"
277
275
  - CHANGELOG.md
278
276
  - Gemfile
data/.ruby-gemset DELETED
@@ -1,2 +0,0 @@
1
- rails_admin_settings
2
-
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.1.5