fiona 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "activerecord", ">= 3"
4
+
5
+ group :development do
6
+ gem "rspec", "~> 2.3.0"
7
+ gem "bundler", "~> 1.0.0"
8
+ gem "jeweler", "~> 1.6.4"
9
+ gem "rcov", ">= 0"
10
+ gem "rdoc"
11
+ end
@@ -0,0 +1,49 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.1.3)
5
+ activesupport (= 3.1.3)
6
+ builder (~> 3.0.0)
7
+ i18n (~> 0.6)
8
+ activerecord (3.1.3)
9
+ activemodel (= 3.1.3)
10
+ activesupport (= 3.1.3)
11
+ arel (~> 2.2.1)
12
+ tzinfo (~> 0.3.29)
13
+ activesupport (3.1.3)
14
+ multi_json (~> 1.0)
15
+ arel (2.2.1)
16
+ builder (3.0.0)
17
+ diff-lcs (1.1.3)
18
+ git (1.2.5)
19
+ i18n (0.6.0)
20
+ jeweler (1.6.4)
21
+ bundler (~> 1.0)
22
+ git (>= 1.2.5)
23
+ rake
24
+ json (1.6.3)
25
+ multi_json (1.0.4)
26
+ rake (0.9.2.2)
27
+ rcov (0.9.11)
28
+ rdoc (3.11)
29
+ json (~> 1.4)
30
+ rspec (2.3.0)
31
+ rspec-core (~> 2.3.0)
32
+ rspec-expectations (~> 2.3.0)
33
+ rspec-mocks (~> 2.3.0)
34
+ rspec-core (2.3.1)
35
+ rspec-expectations (2.3.0)
36
+ diff-lcs (~> 1.1.2)
37
+ rspec-mocks (2.3.0)
38
+ tzinfo (0.3.31)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ activerecord (>= 3)
45
+ bundler (~> 1.0.0)
46
+ jeweler (~> 1.6.4)
47
+ rcov
48
+ rdoc
49
+ rspec (~> 2.3.0)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Chad Remesch
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # fiona - Rails 3 configuration data engine.
2
+
3
+ Fiona lets you unstructured configuration data in your SQL database.
4
+ Examples include application settings and template data.
5
+
6
+ ## Requirements
7
+
8
+ * Activerecord (tested with Rails 3.1)
9
+
10
+ ## Installation
11
+
12
+ gem install fiona
13
+
14
+ If you are using bundler, add the following to your Gemfile:
15
+
16
+ gem "fiona"
17
+
18
+ ## Usage
19
+
20
+ TODO
21
+
22
+ ## Contributing to fiona
23
+
24
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
25
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
26
+ * Fork the project
27
+ * Start a feature/bugfix branch
28
+ * Commit and push until you are happy with your contribution
29
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
30
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
31
+
32
+ ## Copyright
33
+
34
+ Copyright (c) 2011 Chad Remesch. See LICENSE.txt for
35
+ further details.
36
+
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "fiona"
18
+ gem.homepage = "http://github.com/BlueFrogGaming/fiona"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Rails 3 database templating engine.}
21
+ gem.description = %Q{Easily store template data with simplicy. Easily access the data from anywhere in your application.}
22
+ gem.email = "chad@remesch.com"
23
+ gem.authors = ["Chad Remesch"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "fiona #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "fiona"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Chad Remesch"]
12
+ s.date = "2011-12-19"
13
+ s.description = "Easily store template data with simplicy. Easily access the data from anywhere in your application."
14
+ s.email = "chad@remesch.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.markdown",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "fiona.gemspec",
29
+ "lib/fiona.rb",
30
+ "lib/template.rb",
31
+ "lib/template_attribute.rb",
32
+ "spec/spec_helper.rb",
33
+ "spec/template_attribute_spec.rb",
34
+ "spec/template_spec.rb"
35
+ ]
36
+ s.homepage = "http://github.com/BlueFrogGaming/fiona"
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = "1.8.10"
40
+ s.summary = "Rails 3 database templating engine."
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<activerecord>, [">= 3"])
47
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
50
+ s.add_development_dependency(%q<rcov>, [">= 0"])
51
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<activerecord>, [">= 3"])
54
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
57
+ s.add_dependency(%q<rcov>, [">= 0"])
58
+ s.add_dependency(%q<rdoc>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<activerecord>, [">= 3"])
62
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
65
+ s.add_dependency(%q<rcov>, [">= 0"])
66
+ s.add_dependency(%q<rdoc>, [">= 0"])
67
+ end
68
+ end
69
+
@@ -0,0 +1,3 @@
1
+ require 'active_record'
2
+ require 'template'
3
+ require 'template_attribute'
@@ -0,0 +1,57 @@
1
+ class Template < ActiveRecord::Base
2
+ has_many :raw_attributes, :class_name => 'TemplateAttribute', :dependent => :destroy
3
+
4
+ after_save :save_attributes
5
+ after_initialize :rebuild_processed_attributes
6
+
7
+ def self.serialize_attribute(value)
8
+ return ActiveSupport::JSON.encode({:json => value})
9
+ end
10
+
11
+ def self.deserialize_attribute(value)
12
+ return ActiveSupport::JSON.decode(value)['json']
13
+ end
14
+
15
+ def method_missing(method, *args, &block)
16
+ if method.to_s =~ /=$/
17
+ method = method.to_s.gsub(/=$/, '').to_sym
18
+ processed_attributes[method] = args[0]
19
+ return args[1]
20
+ else
21
+ method = method.to_sym
22
+ if processed_attributes.keys.include?(method)
23
+ return processed_attributes[method]
24
+ end
25
+ end
26
+
27
+ super
28
+ end
29
+
30
+ def save_attributes
31
+ return unless @processed_attributes
32
+ raise 'You must first save the template.' unless id
33
+
34
+ @processed_attributes.each do |key, val|
35
+ TemplateAttribute.transaction do
36
+ raw_attr = TemplateAttribute.find_or_initialize_by_template_id_and_key(id, key)
37
+ raw_attr.value = Template.serialize_attribute(val)
38
+ raw_attr.save!
39
+ end
40
+ end
41
+ end
42
+
43
+ def processed_attributes
44
+ return @processed_attributes if @processed_attributes
45
+ return rebuild_processed_attributes
46
+ end
47
+
48
+ def rebuild_processed_attributes
49
+ @processed_attributes = {}
50
+
51
+ raw_attributes.each do |ra|
52
+ @processed_attributes[ra.key.to_sym] = Template.deserialize_attribute(ra.value)
53
+ end
54
+
55
+ return @processed_attributes
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ class TemplateAttribute < ActiveRecord::Base
2
+ belongs_to :template
3
+ end
@@ -0,0 +1,17 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'fiona'
5
+
6
+ begin
7
+ require 'ruby-debug'
8
+ rescue LoadError
9
+ end
10
+
11
+ # Requires supporting files with custom matchers and macros, etc,
12
+ # in ./support/ and its subdirectories.
13
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
14
+
15
+ RSpec.configure do |config|
16
+
17
+ end
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "TemplateAttributeSpec" do
4
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "TemplateSpec" do
4
+ context 'serialization' do
5
+ it 'should encode' do
6
+ Template.serialize_attribute({'foo' => 555}).should == "{\"json\":{\"foo\":555}}"
7
+ end
8
+
9
+ it 'should decode' do
10
+ result = Template.deserialize_attribute("{\"json\":{\"foo\":555}}")
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fiona
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chad Remesch
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: &70205626559920 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70205626559920
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70205626559200 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.3.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70205626559200
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70205626558500 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70205626558500
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &70205626557660 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70205626557660
58
+ - !ruby/object:Gem::Dependency
59
+ name: rcov
60
+ requirement: &70205626556940 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70205626556940
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: &70205626556140 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70205626556140
80
+ description: Easily store template data with simplicy. Easily access the data from
81
+ anywhere in your application.
82
+ email: chad@remesch.com
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files:
86
+ - LICENSE.txt
87
+ - README.markdown
88
+ files:
89
+ - .document
90
+ - .rspec
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE.txt
94
+ - README.markdown
95
+ - Rakefile
96
+ - VERSION
97
+ - fiona.gemspec
98
+ - lib/fiona.rb
99
+ - lib/template.rb
100
+ - lib/template_attribute.rb
101
+ - spec/spec_helper.rb
102
+ - spec/template_attribute_spec.rb
103
+ - spec/template_spec.rb
104
+ homepage: http://github.com/BlueFrogGaming/fiona
105
+ licenses:
106
+ - MIT
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ segments:
118
+ - 0
119
+ hash: -2424350401425242275
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 1.8.10
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: Rails 3 database templating engine.
132
+ test_files: []