fiona 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.markdown +54 -6
  2. data/VERSION +1 -1
  3. data/fiona.gemspec +2 -2
  4. data/lib/template.rb +19 -0
  5. metadata +15 -15
data/README.markdown CHANGED
@@ -1,4 +1,4 @@
1
- # fiona - Rails 3 configuration data engine.
1
+ # Fiona - Rails 3 configuration data engine.
2
2
 
3
3
  Fiona lets you store unstructured configuration data in your SQL database.
4
4
  Examples include application settings and template data.
@@ -8,17 +8,66 @@ Any JSON compatible datastructures and values are permitted (integer, float, str
8
8
 
9
9
  * Activerecord (tested with Rails 3.1)
10
10
 
11
- ## Installation
11
+ ## Gem Installation
12
12
 
13
- gem install fiona
13
+ ### With bundler
14
14
 
15
- If you are using bundler, add the following to your Gemfile:
15
+ Add the following to your Gemfile and run the 'bundle' command to update your Gemfile.lock:
16
16
 
17
17
  gem "fiona"
18
18
 
19
+ ### Without bundler
20
+
21
+ gem install "fiona"
22
+
23
+ ## configuration
24
+
25
+ After you install the gem, you need to generate Fiona's migration:
26
+
27
+ rails generate fiona
28
+
29
+ This should create a migration named create_fiona_tables.rb in your Rails project.
30
+
19
31
  ## Usage
20
32
 
21
- TODO
33
+ Fiona has uses two models (Template and TemplateAttribute).
34
+ Template is an STI table so it is recommended that you subclass it as necessary.
35
+
36
+ Example app/models/setting_template.rb:
37
+
38
+ class SettingTemplate < Template
39
+ end
40
+
41
+ Create a template for application settings:
42
+
43
+ settings = SettingTemplate.new
44
+ settings.key = 'my_settings'
45
+ settings.app_name = 'My cool app'
46
+ settings.domain_name = 'somedomain.com'
47
+ settings.email_addresses = {:support => 'support@somedomain.com', :sales => 'sales@somedomain.com'}
48
+ settings.save!
49
+
50
+ Create a convenient constant for accessing your settings (config/initializers/fiona.rb):
51
+
52
+ SETTINGS = SettingTemplate.find_by_key('my_settings')
53
+
54
+ You can now access your settings at any time:
55
+
56
+ puts SETTINGS.domain_name
57
+
58
+ You can change your settings easily whenever you want:
59
+
60
+ SETTINGS.whatever = 5
61
+ SETTINGS.save!
62
+
63
+ Note: you will need to restart your Rails processes whenever settings change in order for all processes to see the changes.
64
+
65
+ ## TODO
66
+
67
+ * Create a generator for creating subclasses of Template.
68
+ * Keep projects clean by storing all template subclasses in app/templates instead of the models directory.
69
+ * Create a singleton for simplifying template access.
70
+ * Improve caching.
22
71
 
23
72
  ## Contributing to fiona
24
73
 
@@ -34,4 +83,3 @@ TODO
34
83
 
35
84
  Copyright (c) 2011 Chad Remesch. See LICENSE.txt for
36
85
  further details.
37
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
data/fiona.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "fiona"
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chad Remesch"]
12
- s.date = "2011-12-19"
12
+ s.date = "2011-12-20"
13
13
  s.description = "Easily store and use template data with Rails."
14
14
  s.email = "chad@remesch.com"
15
15
  s.extra_rdoc_files = [
data/lib/template.rb CHANGED
@@ -21,6 +21,8 @@ class Template < ActiveRecord::Base
21
21
  method = method.to_sym
22
22
  if processed_attributes.keys.include?(method)
23
23
  return processed_attributes[method]
24
+ elsif default_attributes.keys.include?(method)
25
+ return default_attributes[method]
24
26
  end
25
27
  end
26
28
 
@@ -54,4 +56,21 @@ class Template < ActiveRecord::Base
54
56
 
55
57
  return @processed_attributes
56
58
  end
59
+
60
+ def default_attributes
61
+ return @default_attributes || {}
62
+ end
63
+
64
+ def default_attributes=(defaults)
65
+ @default_attributes = defaults
66
+ end
67
+
68
+ def delete_attribute(attribute)
69
+ if processed_attributes.include?(attribute)
70
+ raw_attributes.where(:key => attribute).map{ |a| a.destroy }
71
+ return processed_attributes.delete(attribute)
72
+ else
73
+ return nil
74
+ end
75
+ end
57
76
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fiona
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-19 00:00:00.000000000Z
12
+ date: 2011-12-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70140526965060 !ruby/object:Gem::Requirement
16
+ requirement: &70318901733500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70140526965060
24
+ version_requirements: *70318901733500
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70140526964560 !ruby/object:Gem::Requirement
27
+ requirement: &70318901732620 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.3.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70140526964560
35
+ version_requirements: *70318901732620
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &70140526964020 !ruby/object:Gem::Requirement
38
+ requirement: &70318901723420 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70140526964020
46
+ version_requirements: *70318901723420
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &70140526963280 !ruby/object:Gem::Requirement
49
+ requirement: &70318901722780 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70140526963280
57
+ version_requirements: *70318901722780
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &70140526962700 !ruby/object:Gem::Requirement
60
+ requirement: &70318901722100 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70140526962700
68
+ version_requirements: *70318901722100
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdoc
71
- requirement: &70140526962140 !ruby/object:Gem::Requirement
71
+ requirement: &70318901721520 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70140526962140
79
+ version_requirements: *70318901721520
80
80
  description: Easily store and use template data with Rails.
81
81
  email: chad@remesch.com
82
82
  executables: []
@@ -118,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  segments:
120
120
  - 0
121
- hash: 875471196289828848
121
+ hash: -1829553723956385784
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  none: false
124
124
  requirements: