mournful_settings 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmJkYzIzNWJhNmIwNDU1MzIzOGIxZmJhYWE1MGRjOGNmYjc4MTM0Ng==
4
+ OTkwNTdkNWM5OTM1MjIwMzUzM2YxOTFlYTVjMmU1YzllYmI0ZmQ4ZQ==
5
5
  data.tar.gz: !binary |-
6
- ZDU2YmVhY2Q3MjBiYzgxNzhlM2M0ZjQ0ZTk2MzYzZmM4OGI5ZWM1ZA==
6
+ MTY5MzRiNzhkYjNiZmI0MDRkOGNlN2EzMDQ5YTIwNzBhZDk0NzM0ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Y2U2ZGI5NDg4ZjE0ZWMzOGFmM2ZhYTcyZjdjMGM4MjNlNWY0ZTE2ZGE5NDA1
10
- NmE2ODRhODIxZTQwNzMxYTg3OTY5Y2Y2MWE0MWI3ZjZhMjk4Yjc0ODAzYjdi
11
- Y2ZkZTkwNjY5NTIzNjBiNjgwYjkyNDUwYWVkNjY0MGEwZTNjYmQ=
9
+ YzZmYjczNGQzOWQwN2FkYzYzZGNjZjQ5ODQ5ZDc4ZDcwMmU2NjU2N2NjZjVj
10
+ MmY3OTQ5NjMwZmMwMTk4ZWVhMWJjYmQ5NzU0MWVlYTE5OWRjM2YzYWI0Yjli
11
+ MjJjYTJhMjZjNmZlN2ZiNDliYjczZWFkYWE3NTY0YTVlNTNkMjE=
12
12
  data.tar.gz: !binary |-
13
- NmFhM2Y4MDU2NTA0MjM2MjdhYmVmOTMxMmJhNjUzNmIwOGQ1YTViYjUwMDBi
14
- ZDZjNTM0MzJmOWI4MDFjNzk5ZTJkNmE0ZTkxMzdiNmJiNWI2OGQ2NmNhODZm
15
- ZjRjMzQxYmRkMjdhNjUxZThhOTQxM2Y4M2Y1YjhkNDQ0YWViNjg=
13
+ Njc3ZWNlNmUxNDM2NjlmOWUzYWI1NGQ1ZjliYWU0NTA2ZTRlOGNmYzhiYjU5
14
+ ZTJiYzgxOWRjMThhMTU1YjkwOTg2ZGQyZjc1NjU1OTAzMWUwNDg2ZTE3OTlj
15
+ NDZjNmQzZTUzNTYyNTZjYjk2ZWZkZWI1NWNjY2VlOTc1M2I2NzQ=
@@ -154,6 +154,12 @@ To add mournful_settings migrations to the host app run this rake task:
154
154
 
155
155
  Then run 'rake db:migrate' to create the 'mournful_settings_settings' table.
156
156
 
157
+ ==== Settings before the database is created
158
+
159
+ If the database table is not present, it will be assumed that the default
160
+ setting (or nil) should be used until the table is created and the matching
161
+ setting stored.
162
+
157
163
  === Updating inherited Setting to use acts_as_mournful_setting
158
164
 
159
165
  The class Setting above could be modified to work with acts_as_mournful_setting,
@@ -22,7 +22,7 @@ ActiveAdmin.register Setting do
22
22
  :checked => (setting.encrypted == false ? false : true)
23
23
  }
24
24
  )
25
- f.input :value_type, collection: MournfulSettings::SettingMethods::VALUE_TYPES
25
+ f.input :value_type, :collection => MournfulSettings::SettingMethods::VALUE_TYPES
26
26
  end
27
27
  f.buttons
28
28
  end
@@ -2,11 +2,24 @@ require 'active_record'
2
2
  require_relative "mournful_settings/railtie" if defined?(Rails) # needed for rake tasks to be loaded into host app
3
3
  require_relative 'active_record/acts/mournful_setting'
4
4
  require_relative 'mournful_settings/setting'
5
+ require 'logger'
5
6
 
6
7
  module MournfulSettings
7
8
 
8
9
  def self.active_admin_load_path
9
10
  File.expand_path("active_admin/admin", File.dirname(__FILE__))
10
11
  end
12
+
13
+ def self.logger
14
+ defined?(Rails) ? Rails.logger : local_logger
15
+ end
16
+
17
+ def self.logger=(alternative_logger)
18
+ @logger = alternative_logger
19
+ end
20
+
21
+ def self.local_logger
22
+ @logger ||= Logger.new('log/mournful_settings.log')
23
+ end
11
24
 
12
25
  end
@@ -21,7 +21,11 @@ module MournfulSettings
21
21
 
22
22
  def for(name, default = nil)
23
23
  setting = find_by_name(name.to_s) # values should be passed to AR as strings
24
+ MournfulSettings.logger.debug "MornfulSetting for #{name} called"
24
25
  setting ? setting.value : default
26
+ rescue ActiveRecord::StatementInvalid => e
27
+ MournfulSettings.logger.warn "Default MournfulSetting for '#{name}' forced because: #{e.message}"
28
+ return default
25
29
  end
26
30
 
27
31
  def recrypt_all &do_while_unencrypted
@@ -1,10 +1,17 @@
1
1
  module MournfulSettings
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
4
4
 
5
5
  # History
6
6
  # =======
7
7
  #
8
+ # 0.1.3: Handles lack of database on initial use
9
+ # ----------------------------------------------
10
+ # In a rails app, if a setting is used in an initializer before the settings
11
+ # table is created, the app could not be run to build the table. In this
12
+ # version, it is assumed that if the database is not present, the default
13
+ # setting should be used.
14
+ #
8
15
  # 0.1.2: Add facility to select value type via active_admin form
9
16
  # --------------------------------------------------------------
10
17
  # Lack of value type was preventing new settings to be created via active admin
@@ -0,0 +1,6 @@
1
+
2
+ class SettingWithoutTable < ActiveRecord::Base
3
+
4
+ acts_as_mournful_setting
5
+
6
+ end
@@ -0,0 +1,24 @@
1
+ require_relative '../../test_helper'
2
+ require 'setting_without_table'
3
+
4
+ # If an application is moved to a new location and settings are used in the
5
+ # application configuration, it is impossible to create the Settings table
6
+ # via the normal rake tasks if MournfulSetting.for returns a
7
+ # 'Could not find table' error. That leave the app in the loop - need a
8
+ # settings table to start the app, but can't create the tables without starting
9
+ # the app.
10
+ #
11
+ # So MournfulSetting.for needs to be handle the lack of table.
12
+ #
13
+ class SettingWithoutTableTest < Test::Unit::TestCase
14
+
15
+ def test_for_without_default
16
+ assert_equal nil, SettingWithoutTable.for(:foo)
17
+ end
18
+
19
+ def test_for_with_default
20
+ default = 'bar'
21
+ assert_equal default, SettingWithoutTable.for(:foo, default)
22
+ end
23
+
24
+ end
@@ -1,6 +1,11 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__),'..','lib')
2
2
  $:.unshift File.join(File.dirname(__FILE__),'dummy','lib')
3
3
 
4
+ unless defined?(Rails)
5
+ MournfulSettings.logger = Logger.new('log/test.log')
6
+ MournfulSettings.logger.level = Logger::INFO
7
+ end
8
+
4
9
  require 'test/unit'
5
10
 
6
11
  require 'active_record'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mournful_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Nichols
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-28 00:00:00.000000000 Z
11
+ date: 2015-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -46,24 +46,26 @@ executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
+ - MIT-LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - lib/active_admin/admin/settings.rb
49
53
  - lib/active_record/acts/mournful_setting.rb
50
- - lib/mournful_settings/version.rb
54
+ - lib/mournful_settings.rb
55
+ - lib/mournful_settings/railtie.rb
51
56
  - lib/mournful_settings/setting.rb
52
- - lib/mournful_settings/setting_methods/cipher.rb
53
57
  - lib/mournful_settings/setting_methods.rb
54
- - lib/mournful_settings/railtie.rb
55
- - lib/mournful_settings.rb
56
- - lib/active_admin/admin/settings.rb
58
+ - lib/mournful_settings/setting_methods/cipher.rb
59
+ - lib/mournful_settings/version.rb
57
60
  - lib/tasks/mournful_settings.rake
58
- - MIT-LICENSE
59
- - Rakefile
60
- - README.rdoc
61
- - test/dummy/lib/setting_actor.rb
62
- - test/dummy/lib/setting.rb
63
61
  - test/dummy/db/development.sqlite3.db
64
62
  - test/dummy/db/test.sqlite3.db
63
+ - test/dummy/lib/setting.rb
64
+ - test/dummy/lib/setting_actor.rb
65
+ - test/dummy/lib/setting_without_table.rb
65
66
  - test/dummy/test/setting_actor_test.rb
66
67
  - test/dummy/test/setting_test.rb
68
+ - test/dummy/test/setting_without_table_test.rb
67
69
  - test/test_helper.rb
68
70
  homepage: https://github.com/reggieb/mournful_settings
69
71
  licenses:
@@ -85,15 +87,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
87
  version: '0'
86
88
  requirements: []
87
89
  rubyforge_project:
88
- rubygems_version: 2.1.10
90
+ rubygems_version: 2.2.2
89
91
  signing_key:
90
92
  specification_version: 4
91
93
  summary: Tool for adding encrypted settings to an app.
92
94
  test_files:
93
95
  - test/dummy/lib/setting_actor.rb
94
96
  - test/dummy/lib/setting.rb
97
+ - test/dummy/lib/setting_without_table.rb
95
98
  - test/dummy/db/development.sqlite3.db
96
99
  - test/dummy/db/test.sqlite3.db
100
+ - test/dummy/test/setting_without_table_test.rb
97
101
  - test/dummy/test/setting_actor_test.rb
98
102
  - test/dummy/test/setting_test.rb
99
103
  - test/test_helper.rb