app-config 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.1
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - ree
@@ -0,0 +1,155 @@
1
+ # AppConfig
2
+
3
+ AppConfig is a library to manage your (web) application dynamic settings with flexible access and configuration strategy.
4
+
5
+ Primary datasource for AppConfig is an ActiveRecord model.
6
+
7
+ ## Installation
8
+
9
+ via rubygems:
10
+
11
+ gem install app-config
12
+
13
+ via github:
14
+
15
+ git clone git://github.com/sosedoff/app-config.git
16
+ cd app-config
17
+ gem build
18
+ gem install app-config-x.y.z.gem
19
+
20
+ ## Supported platforms
21
+
22
+ - Ruby 1.8.7
23
+ - Ruby EE 1.8.7
24
+ - Ruby 1.9.2
25
+
26
+ ## Data Formats
27
+
28
+ You can use following formats:
29
+ - String
30
+ - Boolean
31
+ - Array
32
+ - Hash
33
+
34
+ String format is a default format. Everything is a string by default.
35
+
36
+ Boolean format is just a flag, values 'true', 'on', 'yes', 'y', '1' are equal to True. Everything else is False.
37
+
38
+ Array format is a multiline text which is transformed into array. Each evelemnt will be trimmed. Empty strings are ignored.
39
+
40
+ Hash format is special key-value string, "foo: bar, user: username", which is transformed into Hash instance.
41
+ Only format "keyname: value, keyname2: value2" is supported. No nested hashes allowed.
42
+
43
+ ## Usage
44
+
45
+ AppConfig is designed to work with ActiveRecord model. Only ActiveRecord >= 3.0.0 is supported.
46
+
47
+ By default model "Setting" will be used as a data source.
48
+
49
+ ### Setup
50
+
51
+ In order to use AppConfig you should have a source table, similar to this:
52
+
53
+ ```ruby
54
+ class CreateSettings < ActiveRecord::Migration
55
+ def self.up
56
+ create_table :settings do |t|
57
+ t.string :keyname, :null => false, :limit => 64
58
+ t.text :value, :null => false
59
+ t.string :value_format, :limit => 64, :default => "string"
60
+ t.string :name, :limit => 64
61
+ t.string :description, :limit => 512
62
+ t.timestamps
63
+ end
64
+ end
65
+
66
+ def self.down
67
+ drop_table :settings
68
+ end
69
+ end
70
+ ```
71
+
72
+ Required columns are:
73
+
74
+ - keyname
75
+ - value
76
+ - value_format
77
+
78
+ Columns **:name** and **:description** are optional and used only for informative purpose (ex: show name and description in admin panel).
79
+
80
+ There is no need in indexes since the data is being loaded only once on application start.
81
+
82
+ Simple model with validations should look like this:
83
+
84
+ ```ruby
85
+ class Setting < ActiveRecord::Base
86
+ validates_presence_of :keyname, :value
87
+ validates_uniqueness_of :keyname
88
+ end
89
+ ```
90
+
91
+ ### Configuration
92
+
93
+ Default configuration method is:
94
+
95
+ ```ruby
96
+ AppConfig.configure
97
+ ```
98
+
99
+ If your settings model has a different schema, you can redefine columns:
100
+
101
+ ```ruby
102
+ AppConfig.configure(
103
+ :model => Setting, # model class name as source
104
+ :key => 'KEYNAME_FIELD', # field that contains name
105
+ :format => 'FORMAT_FIELD', # field that contains key format
106
+ :value => 'VALUE_FIELD', # field that contains value data
107
+ )
108
+ ```
109
+
110
+ Load all settings somewhere in your application. In Rails it should be initializer file.
111
+
112
+ ```ruby
113
+ AppConfig.load
114
+ ```
115
+
116
+ Configuration in Rails 3: (you can put this into environment/ENV or application.rb)
117
+ Make sure your application does not have any critical parts depending on AppConfig at startup.
118
+
119
+ ```ruby
120
+ config.after_initialize do
121
+ AppConfig.configure(:model => Setting)
122
+ AppConfig.load if Setting.table_exists?
123
+ end
124
+ ```
125
+
126
+ AppConfig gives you 3 ways to access variables:
127
+
128
+ ```ruby
129
+ AppConfig.my_setting # method-like
130
+ AppConfig[:my_setting] # hash-like by symbol key
131
+ AppConfig['my_setting'] # hash-like by string key
132
+ ```
133
+
134
+ You can define settings items manually.
135
+ **NOTE:** *THESE KEYS WILL BE REMOVED ON RELOAD/LOAD.*
136
+
137
+ ```ruby
138
+ AppConfig.set_key('KEYNAME', 'VALUE', 'FORMAT')
139
+ ```
140
+
141
+ Everytime you change your settings on the fly, use reload:
142
+
143
+ ```ruby
144
+ AppConfig.reload
145
+ ```
146
+
147
+ Cleanup everything:
148
+
149
+ ```ruby
150
+ AppConfig.flush
151
+ ```
152
+
153
+ ## Copyright
154
+
155
+ Copyright (c) 2011 Dan Sosedoff.
@@ -1,3 +1,4 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  require File.expand_path('../lib/app-config/version', __FILE__)
2
3
 
