text_record 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/text_record/base.rb +8 -5
- data/spec/base_spec.rb +8 -8
- data/spec/blog_post_spec.rb +8 -8
- data/spec/collection_spec.rb +3 -3
- data/text_record.gemspec +2 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/text_record/base.rb
CHANGED
@@ -44,19 +44,22 @@ module TextRecord
|
|
44
44
|
def where(options)
|
45
45
|
all.where(options)
|
46
46
|
end
|
47
|
-
|
48
|
-
|
47
|
+
|
48
|
+
def find(slug)
|
49
|
+
new(slug)
|
50
|
+
end
|
51
|
+
end
|
49
52
|
|
50
|
-
# Instance Methods
|
53
|
+
# Instance Methods
|
51
54
|
def initialize(path)
|
52
55
|
@slug = path
|
53
|
-
|
56
|
+
|
54
57
|
raise SlugNotFoundError.new("#{directory} could not be found.") unless File.directory?(directory)
|
55
58
|
|
56
59
|
self.class.attributes.each do |attribute| # class attributes, attr_readers to be added to object
|
57
60
|
attribute.parse(self)
|
58
61
|
end
|
59
|
-
end
|
62
|
+
end
|
60
63
|
|
61
64
|
def ==(other_model)
|
62
65
|
!other_model.nil? && (other_model.class == self.class) && self.slug.eql?(other_model.slug)
|
data/spec/base_spec.rb
CHANGED
@@ -54,15 +54,15 @@ describe TextRecord::Base do
|
|
54
54
|
|
55
55
|
describe "equality" do
|
56
56
|
it "should say two instances are the same if their slugs are the same using ==" do
|
57
|
-
story1 = Story.
|
58
|
-
story2 = Story.
|
57
|
+
story1 = Story.find('Story1')
|
58
|
+
story2 = Story.find('Story1')
|
59
59
|
|
60
60
|
(story1 == story2).should be_true
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should say two instances are the same if their slugs are the same using eql?" do
|
64
|
-
story1 = Story.
|
65
|
-
story2 = Story.
|
64
|
+
story1 = Story.find('Story1')
|
65
|
+
story2 = Story.find('Story1')
|
66
66
|
|
67
67
|
story2.eql?(story1).should be_true
|
68
68
|
end
|
@@ -71,9 +71,9 @@ describe TextRecord::Base do
|
|
71
71
|
describe "#all" do
|
72
72
|
it "should return all the stories" do
|
73
73
|
stories = Story.all
|
74
|
-
story1 = Story.
|
75
|
-
story2 = Story.
|
76
|
-
story3 = Story.
|
74
|
+
story1 = Story.find('Story1')
|
75
|
+
story2 = Story.find('Story2')
|
76
|
+
story3 = Story.find('Story3')
|
77
77
|
|
78
78
|
stories.include?(story1).should be_true
|
79
79
|
stories.include?(story2).should be_true
|
@@ -83,5 +83,5 @@ describe TextRecord::Base do
|
|
83
83
|
it "should return a TextRecord::Collection" do
|
84
84
|
Story.all.should be_a(TextRecord::Collection)
|
85
85
|
end
|
86
|
-
end
|
86
|
+
end
|
87
87
|
end
|
data/spec/blog_post_spec.rb
CHANGED
@@ -13,18 +13,18 @@ describe BlogPost do
|
|
13
13
|
describe "#initialize" do
|
14
14
|
it "should raise an error given an incorrect slug" do
|
15
15
|
# tests for TextRecord::SlugNotFound that has the slug in the error description somewhere
|
16
|
-
lambda { BlogPost.
|
16
|
+
lambda { BlogPost.find("fakeslug") }.should raise_error(TextRecord::SlugNotFoundError, /fakeslug/)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should set the slug" do
|
20
|
-
BlogPost.
|
20
|
+
BlogPost.find("TextRecord").slug.should eql("TextRecord")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "A Blog Post" do
|
26
26
|
before(:each) do
|
27
|
-
@blog_post = BlogPost.
|
27
|
+
@blog_post = BlogPost.find('TextRecord')
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "attributes from yaml" do
|
@@ -78,20 +78,20 @@ describe "A Blog Post" do
|
|
78
78
|
|
79
79
|
describe "#directory" do
|
80
80
|
it "should return the content path plus the slug" do
|
81
|
-
BlogPost.
|
81
|
+
BlogPost.find('TextRecord').directory.should eql(File.join(TextRecord.configuration.content_path, "blog_posts","TextRecord"))
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
85
|
describe "#eql?" do
|
86
86
|
it "should return true if the slugs are the same" do
|
87
|
-
blog_post1 = BlogPost.
|
88
|
-
blog_post2 = BlogPost.
|
87
|
+
blog_post1 = BlogPost.find('TextRecord')
|
88
|
+
blog_post2 = BlogPost.find('TextRecord')
|
89
89
|
blog_post1.eql?(blog_post2).should be_true
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should return false if the slugs are different" do
|
93
|
-
blog_post1 = BlogPost.
|
94
|
-
blog_post2 = BlogPost.
|
93
|
+
blog_post1 = BlogPost.find('TextRecord')
|
94
|
+
blog_post2 = BlogPost.find('ActiveRecord')
|
95
95
|
blog_post1.eql?(blog_post2).should be_false
|
96
96
|
end
|
97
97
|
end
|
data/spec/collection_spec.rb
CHANGED
@@ -2,9 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe TextRecord::Collection do
|
4
4
|
before(:each) do
|
5
|
-
@story1 = Story.
|
6
|
-
@story2 = Story.
|
7
|
-
@story3 = Story.
|
5
|
+
@story1 = Story.find('Story1')
|
6
|
+
@story2 = Story.find('Story2')
|
7
|
+
@story3 = Story.find('Story3')
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "#where" do
|
data/text_record.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{text_record}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Adam Hawkins"]
|
12
|
-
s.date = %q{2010-02-
|
12
|
+
s.date = %q{2010-02-12}
|
13
13
|
s.description = %q{Write your models in text files through YAML/Makdown/TextFile whatever you please. Take the forms out of your code and harness the power of your favorite editor.}
|
14
14
|
s.email = %q{Adman1965@gmaiil.com}
|
15
15
|
s.files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: text_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Hawkins
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-12 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|