static_model 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/History.txt +6 -0
- data/README.rdoc +5 -0
- data/Rakefile +31 -0
- data/index.html +80 -0
- data/lib/static_model/base.rb +12 -2
- data/lib/static_model.rb +6 -6
- data/static_model.gemspec +85 -0
- data/test/data/authors.yml +10 -0
- data/test/data/books.yml +22 -0
- data/test/data/empty.yml +0 -0
- data/test/data/pages.yml +16 -0
- data/test/data/projects.yml +7 -0
- data/test/data/publishers.yml +7 -0
- data/test/data/stores.yml +5 -0
- data/test/test_static_model.rb +472 -427
- metadata +40 -17
- data/Manifest.txt +0 -17
data/.gitignore
ADDED
data/History.txt
CHANGED
data/README.rdoc
CHANGED
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
%w[rubygems rake rake/clean rake/testtask fileutils].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/static_model'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |s|
|
7
|
+
s.name = %q{static_model}
|
8
|
+
s.version = StaticModel::VERSION
|
9
|
+
s.authors = ["Aaron Quint"]
|
10
|
+
s.date = %q{2009-12-03}
|
11
|
+
s.summary = 'ActiveRecord like functionalities for reading from YAML with a simple class implementation'
|
12
|
+
s.description = %q{StaticModel provides a Base class much like ActiveRecord which supports reading from a YAML file and basic associations to ActiveRecord}
|
13
|
+
s.rubyforge_project = %q{quirkey}
|
14
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.2.0"])
|
15
|
+
s.add_runtime_dependency(%q<rubigen>, [">= 1.5.1"])
|
16
|
+
s.add_development_dependency(%q<Shoulda>, [">= 1.2.0"])
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
Rake::TestTask.new do |t|
|
24
|
+
t.libs << "test"
|
25
|
+
t.test_files = FileList['test/test*.rb']
|
26
|
+
t.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
30
|
+
|
31
|
+
task :default => :test
|
data/index.html
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
7
|
+
|
8
|
+
<title>quirkey/static_model @ GitHub</title>
|
9
|
+
|
10
|
+
<style type="text/css">
|
11
|
+
body {
|
12
|
+
margin-top: 1.0em;
|
13
|
+
background-color: #65b1bc;
|
14
|
+
font-family: "helvetica";
|
15
|
+
color: #000000;
|
16
|
+
}
|
17
|
+
#container {
|
18
|
+
margin: 0 auto;
|
19
|
+
width: 700px;
|
20
|
+
}
|
21
|
+
h1 { font-size: 3.8em; color: #9a4e43; margin-bottom: 3px; }
|
22
|
+
h1 .small { font-size: 0.4em; }
|
23
|
+
h1 a { text-decoration: none }
|
24
|
+
h2 { font-size: 1.5em; color: #9a4e43; }
|
25
|
+
h3 { text-align: center; color: #9a4e43; }
|
26
|
+
a { color: #9a4e43; }
|
27
|
+
.description { font-size: 1.2em; margin-bottom: 30px; margin-top: 30px; font-style: italic;}
|
28
|
+
.download { float: right; }
|
29
|
+
pre { background: #000; color: #fff; padding: 15px;}
|
30
|
+
hr { border: 0; width: 80%; border-bottom: 1px solid #aaa}
|
31
|
+
.footer { text-align:center; padding-top:30px; font-style: italic; }
|
32
|
+
</style>
|
33
|
+
|
34
|
+
</head>
|
35
|
+
|
36
|
+
<body>
|
37
|
+
<a href="http://github.com/quirkey/static_model"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
|
38
|
+
|
39
|
+
<div id="container">
|
40
|
+
|
41
|
+
<div class="download">
|
42
|
+
<a href="http://github.com/quirkey/static_model/zipball/master">
|
43
|
+
<img border="0" width="90" src="http://github.com/images/modules/download/zip.png"></a>
|
44
|
+
<a href="http://github.com/quirkey/static_model/tarball/master">
|
45
|
+
<img border="0" width="90" src="http://github.com/images/modules/download/tar.png"></a>
|
46
|
+
</div>
|
47
|
+
|
48
|
+
<h1><a href="http://github.com/quirkey/static_model">static_model</a>
|
49
|
+
<span class="small">by <a href="http://github.com/quirkey">quirkey</a></small></h1>
|
50
|
+
|
51
|
+
<div class="description">
|
52
|
+
ActiveRecord like functionalities for reading from YAML with a simple class implementation
|
53
|
+
</div>
|
54
|
+
|
55
|
+
<h2>Authors</h2>
|
56
|
+
<p>Aaron Quint (aaron@quirkey.com)
|
57
|
+
<h2>Contact</h2>
|
58
|
+
<p>Aaron Quint (aaron@quirkey.com)
|
59
|
+
|
60
|
+
|
61
|
+
<h2>Download</h2>
|
62
|
+
<p>
|
63
|
+
You can download this project in either
|
64
|
+
<a href="http://github.com/quirkey/static_model/zipball/master">zip</a> or
|
65
|
+
<a href="http://github.com/quirkey/static_model/tarball/master">tar</a> formats.
|
66
|
+
</p>
|
67
|
+
<p>You can also clone the project with <a href="http://git-scm.com">Git</a>
|
68
|
+
by running:
|
69
|
+
<pre>$ git clone git://github.com/quirkey/static_model</pre>
|
70
|
+
</p>
|
71
|
+
|
72
|
+
<div class="footer">
|
73
|
+
get the source code on GitHub : <a href="http://github.com/quirkey/static_model">quirkey/static_model</a>
|
74
|
+
</div>
|
75
|
+
|
76
|
+
</div>
|
77
|
+
|
78
|
+
|
79
|
+
</body>
|
80
|
+
</html>
|
data/lib/static_model/base.rb
CHANGED
@@ -63,6 +63,11 @@ module StaticModel
|
|
63
63
|
records[0]
|
64
64
|
end
|
65
65
|
alias_method :first, :find_first
|
66
|
+
|
67
|
+
def find_last
|
68
|
+
records[records.length-1]
|
69
|
+
end
|
70
|
+
alias_method :last, :find_last
|
66
71
|
|
67
72
|
def find_all_by(attribute, value)
|
68
73
|
records.find_all {|r| r.send(attribute) == value }
|
@@ -72,6 +77,11 @@ module StaticModel
|
|
72
77
|
records.find {|r| r.send(attribute) == value }
|
73
78
|
end
|
74
79
|
alias_method :find_by, :find_first_by
|
80
|
+
|
81
|
+
def find_last_by(attribute, value)
|
82
|
+
records.find {|r| r.send(attribute) == value }
|
83
|
+
end
|
84
|
+
alias_method :find_by, :find_last_by
|
75
85
|
|
76
86
|
def load(reload = false)
|
77
87
|
return if loaded? && !reload
|
@@ -153,8 +163,8 @@ module StaticModel
|
|
153
163
|
private
|
154
164
|
def method_missing(meth, *args)
|
155
165
|
meth_name = meth.to_s
|
156
|
-
if meth_name =~ /^find_(all_by|first_by|by)_(.+)/
|
157
|
-
attribute_name = meth_name.gsub(/^find_(all_by|first_by|by)_/, '')
|
166
|
+
if meth_name =~ /^find_(all_by|first_by|last_by|by)_(.+)/
|
167
|
+
attribute_name = meth_name.gsub(/^find_(all_by|first_by|last_by|by)_/, '')
|
158
168
|
finder = meth_name.gsub(/_#{attribute_name}/, '')
|
159
169
|
return self.send(finder, attribute_name, *args)
|
160
170
|
elsif class_attributes.has_key? meth_name
|
data/lib/static_model.rb
CHANGED
@@ -4,11 +4,10 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
4
4
|
require 'yaml' unless defined?(YAML)
|
5
5
|
require 'erb' unless defined?(ERB)
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
require 'active_support/core_ext/integer'
|
7
|
+
require 'active_support'
|
8
|
+
|
9
|
+
module StaticModel
|
10
|
+
VERSION = '0.2.3'
|
12
11
|
end
|
13
12
|
|
14
13
|
require 'static_model/errors'
|
@@ -16,4 +15,5 @@ require 'static_model/associations'
|
|
16
15
|
require 'static_model/active_record'
|
17
16
|
require 'static_model/comparable'
|
18
17
|
require 'static_model/base'
|
19
|
-
require 'static_model/rails'
|
18
|
+
require 'static_model/rails'
|
19
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{static_model}
|
8
|
+
s.version = "0.2.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Aaron Quint"]
|
12
|
+
s.date = %q{2009-12-03}
|
13
|
+
s.description = %q{StaticModel provides a Base class much like ActiveRecord which supports reading from a YAML file and basic associations to ActiveRecord}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"README.rdoc"
|
16
|
+
]
|
17
|
+
s.files = [
|
18
|
+
".gitignore",
|
19
|
+
"History.txt",
|
20
|
+
"License.txt",
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"generators/static_model/USAGE",
|
24
|
+
"generators/static_model/static_model_generator.rb",
|
25
|
+
"generators/static_model/templates/model.rb.erb",
|
26
|
+
"generators/static_model/templates/models.yml.erb",
|
27
|
+
"index.html",
|
28
|
+
"lib/static_model.rb",
|
29
|
+
"lib/static_model/active_record.rb",
|
30
|
+
"lib/static_model/associations.rb",
|
31
|
+
"lib/static_model/base.rb",
|
32
|
+
"lib/static_model/comparable.rb",
|
33
|
+
"lib/static_model/errors.rb",
|
34
|
+
"lib/static_model/rails.rb",
|
35
|
+
"lib/static_model/scope.rb",
|
36
|
+
"lib/static_model/version.rb",
|
37
|
+
"static_model.gemspec",
|
38
|
+
"test/data/authors.yml",
|
39
|
+
"test/data/books.yml",
|
40
|
+
"test/data/empty.yml",
|
41
|
+
"test/data/pages.yml",
|
42
|
+
"test/data/projects.yml",
|
43
|
+
"test/data/publishers.yml",
|
44
|
+
"test/data/stores.yml",
|
45
|
+
"test/test_generator_helper.rb",
|
46
|
+
"test/test_helper.rb",
|
47
|
+
"test/test_static_model.rb",
|
48
|
+
"test/test_static_model_associations.rb",
|
49
|
+
"test/test_static_model_generator.rb",
|
50
|
+
"test/test_static_model_scope.rb"
|
51
|
+
]
|
52
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
53
|
+
s.require_paths = ["lib"]
|
54
|
+
s.rubyforge_project = %q{quirkey}
|
55
|
+
s.rubygems_version = %q{1.3.5}
|
56
|
+
s.summary = %q{ActiveRecord like functionalities for reading from YAML with a simple class implementation}
|
57
|
+
s.test_files = [
|
58
|
+
"test/test_generator_helper.rb",
|
59
|
+
"test/test_helper.rb",
|
60
|
+
"test/test_static_model.rb",
|
61
|
+
"test/test_static_model_associations.rb",
|
62
|
+
"test/test_static_model_generator.rb",
|
63
|
+
"test/test_static_model_scope.rb"
|
64
|
+
]
|
65
|
+
|
66
|
+
if s.respond_to? :specification_version then
|
67
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
68
|
+
s.specification_version = 3
|
69
|
+
|
70
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
71
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.2.0"])
|
72
|
+
s.add_runtime_dependency(%q<rubigen>, [">= 1.5.1"])
|
73
|
+
s.add_development_dependency(%q<Shoulda>, [">= 1.2.0"])
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<activesupport>, [">= 2.2.0"])
|
76
|
+
s.add_dependency(%q<rubigen>, [">= 1.5.1"])
|
77
|
+
s.add_dependency(%q<Shoulda>, [">= 1.2.0"])
|
78
|
+
end
|
79
|
+
else
|
80
|
+
s.add_dependency(%q<activesupport>, [">= 2.2.0"])
|
81
|
+
s.add_dependency(%q<rubigen>, [">= 1.5.1"])
|
82
|
+
s.add_dependency(%q<Shoulda>, [">= 1.2.0"])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
data/test/data/books.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
---
|
2
|
+
- id: 1
|
3
|
+
title: The Omnivore's Dilemma
|
4
|
+
author: Michael Pollan
|
5
|
+
author_id: 1
|
6
|
+
genre: Non-Fiction
|
7
|
+
- id: 2
|
8
|
+
title: In Defense of Food
|
9
|
+
author: Michael Pollan
|
10
|
+
author_id: 1
|
11
|
+
genre: Non-Fiction
|
12
|
+
- id: 3
|
13
|
+
title: Omnivore (Of Man and Manta)
|
14
|
+
author: Piers Anthony
|
15
|
+
author_id: 2
|
16
|
+
genre: Fantasy
|
17
|
+
- id: 4
|
18
|
+
title: Choke
|
19
|
+
author: Chuck Palahniuk
|
20
|
+
author_id: 3
|
21
|
+
genre: Humor
|
22
|
+
|
data/test/data/empty.yml
ADDED
File without changes
|
data/test/data/pages.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
---
|
2
|
+
title: The Best Ever
|
3
|
+
url: http://www.quirkey.com
|
4
|
+
settings:
|
5
|
+
username: test
|
6
|
+
password: test
|
7
|
+
records:
|
8
|
+
- id: 1
|
9
|
+
position: 5
|
10
|
+
title: Getting to know you
|
11
|
+
content: Getting to know all about you
|
12
|
+
- id: 2
|
13
|
+
position: 6
|
14
|
+
title: Its not me, its you
|
15
|
+
content: The oldest excuse in the book
|
16
|
+
url: http://github.com
|