thecore_settings 1.1.15 → 2.0.5

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +20 -0
  3. data/.devcontainer/devcontainer.json +33 -0
  4. data/.github/workflows/gempush.yml +34 -0
  5. data/.gitignore +542 -0
  6. data/.rakeTasks +7 -0
  7. data/.rspec +1 -0
  8. data/.ruby-version +1 -0
  9. data/.travis.yml +31 -0
  10. data/CHANGELOG.md +81 -0
  11. data/Gemfile +4 -0
  12. data/Gemfile.lock +275 -0
  13. data/LICENSE.txt +22 -0
  14. data/README.md +169 -0
  15. data/README.rdoc +68 -0
  16. data/Rakefile +6 -34
  17. data/app/{assets/config/thecore_settings_manifest.js → models/.keep} +0 -0
  18. data/app/models/thecore_settings/setting.rb +77 -0
  19. data/app/views/.keep +0 -0
  20. data/app/views/rails_admin/main/_setting_value.html.haml +41 -0
  21. data/bin/rails +13 -0
  22. data/config/locales/en.yml +29 -0
  23. data/config/locales/{thecore_settings.it.yml → it.yml} +2 -2
  24. data/config/locales/pt-BR.yml +28 -0
  25. data/config/locales/ru.yml +29 -0
  26. data/db/migrate/20161227101954_create_rails_admin_settings.rb +4 -4
  27. data/gemfiles/mongoid-6.0.gemfile +5 -0
  28. data/gemfiles/mongoid-6.3.gemfile +5 -0
  29. data/lib/generators/thecore_settings/migration_generator.rb +15 -0
  30. data/lib/generators/thecore_settings/templates/db/migrate/20161227101954_create_thecore_settings.rb +29 -0
  31. data/lib/generators/thecore_settings/templates/migration.rb +29 -0
  32. data/lib/thecore_settings/determine_mime_type.rb +193 -0
  33. data/lib/thecore_settings/dumper.rb +12 -0
  34. data/lib/thecore_settings/engine.rb +17 -3
  35. data/lib/thecore_settings/fallback.rb +21 -0
  36. data/lib/thecore_settings/hex_color_validator.rb +11 -0
  37. data/lib/thecore_settings/kinds.rb +34 -0
  38. data/lib/thecore_settings/mongoid.rb +19 -0
  39. data/lib/thecore_settings/namespaced.rb +210 -0
  40. data/lib/thecore_settings/processing.rb +217 -0
  41. data/lib/thecore_settings/rails_admin_config.rb +71 -0
  42. data/lib/thecore_settings/require_helpers.rb +86 -0
  43. data/lib/thecore_settings/settings.rb +95 -0
  44. data/lib/thecore_settings/storage/carrier_wave_uploader.rb +9 -0
  45. data/lib/thecore_settings/storage/shrine_uploader.rb +14 -0
  46. data/lib/thecore_settings/tasks.rb +35 -0
  47. data/lib/thecore_settings/uploads.rb +57 -0
  48. data/lib/thecore_settings/validation.rb +126 -0
  49. data/lib/thecore_settings/version.rb +1 -1
  50. data/lib/thecore_settings.rb +115 -123
  51. data/spec/advanced_usage_spec.rb +11 -0
  52. data/spec/carrierwave_spec.rb +41 -0
  53. data/spec/database_trickery_spec.rb +48 -0
  54. data/spec/defaults_spec.rb +87 -0
  55. data/spec/enabling_spec.rb +29 -0
  56. data/spec/factories/setting.rb +8 -0
  57. data/spec/label_spec.rb +16 -0
  58. data/spec/migration_spec.rb +20 -0
  59. data/spec/model_spec.rb +105 -0
  60. data/spec/namespaced_spec.rb +67 -0
  61. data/spec/paperclip_spec.rb +38 -0
  62. data/spec/settings_spec.rb +75 -0
  63. data/spec/shrine_spec.rb +34 -0
  64. data/spec/spec_helper.rb +85 -0
  65. data/spec/support/1024x768.gif +0 -0
  66. data/spec/support/database_cleaner.rb +10 -0
  67. data/spec/support/defaults.yml +23 -0
  68. data/spec/support/defaults_w_file.yml +19 -0
  69. data/spec/support/mongoid.rb +6 -0
  70. data/spec/support/mongoid.yml +6 -0
  71. data/spec/types_spec.rb +101 -0
  72. data/thecore_settings.gemspec +44 -0
  73. metadata +326 -63
  74. data/app/assets/stylesheets/rich/editor.css +0 -20
  75. data/config/initializers/rails_admin_requirements.rb +0 -22
  76. data/config/initializers/thecore_settings_abilities.rb +0 -22
  77. data/config/initializers/thecore_settings_post_init.rb +0 -9
  78. data/config/routes.rb +0 -3
  79. data/db/migrate/20161227101956_add_app_name.rb +0 -5
  80. data/lib/tasks/thecore_settings_tasks.rake +0 -4
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe "Uploads" do
5
+ if Settings.file_uploads_engine != :paperclip
6
+ pending "paperclip not detected, skipped. To run use UPLOADS=paperclip rspec"
7
+ else
8
+ Paperclip.options[:log] = false
9
+ before :each do
10
+ f = "#{File.dirname(__FILE__)}/../uploads/1024x768.gif"
11
+ if File.file?(f)
12
+ File.unlink(f)
13
+ end
14
+ end
15
+ it 'supports file kind' do
16
+ Settings.set('file', File.open("#{File.dirname(__FILE__)}/support/1024x768.gif"), kind: 'file')
17
+ expect(Settings.get(:file).file_file_name).to eq '1024x768.gif'
18
+ expect(Settings.get(:file).file_file_size).to eq 4357
19
+ expect(Settings.file[0..21]).to eq '/uploads/1024x768.gif?'
20
+ expect(File.exists?("#{File.dirname(__FILE__)}/../uploads/1024x768.gif")).to be_truthy
21
+ end
22
+
23
+ it 'supports image kind' do
24
+ Settings.set('file', File.open("#{File.dirname(__FILE__)}/support/1024x768.gif"), kind: 'image')
25
+ expect(Settings.get(:file).file_file_name).to eq '1024x768.gif'
26
+ expect(Settings.get(:file).file_file_size).to eq 4357
27
+ expect(Settings.file[0..21]).to eq '/uploads/1024x768.gif?'
28
+
29
+ expect(File.exists?("#{File.dirname(__FILE__)}/../uploads/1024x768.gif")).to be_truthy
30
+ end
31
+
32
+ it 'supports defaults' do
33
+ Settings.apply_defaults!(File.join(File.dirname(__FILE__), 'support/defaults_w_file.yml'))
34
+ expect(File.exists?(Settings.root_file_path.join("uploads/1024x768.gif"))).to be_truthy
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,75 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'Settings' do
6
+ it "should works as RailsSettings" do
7
+ Settings.destroy_all!
8
+
9
+ email = "my@mail.ru"
10
+ Settings.email = email
11
+ expect(Settings.email).to eq(email)
12
+ end
13
+
14
+ it '#get should return new setting when setting does not exist' do
15
+ t = Settings.get(:test)
16
+ expect(t.class.name).to eq 'ThecoreSettings::Setting'
17
+ expect(t.persisted?).to eq true
18
+ expect(t.value).to eq ''
19
+ end
20
+
21
+ it '#name should return empty string when setting does not exist' do
22
+ expect(Settings.test).to eq ''
23
+ expect(Settings['test'].value).to eq ''
24
+ end
25
+
26
+ it "should save default" do
27
+ Settings.destroy_all!
28
+
29
+ email = "my@mail.ru"
30
+ email2 = "my2@mail.ru"
31
+ Settings.save_default(:email, email)
32
+ expect(Settings.email).to eq(email)
33
+ Settings.email = email2
34
+ expect(Settings.email).to eq(email2)
35
+ Settings.save_default(:email, email)
36
+ expect(Settings.email).to eq(email2)
37
+ end
38
+
39
+ it 'should properly unload' do
40
+ Settings.load!
41
+ expect(Settings.loaded).to eq true
42
+ Settings.unload!
43
+ expect(Settings.loaded).to eq false
44
+ end
45
+
46
+ it 'should work with kind and default' do
47
+ expect(Settings.phone(kind: 'phone', default: '906 111 11 11')).to eq '+7 (906) 111-11-11'
48
+ Settings.phone = '906 222 22 22'
49
+ expect(Settings.phone(kind: 'phone', default: '906 111 11 11')).to eq '+7 (906) 222-22-22'
50
+ end
51
+
52
+ it 'should properly store settings to DB' do
53
+ Settings.unload!
54
+ expect(Settings.loaded).to eq false
55
+ Settings.temp = '123'
56
+ expect(Settings.loaded).to eq true
57
+ Settings.unload!
58
+ expect(Settings.loaded).to eq false
59
+ expect(Settings.temp).to eq '123'
60
+ expect(Settings.loaded).to eq true
61
+ end
62
+
63
+ it 'should support yaml kind' do
64
+ Settings.tdata(kind: 'yaml')
65
+ Settings.tdata = ['one', 'two', 'three']
66
+ expect(YAML.safe_load(Settings.get(:tdata).raw)).to eq ['one', 'two', 'three']
67
+ expect(Settings.tdata).to eq ['one', 'two', 'three']
68
+ end
69
+
70
+ it '#enabled? sets defaults' do
71
+ expect(Settings.enabled?(:phone, kind: 'phone')).to eq true
72
+ expect(Settings.get(:phone).kind).to eq 'phone'
73
+ end
74
+
75
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe "Uploads" do
5
+ if Settings.file_uploads_engine != :shrine
6
+ pending "shrine not detected, skipped. To run use UPLOADS=shrine rspec"
7
+ else
8
+ before :each do
9
+ f = "#{File.dirname(__FILE__)}/../uploads/1024x768.gif"
10
+ if File.file?(f)
11
+ File.unlink(f)
12
+ end
13
+ end
14
+ it 'supports file kind' do
15
+ Settings.set('file', File.open("#{File.dirname(__FILE__)}/support/1024x768.gif"), kind: 'file')
16
+ expect(Settings.get(:file).file.metadata["filename"]).to eq '1024x768.gif'
17
+ expect(Settings.get(:file).file.metadata["size"]).to eq 4357
18
+ expect(Settings.get(:file).file.metadata["mime_type"]).to eq "image/gif"
19
+ expect(Settings.get(:file).file.id.split(".").last).to eq "gif"
20
+ expect(Settings.file.split("/").second + "/" + Settings.file.split("/").last.split(".").last).to eq "uploads/gif"
21
+ expect(File.exists?("public/uploads/#{Settings.get(:file).file.id}")).to be_truthy
22
+ end
23
+ it 'supports image kind' do
24
+ Settings.set('file', File.open("#{File.dirname(__FILE__)}/support/1024x768.gif"), kind: 'image')
25
+ expect(Settings.get(:file).file.metadata["filename"]).to eq '1024x768.gif'
26
+ expect(Settings.get(:file).file.metadata["size"]).to eq 4357
27
+ expect(Settings.get(:file).file.metadata["mime_type"]).to eq "image/gif"
28
+ expect(Settings.get(:file).file.id.split(".").last).to eq "gif"
29
+ expect(Settings.file.split("/").second + "/" + Settings.file.split("/").last.split(".").last).to eq "uploads/gif"
30
+ expect(File.exists?("public/uploads/#{Settings.get(:file).file.id}")).to be_truthy
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,85 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'rubygems'
4
+
5
+ require 'simplecov'
6
+ SimpleCov.start
7
+
8
+ require 'bundler/setup'
9
+ require 'active_support'
10
+ require 'active_support/core_ext'
11
+
12
+ unless ENV['ACTIVERECORD']
13
+ require 'mongoid'
14
+ end
15
+
16
+ require 'database_cleaner'
17
+ require 'factory_bot'
18
+ require 'mongoid-rspec'
19
+
20
+ if ENV['UPLOADS'] == 'paperclip'
21
+ require "mongoid-paperclip"
22
+ end
23
+ if ENV['UPLOADS'] == 'carrierwave'
24
+ require "carrierwave/mongoid"
25
+ CarrierWave.configure do |config|
26
+ config.asset_host = proc do |file|
27
+ "http://localhost"
28
+ end
29
+ end
30
+ end
31
+ if ENV['UPLOADS'] == 'shrine'
32
+ require "shrine"
33
+ require "shrine/storage/file_system"
34
+ Shrine.storages = {
35
+ cache: Shrine::Storage::FileSystem.new("public", prefix: "uploads/cache"), # temporary
36
+ store: Shrine::Storage::FileSystem.new("public", prefix: "uploads"), # permanent
37
+ }
38
+
39
+ if ENV['ACTIVERECORD']
40
+ Shrine.plugin :activerecord
41
+ end
42
+ Shrine.plugin :cached_attachment_data # for retaining the cached file across form redisplays
43
+ Shrine.plugin :restore_cached_data # re-extract metadata when attaching a cached file
44
+ end
45
+
46
+
47
+
48
+ I18n.enforce_available_locales = true
49
+ I18n.load_path << File.join(File.dirname(__FILE__), "..", "config", "locales", "en.yml")
50
+
51
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each do |f|
52
+ require f
53
+ end
54
+
55
+ if ENV['RAILS'] == '1'
56
+ require "active_model/railtie"
57
+ require "action_controller/railtie"
58
+ require "action_view/railtie"
59
+ module RAS
60
+ class Application < Rails::Application
61
+ end
62
+ end
63
+ # Initialize the Rails application.
64
+ Rails.application.initialize!
65
+ end
66
+
67
+ require 'thecore_settings'
68
+
69
+
70
+ if ENV['UPLOADS'] == 'paperclip'
71
+ module ThecoreSettings::Uploads
72
+ def self.paperclip_options
73
+ {path: "#{File.dirname(__FILE__)}/../uploads/:filename", url: '/uploads/:filename'}
74
+ end
75
+ end
76
+ end
77
+
78
+
79
+ Dir["#{File.dirname(__FILE__)}/factories/**/*.rb"].each do |f|
80
+ require f
81
+ end
82
+
83
+ #RSpec.configure do |config|
84
+ #config.expect_with(:rspec) { |c| c.syntax = :should }
85
+ #end
Binary file
@@ -0,0 +1,10 @@
1
+ RSpec.configure do |config|
2
+ config.before :suite do
3
+ DatabaseCleaner.strategy = :truncation
4
+ end
5
+ config.after :each do
6
+ DatabaseCleaner.clean
7
+ Settings.destroy_all!
8
+ end
9
+ end
10
+
@@ -0,0 +1,23 @@
1
+ main:
2
+ footer:
3
+ kind: html
4
+ value: 'test <b></b>'
5
+
6
+ phone:
7
+ kind: 'phone'
8
+ value: '906 1111111'
9
+
10
+ true_setting:
11
+ kind: 'boolean'
12
+ value: true
13
+
14
+ false_setting:
15
+ kind: 'boolean'
16
+ value: false
17
+
18
+ disabled:
19
+ enabled: false
20
+
21
+ other:
22
+ footer:
23
+ value: 'zzz'
@@ -0,0 +1,19 @@
1
+ main:
2
+ footer:
3
+ kind: html
4
+ value: 'test <b></b>'
5
+
6
+ phone:
7
+ kind: 'phone'
8
+ value: '906 1111111'
9
+
10
+ disabled:
11
+ enabled: false
12
+
13
+ other:
14
+ footer:
15
+ value: 'zzz'
16
+
17
+ img:
18
+ kind: 'image'
19
+ value: 'spec/support/1024x768.gif'
@@ -0,0 +1,6 @@
1
+ ENV["MONGOID_ENV"] = "test"
2
+ Mongoid.load!("spec/support/mongoid.yml")
3
+
4
+ RSpec.configure do |configuration|
5
+ configuration.include Mongoid::Matchers
6
+ end
@@ -0,0 +1,6 @@
1
+ test:
2
+ clients:
3
+ default:
4
+ database: thecore_settings
5
+ hosts:
6
+ - localhost:27017
@@ -0,0 +1,101 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'Settings kind' do
6
+ it 'boolean' do
7
+ expect(Settings.get(:testbool, kind: 'boolean').value).to be(false)
8
+ expect(Settings.get(:testbool, default: true, kind: 'boolean').value).to be(false)
9
+ expect(Settings.get(:testbool2, default: true, kind: 'boolean').value).to be(true)
10
+ expect(Settings.testbool2).to be(true)
11
+ Settings.set(:testbool3, true, kind: 'boolean')
12
+ expect(Settings.testbool3).to be(true)
13
+ end
14
+
15
+ it 'html' do
16
+ expect(Settings.get(:email, kind: 'html', default: 'test@example.com').to_s).to eq 'test@example.com'
17
+ end
18
+
19
+ it 'integer' do
20
+ expect(Settings.get(:testint, kind: 'integer').value).to eq 0
21
+ expect(Settings.get(:testint, default: 5, kind: 'integer').value).to eq 0
22
+ expect(Settings.get(:testint2, default: 5, kind: 'integer').value).to eq 5
23
+ expect(Settings.testint2).to eq 5
24
+ end
25
+
26
+ it 'float' do
27
+ expect(Settings.get(:testfloat, kind: 'float').value).to eq 0
28
+ expect(Settings.get(:testfloat, default: 5.2, kind: 'float').value).to eq 0
29
+ expect(Settings.get(:testfloat2, default: 5.5, kind: 'float').value).to eq 5.5
30
+ expect(Settings.testfloat2).to eq 5.5
31
+ end
32
+
33
+ it 'does yaml' do
34
+ Settings.set(:data, '[one, two, three]', kind: 'yaml')
35
+ expect(Settings.get(:data).raw).to eq '[one, two, three]'
36
+ expect(Settings.data).to eq ['one', 'two', 'three']
37
+ end
38
+
39
+ it 'does json' do
40
+ Settings.set(:data, '{"a": 1, "b": 2}', kind: 'json')
41
+ expect(Settings.get(:data).raw).to eq '{"a": 1, "b": 2}'
42
+ expect(Settings.data).to eq({"a" => 1, "b" => 2})
43
+ end
44
+
45
+ it 'phone' do
46
+ Settings.set(:tphone, '906 111 11 11', kind: 'phone')
47
+ expect(Settings.get(:tphone).val.class.name).to eq 'RussianPhone::Number'
48
+ expect(Settings.tphone.class.name).to eq 'RussianPhone::Number'
49
+ expect(Settings.tphone).to eq '906 111 11 11'
50
+ expect(Settings.get(:tphone).phone_kind?).to be_truthy
51
+ expect(Settings.get(:tphone).val.city).to eq '906'
52
+ expect(Settings.get(:tphone).val.formatted_subscriber).to eq '111-11-11'
53
+ end
54
+
55
+ it 'supports phones kind' do
56
+ Settings.set(:tphone, ['906 111 11 11', '907 111 11 11'] * "\n", kind: 'phones')
57
+ expect(Settings.get(:tphone).val.class.name).to eq 'Array'
58
+ expect(Settings.tphone.class.name).to eq 'Array'
59
+ expect(Settings.get(:tphone).val.first.class.name).to eq 'RussianPhone::Number'
60
+ expect(Settings.tphone.first.class.name).to eq 'RussianPhone::Number'
61
+ expect(Settings.tphone.first).to eq '906 111 11 11'
62
+ expect(Settings.get(:tphone).phones_kind?).to be_truthy
63
+ expect(Settings.get(:tphone).val.first.city).to eq '906'
64
+ expect(Settings.get(:tphone).val.last.city).to eq '907'
65
+ expect(Settings.get(:tphone).val.first.formatted_subscriber).to eq '111-11-11'
66
+ end
67
+
68
+ it 'defaults for phone' do
69
+ Settings.dphone(kind: 'phone')
70
+ expect(Settings.get(:dphone).phone_kind?).to be_truthy
71
+ expect(Settings.dphone.formatted_area).to eq ''
72
+ expect(Settings.dphone.formatted_subscriber).to eq ''
73
+ end
74
+
75
+ it 'email validates' do
76
+ Settings.eml(kind: 'email')
77
+ expect(Settings.get(:eml).email_kind?).to be_truthy
78
+ expect { Settings.eml = '1' }.to raise_error
79
+ Settings.eml = 'test@example.com'
80
+ expect(Settings.eml).to eq 'test@example.com'
81
+ end
82
+
83
+ it 'url processing' do
84
+ Settings.url(kind: 'url')
85
+ expect(Settings.get(:url).url_kind?).to be_truthy
86
+ expect(Settings.get(:url).color_kind?).to be_falsey
87
+ Settings.url = 'test.ru'
88
+ expect(Settings.url).to eq 'http://test.ru'
89
+ end
90
+
91
+ it 'color' do
92
+ Settings.col(kind: 'color')
93
+ expect(Settings.get(:col).color_kind?).to be_truthy
94
+ expect { Settings.col = 'test'}.to raise_error
95
+ Settings.col = 'ffffff'
96
+ expect(Settings.col).to eq 'ffffff'
97
+ expect {
98
+ Settings.col = 'zzzzzz'
99
+ }.to raise_error
100
+ end
101
+ end
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'thecore_settings/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "thecore_settings"
8
+ spec.version = ThecoreSettings::VERSION
9
+ spec.authors = ["Gabriele Tassoni", "Gleb Tv"]
10
+ spec.email = ["gabriele.tassoni@gmail.com", "glebtv@gmail.com"]
11
+ spec.description = %q{Mongoid / ActiveRecord + RailsAdmin App Settings management}
12
+ spec.summary = %q{}
13
+ spec.homepage = "https://github.com/gabrieletassoni/thecore_settings"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+
22
+ spec.add_development_dependency "mongoid", '~> 6.3'
23
+ spec.add_development_dependency "rails"
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "mongoid-rspec"
28
+ spec.add_development_dependency "simplecov"
29
+ spec.add_development_dependency "database_cleaner"
30
+ spec.add_development_dependency "factory_bot"
31
+ spec.add_development_dependency "safe_yaml"
32
+ spec.add_development_dependency "russian_phone"
33
+ spec.add_development_dependency "sanitize"
34
+ spec.add_development_dependency "validates_email_format_of"
35
+ spec.add_development_dependency "geocoder"
36
+ spec.add_development_dependency "addressable"
37
+ spec.add_development_dependency "carrierwave-mongoid"
38
+ spec.add_development_dependency "mongoid-paperclip"
39
+ spec.add_development_dependency "rubocop-rspec"
40
+ spec.add_development_dependency 'image_processing'
41
+ spec.add_development_dependency "mini_magick"
42
+ spec.add_development_dependency "shrine", "~> 3.0"
43
+ spec.add_development_dependency "shrine-mongoid", "~> 1.0"
44
+ end