static_record 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +43 -0
- data/Rakefile +9 -0
- data/lib/static_record.rb +25 -0
- data/test/fixtures/yodlee_error.rb +2 -0
- data/test/fixtures/yodlee_errors.yml +17 -0
- data/test/functional/static_record_test.rb +10 -0
- data/test/test_helper.rb +5 -0
- metadata +73 -0
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
static_record
|
2
|
+
=============
|
3
|
+
|
4
|
+
In some cases creating database table for storing immutable records just so you can join data is an overkill. By immutable records think hard-coded categories, 3rd party API error codes, ... in general data that is controlled by developers rather than users. With such data you are much better of not using database for it - imaging creating migration for every update on i.e.. category description. Creating GUI for it is certainly an option if you don't mind throwing more code into the project for this trivial task.
|
5
|
+
|
6
|
+
StaticRecord provides you with the preloading schema-free objects from Yaml to OpenStruct that you can join to your ActiveRecord or any other model.
|
7
|
+
|
8
|
+
## Install
|
9
|
+
|
10
|
+
gem install static_record
|
11
|
+
|
12
|
+
|
13
|
+
## Example usage
|
14
|
+
|
15
|
+
Create model class
|
16
|
+
|
17
|
+
class Category < StaticRecord::Base
|
18
|
+
end
|
19
|
+
|
20
|
+
and in the same directory provide file called categories.yml
|
21
|
+
|
22
|
+
1:
|
23
|
+
name: Watches
|
24
|
+
description: We make vibrant and bold watches for vibrant and bold people
|
25
|
+
|
26
|
+
2:
|
27
|
+
name: Jewelery
|
28
|
+
description: We have a range of original chunky silver jewellery including pendants from the Poseidon collection such as the Easter Island pendant
|
29
|
+
|
30
|
+
and you're all set:
|
31
|
+
|
32
|
+
>> pp Category.all
|
33
|
+
=> {1=>#<Category ...>, 2=>#<Category ...>}
|
34
|
+
|
35
|
+
>> c = Category.find(1)
|
36
|
+
=> #<Category description="We make vibrant and bold watches for vibrant and bold people", name="Watches", id=1>
|
37
|
+
|
38
|
+
>> c.name
|
39
|
+
=> "Watches"
|
40
|
+
|
41
|
+
## Credits
|
42
|
+
|
43
|
+
Author: [Dejan Simic](http://github.com/dejan)
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'active_support/core_ext/string'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module StaticRecord
|
5
|
+
class Base < OpenStruct
|
6
|
+
|
7
|
+
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
|
+
@@all = {}
|
11
|
+
yaml_data.each do |key, value|
|
12
|
+
@@all[key] = klass.new({:id => key}.merge(value))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.all
|
17
|
+
@@all
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.find(id)
|
21
|
+
all[id]
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
0:
|
2
|
+
name: STATUS_OK
|
3
|
+
group: ok
|
4
|
+
|
5
|
+
400:
|
6
|
+
name: STATUS_INVALID_GATHERER_REQUEST
|
7
|
+
|
8
|
+
401:
|
9
|
+
name: STATUS_NO_CONNECTION
|
10
|
+
group: temp
|
11
|
+
description:
|
12
|
+
This is a temporary issue and subsequent refreshes should work fine.
|
13
|
+
If it persists the issue has to be reported to Yodlee to be fixed.
|
14
|
+
|
15
|
+
402:
|
16
|
+
name: STATUS_LOGIN_FAILED
|
17
|
+
group: auth
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: static_record
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Dejan Simic
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-02 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
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.
|
23
|
+
email: desimic@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- Rakefile
|
32
|
+
- lib/static_record.rb
|
33
|
+
- test/fixtures/yodlee_error.rb
|
34
|
+
- test/fixtures/yodlee_errors.yml
|
35
|
+
- test/functional/static_record_test.rb
|
36
|
+
- test/test_helper.rb
|
37
|
+
- README.md
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://github.com/dejan/static_record
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
hash: 3
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.3.7
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Treat your immutable data differently
|
72
|
+
test_files: []
|
73
|
+
|