3
4
  Gem::Specification.new do |s|
@@ -10,18 +11,15 @@ Gem::Specification.new do |s|
10
11
  s.email = ["dan.sosedoff@gmail.com"]
11
12
  s.license = "MIT"
12
13
 
13
- s.add_development_dependency 'rake', '~> 0.8'
14
- s.add_development_dependency 'rspec', '~> 2.6'
15
- s.add_development_dependency 'simplecov', '~> 0.4'
16
- s.add_development_dependency 'sqlite3', '~> 1.3'
17
-
18
- s.add_runtime_dependency 'activerecord', '~> 3.0.0'
19
-
20
14
  s.files = `git ls-files`.split("\n")
21
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
23
17
  s.require_paths = ["lib"]
24
18
 
25
- s.platform = Gem::Platform::RUBY
26
- s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
19
+ s.add_development_dependency 'rake', '~> 0.8'
20
+ s.add_development_dependency 'rspec', '~> 2.6'
21
+ s.add_development_dependency 'simplecov', '~> 0.4'
22
+ s.add_development_dependency 'sqlite3', '~> 1.3'
23
+
24
+ s.add_runtime_dependency 'activerecord', '~> 3.0'
27
25
  end
@@ -1,5 +1,4 @@
1
- require 'active_record'
2
-
1
+ require 'app-config/version'
3
2
  require 'app-config/errors'
4
3
  require 'app-config/processor'
5
- require 'app-config/app-config'
4
+ require 'app-config/app-config'
@@ -1,3 +1,5 @@
1
+ require 'active_record'
2
+
1
3
  module AppConfig
2
4
  extend AppConfig::Processor
3
5
 
@@ -96,8 +98,8 @@ module AppConfig
96
98
 
97
99
  # Fetch data from model
98
100
  def self.fetch
99
- raise InvalidSource, 'Model is not defined!' if @@options[:model].nil?
100
- raise InvalidSource, 'Model was not found!' unless @@options[:model].superclass == ActiveRecord::Base
101
+ raise InvalidSource, 'Model is not defined!' if @@options[:model].nil?
102
+ raise InvalidSource, 'Model was not found!' unless @@options[:model].superclass == ActiveRecord::Base
101
103
  raise InvalidSource, 'Model fields are invalid!' unless check_structure
102
104
 
103
105
  records = {}
@@ -1,6 +1,6 @@
1
1
  module AppConfig
2
- class InvalidType < Exception ; end
3
- class InvalidKeyName < Exception ; end
4
- class InvalidSource < Exception ; end
5
- class UndefinedKey < Exception ; end
2
+ class InvalidType < RuntimeError ; end
3
+ class InvalidKeyName < RuntimeError ; end
4
+ class InvalidSource < RuntimeError ; end
5
+ class UndefinedKey < RuntimeError ; end
6
6
  end
@@ -1,3 +1,5 @@
1
1
  module AppConfig
2
- VERSION = '0.1.1'.freeze
3
- end
2
+ unless defined?(::AppConfig::VERSION)
3
+ VERSION = '0.1.2'.freeze
4
+ end
5
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: app-config
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dan Sosedoff
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-15 00:00:00 -05:00
13
+ date: 2011-08-05 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -65,7 +65,7 @@ dependencies:
65
65
  requirements:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: 3.0.0
68
+ version: "3.0"
69
69
  type: :runtime
70
70
  version_requirements: *id005
71
71
  description: Flexible and simple configuration settings for your Rails/Sinatra applications.
@@ -80,9 +80,10 @@ extra_rdoc_files: []
80
80
  files:
