fiona 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -6,70 +6,52 @@ Any JSON compatible datastructures and values are permitted (integer, float, str
6
6
 
7
7
  ## Requirements
8
8
 
9
- * Activerecord (tested with Rails 3.1)
9
+ * Rails 3.x (tested with Rails 3.1)
10
10
 
11
11
  ## Gem Installation
12
12
 
13
13
  ### With bundler
14
14
 
15
- Add the following to your Gemfile and run the 'bundle' command to update your Gemfile.lock:
15
+ Add the following to your Gemfile and run the 'bundle' command:
16
16
 
17
17
  gem "fiona"
18
18
 
19
- ### Without bundler
19
+ ## Configuration
20
20
 
21
- gem install "fiona"
22
-
23
- ## configuration
24
-
25
- After you install the gem, you need to generate Fiona's migration:
21
+ After you install the gem, you need to run Fiona's generator:
26
22
 
27
23
  rails generate fiona
28
24
 
29
- This should create a migration named create_fiona_tables.rb in your Rails project.
30
-
31
25
  ## Usage
32
26
 
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):
27
+ Create an instance of Template:
51
28
 
52
- SETTINGS = SettingTemplate.find_by_key('my_settings')
29
+ t = Template.new(:key => 'some_template')
30
+ t.some_var = 'some sweet value'
31
+ t.save!
53
32
 
54
- You can now access your settings at any time:
33
+ In the above example, 't' can have as many variables associated with it
34
+ as you want. Their values can be any JSON supported datatype including
35
+ hashes, array, strings, etc.
55
36
 
56
- puts SETTINGS.domain_name
37
+ ### Subclassing
57
38
 
58
- You can change your settings easily whenever you want:
39
+ The Template class can be subclassed since it uses Rails STI. The
40
+ included SettingsTemplate feature is an example of this.
59
41
 
60
- SETTINGS.whatever = 5
61
- SETTINGS.save!
42
+ ### SettingsTemplate
62
43
 
63
- Note: you will need to restart your Rails processes whenever settings change in order for all processes to see the changes.
44
+ Fiona comes with a template class named SettingsTemplate and an
45
+ associated Rails initializer. Together they simplify the management of
46
+ application settings and provide your application with globally
47
+ accessible settings through the 'S' constant.
64
48
 
65
49
  ## TODO
66
50
 
67
51
  * 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
52
  * Improve caching.
71
53
 
72
- ## Contributing to fiona
54
+ ## Contributing to Fiona
73
55
 
74
56
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
75
57
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.0.10
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.9"
8
+ s.version = "0.0.10"
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-20"
12
+ s.date = "2011-12-21"
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 = [
@@ -1,7 +1,10 @@
1
- # defaults = {
2
- # app_name: 'My Awesome Rails App'
3
- # }
4
- #
5
- # S = SettingsTemplate.find_or_initialize_by_key('settings')
6
- # S.default_attributes = defaults
7
- # S.save!
1
+ defaults = {
2
+ app_name: 'My Awesome Rails App'
3
+ }
4
+
5
+ begin
6
+ S = SettingsTemplate.find_or_initialize_by_key('settings')
7
+ S.default_attributes = defaults
8
+ S.save!
9
+ rescue
10
+ end
data/lib/template.rb CHANGED
@@ -74,4 +74,8 @@ class Template < ActiveRecord::Base
74
74
  return nil
75
75
  end
76
76
  end
77
+
78
+ def all_attributes
79
+ return default_attributes.dup.merge(processed_attributes)
80
+ end
77
81
  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.9
4
+ version: 0.0.10
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-20 00:00:00.000000000Z
12
+ date: 2011-12-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70154956904260 !ruby/object:Gem::Requirement
16
+ requirement: &70149798694900 !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: *70154956904260
24
+ version_requirements: *70149798694900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70154956901980 !ruby/object:Gem::Requirement
27
+ requirement: &70149798693100 !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: *70154956901980
35
+ version_requirements: *70149798693100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &70154956899720 !ruby/object:Gem::Requirement
38
+ requirement: &70149798692180 !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: *70154956899720
46
+ version_requirements: *70149798692180
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &70154956896880 !ruby/object:Gem::Requirement
49
+ requirement: &70149798691140 !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: *70154956896880
57
+ version_requirements: *70149798691140
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &70154956894440 !ruby/object:Gem::Requirement
60
+ requirement: &70149798690080 !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: *70154956894440
68
+ version_requirements: *70149798690080
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdoc
71
- requirement: &70154956892240 !ruby/object:Gem::Requirement
71
+ requirement: &70149798689060 !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: *70154956892240
79
+ version_requirements: *70149798689060
80
80
  description: Easily store and use template data with Rails.
81
81
  email: chad@remesch.com
82
82
  executables: []
@@ -120,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  segments:
122
122
  - 0
123
- hash: 3628875406415562831
123
+ hash: 3233879644313255055
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  none: false
126
126
  requirements: