settler 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -1
- data/VERSION +1 -1
- data/generators/settler/settler_generator.rb +1 -1
- data/init.rb +0 -3
- data/lib/default_scope_patch.rb +15 -0
- data/lib/generators/settler/USAGE +5 -0
- data/lib/generators/settler/settler_generator.rb +24 -0
- data/lib/generators/settler/templates/migration.rb +19 -0
- data/lib/generators/settler/templates/settler.yml +30 -0
- data/lib/setting.rb +8 -2
- data/lib/settler.rb +2 -0
- data/settler.gemspec +7 -2
- metadata +9 -4
data/README.rdoc
CHANGED
@@ -24,7 +24,8 @@ Or install as a plugin if you must. But gems are cooler.
|
|
24
24
|
|
25
25
|
* You must create the table used by the Setting model and install an initial configuration file. Simply run this command:
|
26
26
|
|
27
|
-
ruby script/generate settler
|
27
|
+
rails2: ruby script/generate settler
|
28
|
+
rails3: rails g settler
|
28
29
|
|
29
30
|
* This will create a migration and will add a settler.yml configuration file in your config directory. Now just migrate the database:
|
30
31
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.1
|
data/init.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
class SettlerGenerator < Rails::Generators::Base
|
2
|
+
include Rails::Generators::Migration
|
3
|
+
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
def generate_migration
|
7
|
+
migration_template "migration.rb", "db/migrate/create_settings_table.rb"
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_settler_configruration
|
11
|
+
copy_file 'settler.yml', 'config/settler.yml'
|
12
|
+
end
|
13
|
+
|
14
|
+
# Implement the required interface for Rails::Generators::Migration.
|
15
|
+
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
16
|
+
def self.next_migration_number(dirname)
|
17
|
+
if ActiveRecord::Base.timestamped_migrations
|
18
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
19
|
+
else
|
20
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateSettingsTable < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :settings, :force => true do |t|
|
4
|
+
t.string :key, :null => false
|
5
|
+
t.string :alt
|
6
|
+
t.text :value
|
7
|
+
t.boolean :editable
|
8
|
+
t.boolean :deletable
|
9
|
+
t.boolean :deleted
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
13
|
+
add_index :settings, :key
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
drop_table :settings
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
settings: &settings
|
2
|
+
google_analytics_key: &google
|
3
|
+
alt: Google analytics key
|
4
|
+
value: 'UA-xxxxxx-x'
|
5
|
+
editable: true
|
6
|
+
deletable: false
|
7
|
+
validations:
|
8
|
+
presence: true
|
9
|
+
search_algorithm:
|
10
|
+
alt: Default search engine
|
11
|
+
value: 'ferret'
|
12
|
+
editable: true
|
13
|
+
validations:
|
14
|
+
inclusion: [ 'ferret' , 'sphinx' ]
|
15
|
+
white_list:
|
16
|
+
alt: 'White-listed words'
|
17
|
+
value: 'herp, derp'
|
18
|
+
|
19
|
+
development:
|
20
|
+
<<: *settings
|
21
|
+
google_analytics_key:
|
22
|
+
<<: *google
|
23
|
+
alt: Development Google analytics key
|
24
|
+
value: 'UA-xxxxxx-1'
|
25
|
+
|
26
|
+
test:
|
27
|
+
<<: *settings
|
28
|
+
|
29
|
+
production:
|
30
|
+
<<: *settings
|
data/lib/setting.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'type_casters'
|
2
|
+
require 'default_scope_patch' if defined?(ActiveRecord::VERSION) && ActiveRecord::VERSION::MAJOR >= 3
|
2
3
|
|
3
4
|
# The Setting class is an AR model that encapsulates a Settler setting. The key if the setting is the only required attribute.\
|
4
5
|
class Setting < ActiveRecord::Base
|
@@ -10,11 +11,16 @@ class Setting < ActiveRecord::Base
|
|
10
11
|
|
11
12
|
validates_presence_of :key
|
12
13
|
validate :setting_validations
|
13
|
-
if rails3 then validate(:ensure_editable, :on => :update) else validate_on_update(:ensure_editable) end
|
14
14
|
|
15
15
|
serialize :value
|
16
16
|
|
17
|
-
|
17
|
+
if rails3
|
18
|
+
validate(:ensure_editable, :on => :update)
|
19
|
+
default_scope lambda{ where(['deleted = ? or deleted IS NULL', false]) }
|
20
|
+
else
|
21
|
+
validate_on_update(:ensure_editable)
|
22
|
+
default_scope :conditions => ['deleted = ? or deleted IS NULL', false]
|
23
|
+
end
|
18
24
|
|
19
25
|
scope_method = rails3 ? :scope : :named_scope
|
20
26
|
send scope_method, :editable, :conditions => { :editable => true }
|
data/lib/settler.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'erb'
|
3
3
|
require 'hash_extension'
|
4
|
+
require 'setting'
|
5
|
+
require 'type_casters'
|
4
6
|
|
5
7
|
# Settler loads and manages application wide settings and provides an interface for retrieving settings. The Settler
|
6
8
|
# object cannot be instantiated; all functionality is available on class level.
|
data/settler.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{settler}
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Reinier de Lange"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-02-24}
|
13
13
|
s.description = %q{This gem is a combination of the Squeegy's rails-settings and Binarylogic's settingslogic gem, meaning it reads its configuration from a YAML file, but stores all settings in the database as well for on the fly changes.}
|
14
14
|
s.email = %q{r.j.delange@nedforce.nl}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,6 +27,11 @@ Gem::Specification.new do |s|
|
|
27
27
|
"generators/settler/templates/migration.rb",
|
28
28
|
"generators/settler/templates/settler.yml",
|
29
29
|
"init.rb",
|
30
|
+
"lib/default_scope_patch.rb",
|
31
|
+
"lib/generators/settler/USAGE",
|
32
|
+
"lib/generators/settler/settler_generator.rb",
|
33
|
+
"lib/generators/settler/templates/migration.rb",
|
34
|
+
"lib/generators/settler/templates/settler.yml",
|
30
35
|
"lib/hash_extension.rb",
|
31
36
|
"lib/setting.rb",
|
32
37
|
"lib/settler.rb",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: settler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 1
|
10
|
+
version: 1.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Reinier de Lange
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-02-24 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -39,6 +39,11 @@ files:
|
|
39
39
|
- generators/settler/templates/migration.rb
|
40
40
|
- generators/settler/templates/settler.yml
|
41
41
|
- init.rb
|
42
|
+
- lib/default_scope_patch.rb
|
43
|
+
- lib/generators/settler/USAGE
|
44
|
+
- lib/generators/settler/settler_generator.rb
|
45
|
+
- lib/generators/settler/templates/migration.rb
|
46
|
+
- lib/generators/settler/templates/settler.yml
|
42
47
|
- lib/hash_extension.rb
|
43
48
|
- lib/setting.rb
|
44
49
|
- lib/settler.rb
|