static_record 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/static_record.rb CHANGED
@@ -1,14 +1,20 @@
1
1
  require 'active_support/core_ext/string'
2
2
  require 'ostruct'
3
+ require 'yaml'
3
4
 
4
5
  module StaticRecord
5
6
  class Base < OpenStruct
6
7
 
7
8
  def self.inherited(klass)
8
- dir = File.dirname(caller.first.chop.chop)
9
- yaml_data = YAML.load(IO.read("#{dir}/#{klass.to_s.tableize}.yml"))
10
9
  @@all = {}
11
- yaml_data.each do |key, value|
10
+ dir = File.dirname(caller.first.chop.chop)
11
+ base_name = "#{dir}/#{klass.to_s.tableize}"
12
+ if File.exists?(f="#{base_name}.yml")
13
+ results = YAML.load(IO.read f)
14
+ else
15
+ raise "Seed data could not be found #{base_name}.yml"
16
+ end
17
+ results.each do |key, value|
12
18
  @@all[key] = klass.new({:id => key}.merge(value))
13
19
  end
14
20
  end
@@ -7,4 +7,4 @@ class StaticRecordTest < Test::Unit::TestCase
7
7
  assert !YodleeError.find(401).description.nil?
8
8
  end
9
9
 
10
- end
10
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: static_record
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
4
+ hash: 27
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dejan Simic
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-02 00:00:00 +01:00
19
- default_executable:
18
+ date: 2013-02-04 00:00:00 Z
20
19
  dependencies: []
21
20
 
22
21
  description: StaticRecord provides you with the preloading schema-free objects from Yaml to OpenStruct that you can join to your ActiveRecord or any other model.
@@ -35,7 +34,6 @@ files:
35
34
  - test/functional/static_record_test.rb
36
35
  - test/test_helper.rb
37
36
  - README.md
38
- has_rdoc: true
39
37
  homepage: http://github.com/dejan/static_record
40
38
  licenses: []
41
39
 
@@ -65,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
63
  requirements: []
66
64
 
67
65
  rubyforge_project:
68
- rubygems_version: 1.3.7
66
+ rubygems_version: 1.8.24
69
67
  signing_key:
70
68
  specification_version: 3
71
69
  summary: Treat your immutable data differently