81
81
  - .gitignore
82
82
  - .rspec
83
+ - .travis.yml
83
84
  - Gemfile
84
85
  - LICENSE.txt
85
- - README.rdoc
86
+ - README.md
86
87
  - Rakefile
87
88
  - app-config.gemspec
88
89
  - lib/app-config.rb
@@ -114,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  requirements:
115
116
  - - ">="
116
117
  - !ruby/object:Gem::Version
117
- version: 1.3.6
118
+ version: "0"
118
119
  requirements: []
119
120
 
120
121
  rubyforge_project:
@@ -1,113 +0,0 @@
1
- = AppConfig
2
-
3
- AppConfig is a library to manage your (web) application dynamic settings with flexible access and configuration strategy.
4
-
5
- Primary datasource for AppConfig is an ActiveRecord model.
6
-
7
- == Installation
8
-
9
- via rubygems:
10
-
11
- gem install app-config
12
-
13
- via github:
14
-
15
- git clone git://github.com/sosedoff/app-config.git
16
- cd app-config
17
- gem build
18
- gem install app-config-x.y.z.gem
19
-
20
- == Supported platforms
21
-
22
- - Ruby 1.8.7
23
- - Ruby REE 1.8.7
24
- - Ruby 1.9.2
25
-
26
- == Data Formats
27
-
28
- You can use following formats:
29
- - String
30
- - Boolean
31
- - Array
32
- - Hash
33
-
34
- String format is a default format. Everything is a string by default.
35
-
36
- Boolean format is just a flag, values 'true', 'on', 'yes', 'y', '1' are equal to True. Everything else is False.
37
-
38
- Array format is a multiline text which is transformed into array. Each evelemnt will be trimmed. Empty strings are ignored.
39
-
40
- Hash format is special key-value string, "foo: bar, user: username", which is transformed into Hash instance.
41
- Only format "keyname: value, keyname2: value2" is supported. No nested hashes allowed.
42
-
43
- == Usage
44
-
45
- AppConfig is designed to work with ActiveRecord model. Only ActiveRecord >= 3.0.0 is supported.
46
-
47
- By default model "Setting" will be used as a data source.
48
-
49
- Default migration:
50
-
51
- class CreateSettings < ActiveRecord::Migration
52
- def self.up
53
- create_table :settings do |t|
54
- t.string :keyname, :null => false, :limit => 64
55
- t.string :name, :null => false, :limit => 64
56
- t.text :value, :null => false
57
- t.string :value_format, :limit => 64, :default => "string"
58
- t.string :description, :limit => 512, :null => false
59
- t.timestamps
60
- end
61
- end
62
-
63
- def self.down
64
- drop_table :settings
65
- end
66
- end
67
-
68
- Now, configure:
69
-
70
- AppConfig.configure
71
-
72
- If your settings model has a different schema, you can redefine columns:
73
-
74
- AppConfig.configure(
75
- :model => Setting, # define your model as a source
76
- :key => 'KEYNAME_FIELD', # field that contains name
77
- :format => 'FORMAT_FIELD', # field that contains key format
78
- :value => 'VALUE_FIELD', #field that contains value data
79
- )
80
-
81
- Load all settings somewhere in your application. In Rails it should be initializer file.
82
-
83
- AppConfig.load
84
-
85
- Configuration in Rails 3: (you can put this into environment/ENV or application.rb)
86
- Make sure your application does not have any critical parts depending on AppConfig at startup.
87
-
88
- config.after_initialize do
89
- AppConfig.configure(:model => Setting)
90
- AppConfig.load if Setting.table_exists?
91
- end
92
-
93
- AppConfig gives you 3 ways to access variables:
94
-
95
- AppConfig.my_setting # method-like
96
- AppConfig[:my_setting] # hash-like by symbol key
97
- AppConfig['my_setting'] # hash-like by string key
98
-
99
- You can define settings items manually. NOTE: THESE KEYS WILL BE REMOVED ON RELOAD/LOAD.
100
-
101
- AppConfig.set('KEYNAME, 'VALUE', 'FORMAT')
102
-
103
- Everytime you change your settings on the fly, use reload:
104
-
105
- AppConfig.reload
106
-
107
- Cleanup everything:
108
-
109
- AppConfig.flush
110
-
111
- == Copyright
112
-
113
- Copyright (c) 2011 Dan Sosedoff.