Skip to content
This repository has been archived by the owner on Mar 20, 2018. It is now read-only.

Commit

Permalink
Adding an app settings table and constract to attempt to move these t…
Browse files Browse the repository at this point in the history
…hings out of config files.
  • Loading branch information
bguthrie committed Aug 8, 2013
1 parent 8bf9b91 commit 99ec368
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 84 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -57,6 +57,7 @@ gem 'aws-sdk'
gem 'garb'
gem 'oauth'
gem 'rails_config'
gem 'activerecord-postgres-hstore'

# To use ActiveModel has_secure_password
gem 'bcrypt-ruby', '~> 3.0.0'
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Expand Up @@ -56,6 +56,10 @@ GEM
activesupport (= 3.2.12)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activerecord-postgres-hstore (0.7.6)
activerecord (>= 3.1)
pg-hstore (>= 1.1.5)
rake
activeresource (3.2.12)
activemodel (= 3.2.12)
activesupport (= 3.2.12)
Expand Down Expand Up @@ -197,6 +201,7 @@ GEM
nokogiri (1.5.6)
oauth (0.4.7)
pg (0.14.1)
pg-hstore (1.2.0)
polyglot (0.3.3)
premailer (1.7.3)
css_parser (>= 1.1.9)
Expand Down Expand Up @@ -356,6 +361,7 @@ PLATFORMS

DEPENDENCIES
active_attr
activerecord-postgres-hstore
airbrake
anjlab-bootstrap-rails (>= 2.2)
aws-sdk
Expand Down
32 changes: 32 additions & 0 deletions app/models/app_settings.rb
@@ -0,0 +1,32 @@
class AppSettings < ActiveRecord::Base
serialize :data, ActiveRecord::Coders::Hstore
self.table_name = "settings"

class << self

def instance
@instance ||= ( self.first || self.create )
end

def create_with_instance_checking(*args)
if self.first.nil?
create_without_instance_checking(*args)
else
raise "Can't create a new instance."
end
end

alias_method_chain :create, :instance_checking

def [](key)
self.instance.data[key]
end

def []=(key, value)
self.instance.data[key] = value
self.instance.save
value
end

end
end
8 changes: 8 additions & 0 deletions db/migrate/20130807232909_add_hstore_settings_to_app.rb
@@ -0,0 +1,8 @@
class AddHstoreSettingsToApp < ActiveRecord::Migration
def change
create_table :settings do |t|
t.hstore :data
t.timestamps
end
end
end

0 comments on commit 99ec368

Please sign in to comment.