rails_admin_settings 0.5.3 → 0.5.4

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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +0 -0
  4. data/.travis.yml +15 -0
  5. data/README.md +1 -1
  6. data/Rakefile +0 -0
  7. data/app/models/rails_admin_settings/setting.rb +0 -1
  8. data/app/views/rails_admin/main/_setting_value.html.haml +0 -0
  9. data/config/locales/en.rails_admin_settings.yml +0 -0
  10. data/config/locales/ru.rails_admin_settings.yml +0 -0
  11. data/gemfiles/mongoid-3.0.gemfile +6 -0
  12. data/gemfiles/mongoid-3.1.gemfile +5 -0
  13. data/gemfiles/mongoid-4.0.gemfile +5 -0
  14. data/lib/rails_admin_settings/engine.rb +0 -0
  15. data/lib/rails_admin_settings/hex_color_validator.rb +0 -0
  16. data/lib/rails_admin_settings/processing.rb +10 -2
  17. data/lib/rails_admin_settings/rails_admin_config.rb +0 -0
  18. data/lib/rails_admin_settings/require_helpers.rb +0 -0
  19. data/lib/rails_admin_settings/settings.rb +62 -30
  20. data/lib/rails_admin_settings/storage/carrierwave.rb +0 -0
  21. data/lib/rails_admin_settings/types.rb +1 -1
  22. data/lib/rails_admin_settings/uploads.rb +8 -4
  23. data/lib/rails_admin_settings/validation.rb +0 -0
  24. data/lib/rails_admin_settings/version.rb +1 -1
  25. data/lib/rails_admin_settings.rb +0 -0
  26. data/rails_admin_settings.gemspec +3 -0
  27. data/spec/advanced_usage_spec.rb +0 -0
  28. data/spec/carrierwave_spec.rb +36 -0
  29. data/spec/database_trickery_spec.rb +0 -0
  30. data/spec/factories/setting.rb +0 -0
  31. data/spec/model_spec.rb +0 -0
  32. data/spec/paperclip_spec.rb +34 -0
  33. data/spec/settings_spec.rb +0 -0
  34. data/spec/spec_helper.rb +10 -0
  35. data/spec/support/1024x768.gif +0 -0
  36. data/spec/support/database_cleaner.rb +0 -0
  37. data/spec/support/mongoid.rb +0 -0
  38. data/spec/support/mongoid.yml +0 -0
  39. data/spec/types_spec.rb +0 -0
  40. metadata +40 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cdc19ffd66918e198000472862fc7045515bf282
4
- data.tar.gz: 952677372ec953f096e51741cd0ef947cb955bdc
3
+ metadata.gz: 04813caf7297c8963bfeb2ef852f48b59bad20e0
4
+ data.tar.gz: e7f5313d59b0d98ee04fd229f9cf3667b6050e06
5
5
  SHA512:
6
- metadata.gz: a92df07ac3ba6a9f2e9d1789f41d17ea70a8fdd1a0aa29797dfc56b3a3319d5b9237f4bab61a4d1ab6c2d5ddcc9c0195dd6c8d8509b7d5c5b3172a96bad9cda3
7
- data.tar.gz: f5d158f45f9ec64d5093a6c44619a63c3faef976ae316d6ef17f45d73670bc2fc495d4e2bf035c9a20dcfe7547ff867e1ffc02b59f44106d07e2781f73c9f2b2
6
+ metadata.gz: 1f4d2ab7a2e3d31fa5f40bc52e61fc6ba8429d64068a2ab6fe033224937b701458ad454e18e3e2aba672415a3fcdc8c129c2d38270af5fa945578abad0367a50
7
+ data.tar.gz: df8efddcdcce6daf6a99ec0759e98e2747abed205b06df39b562ca5c4cc1215336078efb06e181627359cf915e6d5244b036601705622d0dcc3486798ebb101f
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .idea
19
+ /uploads
data/.rspec CHANGED
File without changes
data/.travis.yml CHANGED
@@ -1,5 +1,20 @@
1
1
  language: ruby
2
2
  services: mongodb
3
+
4
+ notifications:
5
+ email: false
6
+
3
7
  rvm:
4
8
  - 1.9.3
