static_model 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.2.2 2008-12-07
2
+
3
+ * 1 minor enhancements
4
+ * YAML data files can now include ERB - see tests for examples
5
+
1
6
  == 0.2.1 2008-12-03
2
7
 
3
8
  * 1 minor enhancement
@@ -77,7 +77,9 @@ module StaticModel
77
77
  return if loaded? && !reload
78
78
  raise(StaticModel::DataFileNotFound, "You must set a data file to load from") unless File.readable?(data_file)
79
79
  begin
80
- data = YAML::load_file(data_file)
80
+ raw_data = File.open(data_file) {|f| f.read }
81
+ parsed_data = ERB.new(raw_data).result
82
+ data = YAML::load(parsed_data)
81
83
  rescue
82
84
  raise(StaticModel::BadDataFile, "The data file you specified '#{data_file}' was not in a readable format.")
83
85
  end
@@ -2,7 +2,7 @@ module StaticModel #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/static_model.rb CHANGED
@@ -1,12 +1,15 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
- require 'yaml'
5
-
6
- require 'active_support/inflector'
7
- require 'active_support/core_ext/hash'
8
- require 'active_support/core_ext/string'
4
+ require 'yaml' unless defined?(YAML)
5
+ require 'erb' unless defined?(ERB)
9
6
 
7
+ unless defined?(ActiveSupport::CoreExtensions)
8
+ require 'active_support/inflector'
9
+ require 'active_support/core_ext/hash'
10
+ require 'active_support/core_ext/string'
11
+ require 'active_support/core_ext/integer'
12
+ end
10
13
 
11
14
  require 'static_model/errors'
12
15
  require 'static_model/associations'
data/test/test_helper.rb CHANGED
@@ -44,7 +44,10 @@ class Store < StaticModel::Base
44
44
 
45
45
  end
46
46
 
47
-
47
+ class Project < StaticModel::Base
48
+ set_data_file File.join(File.dirname(__FILE__), 'data', 'projects.yml')
49
+ belongs_to :author
50
+ end
48
51
 
49
52
  class Test::Unit::TestCase
50
53
 
@@ -147,6 +147,20 @@ class TestStaticModel < Test::Unit::TestCase
147
147
 
148
148
  end
149
149
  end
150
+
151
+ context "loading a data_file with embedded erb" do
152
+ setup do
153
+ @projects = Project.all
154
+ end
155
+
156
+ should "evaluate erb expressions at load time" do
157
+ assert_equal 1.day.ago.strftime('%m/%d/%Y %I:%M%p'), @projects.first.created_at
158
+ end
159
+
160
+ should "evaluate erb in current context" do
161
+ assert_equal Author.first, @projects[1].author
162
+ end
163
+ end
150
164
 
151
165
  context "find" do
152
166
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: static_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Quint
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-03 00:00:00 -05:00
12
+ date: 2008-12-07 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.8.2
33
+ version: 1.8.0
34
34
  version:
35
35
  description: ActiveRecord like functionalities for reading from YAML with a simple class implementation
36
36
  email:
@@ -43,6 +43,7 @@ extra_rdoc_files:
43
43
  - History.txt
44
44
  - License.txt
45
45
  - Manifest.txt
46
+ - README.rdoc
46
47
  files:
47
48
  - History.txt
48
49
  - License.txt
@@ -66,7 +67,7 @@ homepage: http://quirkey.rubyforge.org
66
67
  post_install_message: ""
67
68
  rdoc_options:
68
69
  - --main
69
- - README.txt
70
+ - README.rdoc
70
71
  require_paths:
71
72
  - lib
72
73
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -84,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
85
  requirements: []
85
86
 
86
87
  rubyforge_project: quirkey
87
- rubygems_version: 1.2.0
88
+ rubygems_version: 1.3.1
88
89
  signing_key:
89
90
  specification_version: 2
90
91
  summary: ActiveRecord like functionalities for reading from YAML with a simple class implementation