9
+ - 2.0.0
10
+ - jruby-19mode
11
+
12
+ env:
13
+ - "UPLOADS=paperclip"
14
+ - "UPLOADS=carrierwave"
5
15
 
16
+ gemfile:
17
+ - Gemfile
18
+ - gemfiles/mongoid-3.0.gemfile
19
+ - gemfiles/mongoid-3.1.gemfile
20
+ - gemfiles/mongoid-4.0.gemfile
data/README.md CHANGED
@@ -3,7 +3,7 @@
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.png)](https://gemnasium.com/rs-pro/rails_admin_settings)
5
5
 
6
- Note: This gem currently supports Mongoid only, as I don't need AR support.
6
+ Note: This gem currently supports Mongoid 3/4 only, as I don't need AR support.
7
7
 
8
8
  Pull request with AR support will be welcome
9
9
 
data/Rakefile CHANGED
File without changes
@@ -25,7 +25,6 @@ module RailsAdminSettings
25
25
  include RailsAdminSettings::Uploads
26
26
  include RailsAdminSettings::Validation
27
27
 
28
-
29
28
  def disabled?
30
29
  !enabled
31
30
  end
File without changes
File without changes
File without changes
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "mongoid", github: "mongoid/mongoid", branch: "3.0.0-stable"
4
+ gem "activemodel", "~> 3.2"
5
+
6
+ gemspec path: "../"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "mongoid", github: "mongoid/mongoid", branch: "3.1.0-stable"
4
+
5
+ gemspec path: "../"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "mongoid", github: "mongoid/mongoid", branch: "master"
4
+
5
+ gemspec path: "../"
File without changes
File without changes
@@ -10,13 +10,21 @@ module RailsAdminSettings
10
10
  (RailsAdminSettings.types - ['phone', 'integer', 'yaml']).include? type
11
11
  end
12
12
 
13
+ def upload_type?
14
+ ['file', 'image'].include? type
15
+ end
16
+
13
17
  def html_type?
14
18
  ['html', 'sanitized'].include? type
15
19
  end
16
20
 
17
21
  def value
18
- if file_type?
19
- file.url
22
+ if upload_type?
23
+ if file?
24
+ file.url
25
+ else
26
+ nil
27
+ end
20
28
  elsif raw.blank? || disabled?
21
29
  default_value
22
30
  else
File without changes
File without changes
@@ -1,32 +1,39 @@
1
+ require 'thread'
2
+
1
3
  class Settings
2
4
  cattr_accessor :file_uploads_supported, :file_uploads_engine, :settings
3
5
  @@file_uploads_supported = false
4
6
  @@file_uploads_engine = false
7
+ @@mutex = Mutex.new
5
8
 
6
9
  class << self
7
10
  @@loaded = false
8
11
  @@settings = {}
9
12
 
10
13
  def load!
11
- if @@loaded
12
- false
13
- else
14
- @@settings = {}
15
- RailsAdminSettings::Setting.all.each do |setting|
16
- @@settings[setting.key] = setting
14
+ @@mutex.synchronize do
15
+ if @@loaded
16
+ false
17
+ else
18
+ @@settings = {}
19
+ RailsAdminSettings::Setting.all.each do |setting|
20
+ @@settings[setting.key] = setting
21
+ end
22
+ @@loaded = true
23
+ true
17
24
  end
18
- @@loaded = true
19
- true
20
25
  end
21
26
  end
22
27
 
23
28
  def unload!
24
- if @@loaded
25
- @@settings = {}
26
- @@loaded = false
27
- true
28
- else
29
- false
29
+ @@mutex.synchronize do
30
+ if @@loaded
31
+ @@settings = {}
32
+ @@loaded = false
33
+ true
34
+ else
35
+ false
36
+ end
30
37
  end
31
38
  end
32
39
 
@@ -54,12 +61,29 @@ class Settings
54
61
  value = value.to_yaml
55
62
  end
56
63
 
64
+ is_file = !options[:type].nil? && (options[:type] == 'image' || options[:type] == 'file')
65
+ if is_file
66
+ options[:raw] = ''
67
+ else
68
+ options[:raw] = value
69
+ end
70
+
57
71
  if @@settings[key].nil?
58
- write_to_database(key, options.merge(key: key, raw: value))
72
+ write_to_database(key, options.merge(key: key))
59
73
  else
60
- @@settings[key].update_attributes!(options.merge(raw: value))
61
- @@settings[key]
74
+ @@mutex.synchronize do
75
+ @@settings[key].update_attributes!(options)
76
+ end
62
77
  end
78
+
79
+ if is_file
80
+ @@mutex.synchronize do
81
+ @@settings[key].file = value
82
+ @@settings[key].save!
83
+ end
84
+ end
85
+
86
+ @@settings[key]
63
87
  end
64
88
 
65
89
  def valid_yaml?(value)
@@ -100,6 +124,7 @@ class Settings
100
124
  load!
101
125
  key = key.to_s
102
126
  options.merge!(default: value)
127
+
103
128
  if @@settings[key].nil?
104
129
  create_setting(key, options).val
105
130
  else
@@ -116,6 +141,7 @@ class Settings
116
141
  key = key.to_s
117
142
  options.symbolize_keys!
118
143
  options[:raw] = options.delete(:default)
144
+
119
145
  if @@settings[key].nil?
120
146
  write_to_database(key, options.merge(key: key))
121
147
  else
@@ -139,9 +165,12 @@ class Settings
139
165
  def destroy!(key)
140
166
  load!
141
167
  key = key.to_s
142
- unless @@settings[key].nil?
143
- @@settings[key].destroy
144
- @@settings.delete(key)
168
+
169
+ @@mutex.synchronize do
170
+ unless @@settings[key].nil?
171
+ @@settings[key].destroy
172
+ @@settings.delete(key)
173
+ end
145
174
  end
146
175
  end
147
176
 
@@ -153,20 +182,23 @@ class Settings
153
182
 
154
183
  def write_to_database(key, options)
155
184
  key = key.to_s
156
- @@settings[key] = RailsAdminSettings::Setting.create(options)
157
- unless @@settings[key].persisted?
158
- if @@settings[key].errors[:key].any?
159
- @@settings[key] = RailsAdminSettings::Setting.where(key: key).first
160
- if options[:raw].blank? && !@@settings[key].blank?
161
- # do not update setting if it's not blank in DB and we want to make it blank
162
- else
163
- unless @@settings[key].update_attributes(options)
164
- raise RailsAdminSettings::PersistenceException
185
+
186
+ @@mutex.synchronize do
187
+ @@settings[key] = RailsAdminSettings::Setting.create(options)
188
+ unless @@settings[key].persisted?
189
+ if @@settings[key].errors[:key].any?
190
+ @@settings[key] = RailsAdminSettings::Setting.where(key: key).first
191
+ if options[:raw].blank? && !@@settings[key].blank?
192
+ # do not update setting if it's not blank in DB and we want to make it blank
193
+ else
194
+ unless @@settings[key].update_attributes(options)
195
+ raise RailsAdminSettings::PersistenceException
196
+ end
165
197
  end
166
198
  end
167
199
  end
200
+ @@settings[key]
168
201
  end
169
- @@settings[key]
170
202
  end
171
203
 
172
204
  def label key
File without changes
@@ -1,5 +1,5 @@
1
1
  module RailsAdminSettings
2
2
  def self.types
3
- ['string', 'integer', 'html', 'sanitized', 'yaml', 'phone', 'email', 'address', 'file', 'url', 'domain', 'color']
3
+ ['string', 'integer', 'html', 'sanitized', 'yaml', 'phone', 'email', 'address', 'file', 'image', 'url', 'domain', 'color']
4
4
  end
5
5
  end
@@ -5,7 +5,7 @@ module RailsAdminSettings
5
5
  def self.included(base)
6
6
  # carrierwave
7
7
  if base.respond_to?(:mount_uploader)
8
- # puts "[rails_admin_settings] CarrierWave detected"
8
+ puts "[rails_admin_settings] CarrierWave detected"
9
9
  # base.field(:file, type: String)
10
10
  base.mount_uploader(:file, RailsAdminSettings::Uploads::CarrierWave)
11
11
  Settings.file_uploads_supported = true
@@ -13,16 +13,20 @@ module RailsAdminSettings
13
13
  # paperclip
14
14
  elsif Mongoid.const_defined?('Paperclip')
15
15
  base.send(:include, Mongoid::Paperclip)
16
- # puts "[rails_admin_settings] PaperClip detected"
16
+ puts "[rails_admin_settings] PaperClip detected"
17
17
  base.field(:file, type: String)
18
- base.has_mongoid_attached_file(:file)
18
+ if defined?(Rails)
19
+ base.has_mongoid_attached_file(:file)
20
+ else
21
+ base.has_mongoid_attached_file(:file, path: "#{File.dirname(__FILE__)}/../../uploads/:filename", url: '/uploads/:filename')
22
+ end
19
23
  base.send(:attr_accessor, :delete_file)
20
24
  base.before_validation { self.file.clear if self.delete_file == '1' }
21
25
 
22
26
  Settings.file_uploads_supported = true
23
27
  Settings.file_uploads_engine = :paperclip
24
28
  else
25
- # puts "[rails_admin_settings] Uploads disabled"
29
+ puts "[rails_admin_settings] Uploads disabled"
26
30
  end
27
31
  end
28
32
  end
File without changes
@@ -1,3 +1,3 @@
1
1
  module RailsAdminSettings
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  end
File without changes
@@ -34,4 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency "validates_email_format_of", "~> 1.5.3"
35
35
  spec.add_development_dependency "geocoder", "~> 1.1.6"
36
36
  spec.add_development_dependency "addressable", "~> 2.3.3"
37
+
38
+ spec.add_development_dependency "glebtv-carrierwave-mongoid"
39
+ spec.add_development_dependency "glebtv-mongoid-paperclip"
37
40
  end
File without changes
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Uploads" do
4
+ if Settings.file_uploads_engine != :carrierwave
5
+ pending "paperclip not detected, skipped. To run use UPLOADS=carrierwave rspec"
6
+ else
7
+ before :each do
8
+ f = "#{File.dirname(__FILE__)}/../uploads/1024x768.gif"
9
+ if File.file?(f)
10
+ File.unlink(f)
11
+ end
12
+ end
13
+ it 'supports file type' do
14
+ Settings.set('file', File.open("#{File.dirname(__FILE__)}/support/1024x768.gif"), type: 'file')
15
+
16
+ # because we're not inside Rails
17
+ Settings.get(:file).file.root = '/'
18
+
19
+ Settings.get(:file).file.file.file.should eq "#{File.dirname(__FILE__).gsub('/spec', '/')}uploads/1024x768.gif"
20
+
21
+ File.exists?("#{File.dirname(__FILE__)}/../uploads/1024x768.gif").should be_true
22
+ end
23
+
24
+ it 'supports image type' do
25
+ Settings.set('file', File.open("#{File.dirname(__FILE__)}/support/1024x768.gif"), type: 'image')
26
+
27
+ # because we're not inside Rails
28
+ Settings.get(:file).file.root = '/'
29
+
30
+ Settings.get(:file).file.file.file.should eq "#{File.dirname(__FILE__).gsub('/spec', '/')}uploads/1024x768.gif"
31
+
32
+ File.exists?("#{File.dirname(__FILE__)}/../uploads/1024x768.gif").should be_true
33
+ end
34
+ end
35
+ end
36
+
File without changes
File without changes
data/spec/model_spec.rb CHANGED
File without changes
@@ -0,0 +1,34 @@
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 type' do
16
+ Settings.set('file', File.open("#{File.dirname(__FILE__)}/support/1024x768.gif"), type: 'file')
17
+ Settings.get(:file).file_file_name.should eq '1024x768.gif'
18
+ Settings.get(:file).file_file_size.should eq 4357
19
+ Settings.file[0..21].should eq '/uploads/1024x768.gif?'
20
+
21
+ File.exists?("#{File.dirname(__FILE__)}/../uploads/1024x768.gif").should be_true
22
+ end
23
+
24
+ it 'supports image type' do
25
+ Settings.set('file', File.open("#{File.dirname(__FILE__)}/support/1024x768.gif"), type: 'image')
26
+ Settings.get(:file).file_file_name.should eq '1024x768.gif'
27
+ Settings.get(:file).file_file_size.should eq 4357
28
+ Settings.file[0..21].should eq '/uploads/1024x768.gif?'
29
+
30
+ File.exists?("#{File.dirname(__FILE__)}/../uploads/1024x768.gif").should be_true
31
+ end
32
+ end
33
+ end
34
+
File without changes
data/spec/spec_helper.rb CHANGED
@@ -12,6 +12,16 @@ require 'database_cleaner'
12
12
  require 'factory_girl'
13
13
  require 'mongoid-rspec'
14
14
 
15
+ require "glebtv-mongoid-paperclip" if ENV['UPLOADS'] == 'paperclip'
16
+ if ENV['UPLOADS'] == 'carrierwave'
17
+ require "glebtv-carrierwave-mongoid"
18
+ CarrierWave.configure do |config|
19
+ config.asset_host = proc do |file|
20
+ "http://localhost"
21
+ end
22
+ end
23
+ end
24
+
15
25
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each do |f|
16
26
  require f
17
27
  end
Binary file
File without changes
File without changes
File without changes
data/spec/types_spec.rb CHANGED
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gleb Tv
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-09 00:00:00.000000000 Z
11
+ date: 2013-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -206,6 +206,34 @@ dependencies:
206
206
  - - ~>
207
207
  - !ruby/object:Gem::Version
208
208
  version: 2.3.3
209
+ - !ruby/object:Gem::Dependency
210
+ name: glebtv-carrierwave-mongoid
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - '>='
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - '>='
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: glebtv-mongoid-paperclip
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - '>='
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
209
237
  description: Mongoid / RailsAdmin App Settings management
210
238
  email:
211
239
  - glebtv@gmail.com
@@ -226,6 +254,9 @@ files:
226
254
  - app/views/rails_admin/main/_setting_value.html.haml
227
255
  - config/locales/en.rails_admin_settings.yml
228
256
  - config/locales/ru.rails_admin_settings.yml
257
+ - gemfiles/mongoid-3.0.gemfile
258
+ - gemfiles/mongoid-3.1.gemfile
259
+ - gemfiles/mongoid-4.0.gemfile
229
260
  - lib/rails_admin_settings.rb
230
261
  - lib/rails_admin_settings/engine.rb
231
262
  - lib/rails_admin_settings/hex_color_validator.rb
@@ -240,12 +271,15 @@ files:
240
271
  - lib/rails_admin_settings/version.rb
241
272
  - rails_admin_settings.gemspec
242
273
  - spec/advanced_usage_spec.rb
274
+ - spec/carrierwave_spec.rb
243
275
  - spec/database_trickery_spec.rb
244
276
  - spec/factories/setting.rb
245
277
  - spec/label_spec.rb
246
278
  - spec/model_spec.rb
279
+ - spec/paperclip_spec.rb
247
280
  - spec/settings_spec.rb
248
281
  - spec/spec_helper.rb
282
+ - spec/support/1024x768.gif
249
283
  - spec/support/database_cleaner.rb
250
284
  - spec/support/mongoid.rb
251
285
  - spec/support/mongoid.yml
@@ -270,18 +304,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
304
  version: '0'
271
305
  requirements: []
272
306
  rubyforge_project:
273
- rubygems_version: 2.0.6
307
+ rubygems_version: 2.1.10
274
308
  signing_key:
275
309
  specification_version: 4
276
310
  summary: Setting for Rails app with mongoid and RailsAdmin
277
311
  test_files:
278
312
  - spec/advanced_usage_spec.rb
313
+ - spec/carrierwave_spec.rb
279
314
  - spec/database_trickery_spec.rb
280
315
  - spec/factories/setting.rb
281
316
  - spec/label_spec.rb
282
317
  - spec/model_spec.rb
318
+ - spec/paperclip_spec.rb
283
319
  - spec/settings_spec.rb
284
320
  - spec/spec_helper.rb
321
+ - spec/support/1024x768.gif
285
322
  - spec/support/database_cleaner.rb
286
323
  - spec/support/mongoid.rb
287
324
  - spec/support/mongoid.yml