ramaze 2011.07.25 → 2011.10.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. data/.gitignore +3 -0
  2. data/.mailmap +3 -2
  3. data/.travis.yml +17 -0
  4. data/.yardopts +13 -0
  5. data/README.md +95 -352
  6. data/examples/app/blog/app.rb +25 -64
  7. data/examples/app/blog/config.ru +11 -9
  8. data/examples/app/blog/controller/init.rb +29 -86
  9. data/examples/app/blog/controller/posts.rb +232 -0
  10. data/examples/app/blog/controller/users.rb +160 -0
  11. data/examples/app/blog/layout/default.xhtml +61 -0
  12. data/examples/app/blog/migrations/01_create_schema.rb +50 -0
  13. data/examples/app/blog/model/comment.rb +41 -54
  14. data/examples/app/blog/model/init.rb +41 -13
  15. data/examples/app/blog/model/post.rb +35 -0
  16. data/examples/app/blog/model/user.rb +105 -0
  17. data/examples/app/blog/public/.htaccess +24 -0
  18. data/examples/app/blog/public/css/grid.css +107 -0
  19. data/examples/app/blog/public/css/layout.css +203 -0
  20. data/examples/app/blog/public/css/reset.css +123 -0
  21. data/examples/app/blog/public/css/text.css +109 -0
  22. data/examples/app/blog/public/dispatch.fcgi +11 -0
  23. data/examples/app/blog/public/favicon.ico +0 -0
  24. data/examples/app/blog/public/images/bg.png +0 -0
  25. data/examples/app/blog/start.rb +18 -3
  26. data/examples/app/blog/view/feed.xhtml +23 -0
  27. data/examples/app/blog/view/form.xhtml +11 -0
  28. data/examples/app/blog/view/index.xhtml +44 -0
  29. data/examples/app/blog/view/users/form.xhtml +12 -0
  30. data/examples/app/blog/view/users/index.xhtml +30 -0
  31. data/examples/app/blog/view/users/login.xhtml +8 -0
  32. data/examples/app/blog/view/view.xhtml +68 -0
  33. data/{doc → guide}/AUTHORS +5 -3
  34. data/{doc → guide}/CHANGELOG +428 -0
  35. data/{doc/GPL → guide/GPL_LICENSE} +0 -0
  36. data/{doc/COPYING → guide/RUBY_LICENSE} +3 -6
  37. data/guide/_static/logo.png +0 -0
  38. data/guide/_static/logo.svg +49 -0
  39. data/guide/_static/ramaze_console.png +0 -0
  40. data/guide/css/common.css +20 -0
  41. data/guide/general/cache.md +167 -0
  42. data/guide/general/configuration.md +168 -0
  43. data/guide/general/contributing.md +108 -0
  44. data/guide/general/controllers.md +115 -0
  45. data/guide/general/helpers.md +76 -0
  46. data/guide/general/installation.md +58 -0
  47. data/guide/general/logging.md +99 -0
  48. data/guide/general/middlewares.md +100 -0
  49. data/guide/general/models.md +78 -0
  50. data/guide/general/principles.md +53 -0
  51. data/guide/general/ramaze_command.md +155 -0
  52. data/guide/general/routes.md +81 -0
  53. data/guide/general/sessions.md +140 -0
  54. data/guide/general/special_thanks.md +67 -0
  55. data/guide/general/testing.md +61 -0
  56. data/guide/general/views.md +322 -0
  57. data/guide/tutorials/introduction.md +259 -0
  58. data/lib/proto/config.ru +1 -1
  59. data/lib/proto/public/favicon.ico +0 -0
  60. data/lib/proto/view/index.xhtml +7 -7
  61. data/lib/ramaze.rb +4 -4
  62. data/lib/ramaze/app.rb +11 -11
  63. data/lib/ramaze/app_graph.rb +2 -4
  64. data/lib/ramaze/bin/console.rb +3 -3
  65. data/lib/ramaze/bin/create.rb +2 -2
  66. data/lib/ramaze/bin/restart.rb +4 -4
  67. data/lib/ramaze/bin/runner.rb +5 -5
  68. data/lib/ramaze/bin/start.rb +19 -4
  69. data/lib/ramaze/bin/status.rb +3 -3
  70. data/lib/ramaze/bin/stop.rb +3 -3
  71. data/lib/ramaze/cache.rb +1 -0
  72. data/lib/ramaze/cache/lru.rb +8 -4
  73. data/lib/ramaze/cache/memcache.rb +32 -13
  74. data/lib/ramaze/cache/redis.rb +164 -0
  75. data/lib/ramaze/cache/sequel.rb +43 -28
  76. data/lib/ramaze/controller.rb +1 -2
  77. data/lib/ramaze/dependencies.rb +40 -3
  78. data/lib/ramaze/helper/bench.rb +26 -16
  79. data/lib/ramaze/helper/blue_form.rb +46 -73
  80. data/lib/ramaze/helper/cache.rb +10 -6
  81. data/lib/ramaze/helper/csrf.rb +35 -39
  82. data/lib/ramaze/helper/disqus.rb +5 -4
  83. data/lib/ramaze/helper/email.rb +35 -24
  84. data/lib/ramaze/helper/erector.rb +9 -13
  85. data/lib/ramaze/helper/flash.rb +7 -9
  86. data/lib/ramaze/helper/formatting.rb +194 -179
  87. data/lib/ramaze/helper/gravatar.rb +4 -8
  88. data/lib/ramaze/helper/identity.rb +3 -3
  89. data/lib/ramaze/helper/layout.rb +23 -8
  90. data/lib/ramaze/helper/markaby.rb +1 -1
  91. data/lib/ramaze/helper/paginate.rb +46 -39
  92. data/lib/ramaze/helper/request_accessor.rb +3 -1
  93. data/lib/ramaze/helper/simple_captcha.rb +18 -17
  94. data/lib/ramaze/helper/stack.rb +1 -1
  95. data/lib/ramaze/helper/tagz.rb +4 -2
  96. data/lib/ramaze/helper/upload.rb +523 -0
  97. data/lib/ramaze/helper/user.rb +4 -8
  98. data/lib/ramaze/helper/xhtml.rb +11 -15
  99. data/lib/ramaze/log.rb +9 -6
  100. data/lib/ramaze/log/rotatinginformer.rb +62 -27
  101. data/lib/ramaze/log/syslog.rb +20 -15
  102. data/lib/ramaze/log/xosd.rb +2 -1
  103. data/lib/ramaze/reloader.rb +2 -0
  104. data/lib/ramaze/request.rb +11 -10
  105. data/lib/ramaze/setup.rb +23 -6
  106. data/lib/ramaze/snippets/array/put_within.rb +3 -9
  107. data/lib/ramaze/snippets/binding/locals.rb +5 -10
  108. data/lib/ramaze/snippets/fiber.rb +1 -23
  109. data/lib/ramaze/snippets/kernel/pretty_inspect.rb +3 -6
  110. data/lib/ramaze/snippets/numeric/filesize_format.rb +3 -5
  111. data/lib/ramaze/snippets/numeric/time.rb +3 -7
  112. data/lib/ramaze/snippets/object/__dir__.rb +3 -7
  113. data/lib/ramaze/snippets/object/instance_variable_defined.rb +3 -6
  114. data/lib/ramaze/snippets/object/pretty.rb +3 -7
  115. data/lib/ramaze/snippets/object/scope.rb +7 -9
  116. data/lib/ramaze/snippets/proc/locals.rb +12 -12
  117. data/lib/ramaze/snippets/ramaze/acquire.rb +15 -14
  118. data/lib/ramaze/snippets/ramaze/deprecated.rb +1 -1
  119. data/lib/ramaze/snippets/ramaze/fiber.rb +1 -1
  120. data/lib/ramaze/snippets/ramaze/lru_hash.rb +2 -3
  121. data/lib/ramaze/snippets/ramaze/struct.rb +2 -4
  122. data/lib/ramaze/snippets/string/camel_case.rb +8 -10
  123. data/lib/ramaze/snippets/string/color.rb +3 -4
  124. data/lib/ramaze/snippets/string/end_with.rb +3 -6
  125. data/lib/ramaze/snippets/string/esc.rb +3 -8
  126. data/lib/ramaze/snippets/string/ord.rb +3 -8
  127. data/lib/ramaze/snippets/string/snake_case.rb +6 -9
  128. data/lib/ramaze/snippets/string/start_with.rb +3 -8
  129. data/lib/ramaze/snippets/string/unindent.rb +3 -6
  130. data/lib/ramaze/snippets/thread/into.rb +1 -3
  131. data/lib/ramaze/spec.rb +2 -31
  132. data/lib/ramaze/spec/bacon.rb +18 -2
  133. data/lib/ramaze/version.rb +1 -1
  134. data/lib/ramaze/view.rb +1 -1
  135. data/ramaze.gemspec +1 -1
  136. data/spec/helper.rb +2 -1
  137. data/spec/ramaze/bin/start.rb +16 -20
  138. data/spec/ramaze/cache/localmemcache.rb +4 -7
  139. data/spec/ramaze/cache/memcache.rb +3 -1
  140. data/spec/ramaze/cache/redis.rb +62 -0
  141. data/spec/ramaze/helper/blue_form.rb +33 -4
  142. data/spec/ramaze/helper/layout.rb +40 -7
  143. data/spec/ramaze/helper/upload.rb +149 -0
  144. data/spec/ramaze/helper/uploads/text_1.txt +1 -0
  145. data/spec/ramaze/helper/uploads/text_2.txt +1 -0
  146. data/spec/ramaze/log/growl.rb +4 -6
  147. data/spec/ramaze/log/syslog.rb +6 -0
  148. data/spec/ramaze/view/lokar.rb +5 -0
  149. data/spec/ramaze/view/nagoro.rb +5 -0
  150. data/tasks/authors.rake +1 -1
  151. data/tasks/bacon.rake +14 -5
  152. data/tasks/changelog.rake +1 -1
  153. data/tasks/yard.rake +12 -4
  154. metadata +277 -239
  155. data/doc/LEGAL +0 -26
  156. data/examples/app/blog/README +0 -3
  157. data/examples/app/blog/controller/comment.rb +0 -45
  158. data/examples/app/blog/controller/entry.rb +0 -85
  159. data/examples/app/blog/controller/main.rb +0 -20
  160. data/examples/app/blog/controller/tag.rb +0 -9
  161. data/examples/app/blog/layout/default.nag +0 -31
  162. data/examples/app/blog/model/entry.rb +0 -89
  163. data/examples/app/blog/model/tag.rb +0 -36
  164. data/examples/app/blog/public/css/screen.css +0 -273
  165. data/examples/app/blog/spec/blog.rb +0 -87
  166. data/examples/app/blog/view/comment/form.nag +0 -10
  167. data/examples/app/blog/view/comment/show.nag +0 -16
  168. data/examples/app/blog/view/entry/edit.nag +0 -14
  169. data/examples/app/blog/view/entry/feed.atom.nag +0 -8
  170. data/examples/app/blog/view/entry/feed.rss.nag +0 -7
  171. data/examples/app/blog/view/entry/index.nag +0 -7
  172. data/examples/app/blog/view/entry/new.nag +0 -13
  173. data/examples/app/blog/view/entry/show.nag +0 -36
  174. data/examples/app/blog/view/feed.atom.nag +0 -18
  175. data/examples/app/blog/view/feed.rss.nag +0 -25
  176. data/examples/app/blog/view/index.nag +0 -6
  177. data/examples/app/blog/view/tag/index.nag +0 -5
  178. data/lib/proto/public/ramaze.png +0 -0
  179. data/lib/ramaze/rest.rb +0 -36
  180. data/spec/ramaze/rest.rb +0 -28
  181. data/tasks/rcov.rake +0 -22
@@ -0,0 +1,160 @@
1
+ ##
2
+ # The Users controller is used for managing users and allowing existing users to
3
+ # log in.
4
+ #
5
+ # @author Yorick Peterse
6
+ # @since 26-09-2011
7
+ #
8
+ class Users < BaseController
9
+ map '/users'
10
+
11
+ # The user has to be logged in in order to access this controller. The only
12
+ # exception is the login() method.
13
+ before_all do
14
+ if action.method.to_sym != :login and !logged_in?
15
+ flash[:error] = 'You need to be logged in to view that page'
16
+ redirect(Users.r(:login))
17
+ end
18
+ end
19
+
20
+ ##
21
+ # Shows an overview of all the users that have been added to the database.
22
+ #
23
+ # @author Yorick Peterse
24
+ # @since 27-09-2011
25
+ #
26
+ def index
27
+ @users = paginate(User)
28
+ @title = 'Users'
29
+ end
30
+
31
+ ##
32
+ # Allows users to add another user to the database.
33
+ #
34
+ # @author Yorick Peterse
35
+ # @since 27-09-2011
36
+ #
37
+ def new
38
+ @user = flash[:form_data] || User.new
39
+ @title = 'New user'
40
+
41
+ render_view(:form)
42
+ end
43
+
44
+ ##
45
+ # Edits an existing user. If the specified user ID is invalid the user is
46
+ # redirected back to the previous page.
47
+ #
48
+ # @author Yorick Peterse
49
+ # @since 27-09-2011
50
+ # @param [Fixnum] id The ID of the user to edit.
51
+ #
52
+ def edit(id)
53
+ @user = flash[:form_data] || User[id]
54
+
55
+ if @user.nil?
56
+ flash[:error] = 'The specified user is invalid'
57
+ redirect_referrer
58
+ end
59
+
60
+ @title = "Edit #{@user.username}"
61
+
62
+ render_view(:form)
63
+ end
64
+
65
+ ##
66
+ # Saves the changes made by Users#new() and Users#edit(). Just like
67
+ # Posts#save() this method is used for both methods since the actions required
68
+ # for adding/updating the data is pretty much identical.
69
+ #
70
+ # @author Yorick Peterse
71
+ # @since 27-09-2011
72
+ #
73
+ def save
74
+ data = request.subset(:username, :password)
75
+ id = request.params['id']
76
+
77
+ if !id.nil? and !id.empty?
78
+ user = User[id]
79
+
80
+ if user.nil?
81
+ flash[:error] = 'The specified user is invalid'
82
+ redirect_referrer
83
+ end
84
+
85
+ success = 'The user has been updated'
86
+ error = 'The user could not be updated'
87
+ else
88
+ user = User.new
89
+ success = 'The user has been added'
90
+ error = 'The user could not be added'
91
+ end
92
+
93
+ begin
94
+ user.update(data)
95
+
96
+ flash[:success] = success
97
+ redirect(Users.r(:edit, user.id))
98
+ rescue => e
99
+ Ramaze::Log.error(e)
100
+
101
+ flash[:error] = error
102
+ flash[:form_errors] = user.errors
103
+ flash[:form_data] = user
104
+
105
+ redirect_referrer
106
+ end
107
+ end
108
+
109
+ ##
110
+ # Deletes a single user and redirects the user back to the overview.
111
+ #
112
+ # @author Yorick Peterse
113
+ # @since 27-09-2011
114
+ # @param [Fixnum] id The ID of the user to delete.
115
+ #
116
+ def delete(id)
117
+ begin
118
+ User.filter(:id => id).destroy
119
+ flash[:success] = 'The specified user has been removed'
120
+ rescue => e
121
+ Ramaze::Log.error(e)
122
+ flash[:error] = 'The specified user could not be removed'
123
+ end
124
+
125
+ redirect_referrer
126
+ end
127
+
128
+ ##
129
+ # Allows a user to log in. Once logged in the user is able to manage existing
130
+ # users and edit posts.
131
+ #
132
+ # @author Yorick Peterse
133
+ # @since 27-09-2011
134
+ #
135
+ def login
136
+ if request.post?
137
+ if user_login(request.subset('username', 'password'))
138
+ flash[:success] = 'You have been logged in'
139
+ redirect(Posts.r(:index))
140
+ else
141
+ flash[:error] = 'You could not be logged in'
142
+ end
143
+ end
144
+
145
+ @title = 'Login'
146
+ end
147
+
148
+ ##
149
+ # Logs the user out and destroys the session.
150
+ #
151
+ # @author Yorick Peterse
152
+ # @since 27-09-2011
153
+ #
154
+ def logout
155
+ user_logout
156
+ session.clear
157
+ flash[:success] = 'You have been logged out'
158
+ redirect(Users.r(:login))
159
+ end
160
+ end # Users
@@ -0,0 +1,61 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+
6
+ <title>#{@title}</title>
7
+
8
+ #{css('reset')}
9
+ #{css('grid')}
10
+ #{css('layout')}
11
+ #{css('text')}
12
+ </head>
13
+ <body>
14
+ <div class="container">
15
+ <div id="container" class="row">
16
+ <!-- Top part, contains the navigation menu -->
17
+ <div id="top" class="grid_12">
18
+ <header class="grid_6">
19
+ <h1>#{@title}</h1>
20
+ </header>
21
+
22
+ <nav class="grid_6 last">
23
+ <ul class="clearfix">
24
+ <li>#{Posts.a('Posts', :index)}</li>
25
+
26
+ <?r if logged_in? ?>
27
+
28
+ <li>#{Users.a('Users', :index)}</li>
29
+ <li>#{Users.a('Logout', :logout)}</li>
30
+
31
+ <?r else ?>
32
+
33
+ <li>#{Users.a('Login', :login)}</li>
34
+
35
+ <?r end ?>
36
+ </ul>
37
+ </nav>
38
+ </div>
39
+
40
+ <?r [:success, :error].each do |type| ?>
41
+ <?r if flash[type] ?>
42
+ <div class="message grid_12 #{type}">
43
+ <p>#{flash[type]}</p>
44
+ </div>
45
+ <?r end ?>
46
+ <?r end ?>
47
+
48
+ <div id="content" class="grid_12">
49
+ #{@content}
50
+ </div>
51
+ </div>
52
+
53
+ <footer id="footer">
54
+ <p>
55
+ Ramaze is free software and is licensed under the Ruby
56
+ license.
57
+ </p>
58
+ </footer>
59
+ </div>
60
+ </body>
61
+ </html>
@@ -0,0 +1,50 @@
1
+ # For more information on Sequel migrations see the following page:
2
+ # http://sequel.rubyforge.org/rdoc/files/doc/migration_rdoc.html
3
+ Sequel.migration do
4
+ # The up() method and block is used to update a database to the current
5
+ # migration.
6
+ up do
7
+ create_table(:users) do
8
+ primary_key :id
9
+
10
+ String :username, :null => false
11
+ String :password, :null => false
12
+ end
13
+
14
+ create_table(:posts) do
15
+ primary_key :id
16
+
17
+ String :title, :null => false
18
+ String :body , :null => false, :text => true
19
+
20
+ Time :created_at
21
+ Time :updated_at
22
+
23
+ foreign_key :user_id, :users, :on_update => :cascade,
24
+ :on_delete => :cascade, :key => :id
25
+ end
26
+
27
+ create_table(:comments) do
28
+ primary_key :id
29
+
30
+ String :username, :null => true
31
+ String :comment , :null => false, :text => true
32
+
33
+ Time :created_at
34
+
35
+ foreign_key :post_id, :posts, :on_update => :cascade,
36
+ :on_delete => :cascade, :key => :id
37
+
38
+ foreign_key :user_id, :users, :on_update => :cascade,
39
+ :on_delete => :cascade, :key => :id
40
+ end
41
+ end
42
+
43
+ # The down() method and block is used to revert the changes introduced by the
44
+ # up() block.
45
+ down do
46
+ drop_table(:comments)
47
+ drop_table(:posts)
48
+ drop_table(:users)
49
+ end
50
+ end
@@ -1,58 +1,45 @@
1
- module Blog
2
- class Comment < Sequel::Model
3
- set_schema do
4
- primary_key :id
5
-
6
- # on update
7
- varchar :author
8
- varchar :email
9
- varchar :homepage
10
- text :content
11
-
12
- # system
13
- time :published
14
- time :updated
15
- boolean :public, :default => true
16
-
17
- foreign_key :entry_id
18
- end
19
-
20
- many_to_one :entry, :class => 'Blog::Entry'
21
-
22
- create_table unless table_exists?
23
-
24
- before_save{ self.updated = Time.now }
25
- before_create{ self.published = Time.now }
26
-
27
- validations.clear
28
-
29
- validates do
30
- length_of :author, :within => (2..255)
31
- # yay, reddit! we should rather set a minimum like:
32
- # "I, for one, welcome our new x overlords.".size
33
- length_of :content, :minimum => 2
34
-
35
- # a@b.c anyone know a domain like that?
36
- length_of :email, :within => (5..255)
37
- format_of :email, :with => /^([^@\s]{1}+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
38
-
39
- format_of :homepage, :with => /^https?:\/\/[^\s\/]+\.[^\s\/]+/
40
- end
41
-
42
- def href
43
- Entries.r(:/, "#{entry.slug}#comment-#{id}")
1
+ ##
2
+ # The Comment model is used for creating and managing comments.
3
+ #
4
+ # @author Yorick Peterse
5
+ # @since 26-09-2011
6
+ #
7
+ class Comment < Sequel::Model
8
+ plugin :timestamps, :create => :created_at, :update => :updated_at
9
+
10
+ # A comment can belong to only one post and one user
11
+ many_to_one :post
12
+ many_to_one :user
13
+
14
+ ##
15
+ # Validates a comment before saving it to the database.
16
+ #
17
+ # @author Yorick Peterse
18
+ # @since 26-09-2011
19
+ #
20
+ def validate
21
+ validates_presence(:comment)
22
+
23
+ # Comments can either have user ID or a custom name. The user ID is only set
24
+ # when the user is logged in.
25
+ unless self.user_id
26
+ validates_presence(:username)
44
27
  end
28
+ end
45
29
 
46
- def update(entry, hash)
47
- return unless entry
48
-
49
- [:author, :email, :homepage, :content].each do |key|
50
- self[key] = hash[key]
51
- end
52
-
53
- return unless valid?
54
- save
55
- entry.add_comment(self)
30
+ ##
31
+ # Gets the name of the author from either an associated user or the "name"
32
+ # field.
33
+ #
34
+ # @author Yorick Peterse
35
+ # @since 26-09-2011
36
+ # @return [String]
37
+ #
38
+ def username
39
+ if user and user.username
40
+ return user.username
41
+ else
42
+ return super
56
43
  end
57
44
  end
58
- end
45
+ end # Comment
@@ -1,16 +1,44 @@
1
- require 'sequel'
2
- require 'sequel/extensions/inflector'
1
+ # Configure Sequel. This example uses a SQLite3 database with it's encoding set
2
+ # to UTF-8. The :test option is used to confirm that the database connection is
3
+ # valid before it's actually being used. In this case the connection returned by
4
+ # Sequel.connect is stored in a constant called "DB" but you're free to store it
5
+ # wherever you want.
6
+ DB = Sequel.connect(
7
+ :adapter => 'sqlite',
8
+ :database => __DIR__('../database.db'),
9
+ :test => true,
10
+ :encoding => 'utf8'
11
+ )
3
12
 
4
- module Blog
5
- DB = Sequel.sqlite("#{__DIR__}/../blog.db")
6
- # DB = Sequel.connect("sqlite:///#{__DIR__}/../blog.db")
7
- end
13
+ # The validation_helpers plugin is required if you want to use the #validate()
14
+ # method in your model in combination with easy to use methods such as
15
+ # validates_presence().
16
+ Sequel::Model.plugin(:validation_helpers)
17
+
18
+ # The migration extension is needed in order to run migrations.
19
+ Sequel.extension(:migration)
20
+
21
+ # The pagination extension is needed by Ramaze::Helper::Paginate.
22
+ Sequel.extension(:pagination)
23
+
24
+ # Migrate the database
25
+ Sequel::Migrator.run(DB, __DIR__('../migrations'))
8
26
 
9
- Sequel.extension :pagination
10
- Sequel::Model.plugin :validation_class_methods
11
- Sequel::Model.plugin :schema
12
- Sequel::Model.plugin :hook_class_methods
27
+ # Time to load all the models now that Sequel is set up.
28
+ require __DIR__('comment')
29
+ require __DIR__('post')
30
+ require __DIR__('user')
13
31
 
14
- require 'model/tag'
15
- require 'model/entry'
16
- require 'model/comment'
32
+ # Insert the default user if this hasn't already been done so.
33
+ unless User[:username => 'admin']
34
+ User.create(:username => 'admin', :password => 'admin')
35
+ end
36
+
37
+ # Insert a default post if no posts have been added.
38
+ if Post.all.empty?
39
+ Post.create(
40
+ :title => 'Example Post',
41
+ :body => 'This is a post that uses Markdown!',
42
+ :user_id => User[:username => 'admin'].id
43
+ )
44
+ end
@@ -0,0 +1,35 @@
1
+ ##
2
+ # The Post class is a model that's used for managing posts. The corresponding
3
+ # table is called "posts". For more information on how Sequel works see the
4
+ # following page: http://sequel.rubyforge.org/documentation.html
5
+ #
6
+ # @author Yorick Peterse
7
+ # @since 26-09-2011
8
+ #
9
+ class Post < Sequel::Model
10
+ # The timestamps plugin is used to automatically fill two database columns
11
+ # with the dates and times on which an object was created and when it was
12
+ # modified.
13
+ plugin :timestamps, :create => :created_at, :update => :updated_at
14
+
15
+ # Multiple posts can only belong to a single user.
16
+ many_to_one :user
17
+ one_to_many :comments
18
+
19
+ ##
20
+ # Post#validate() is called whenever an instance of this class is saved or
21
+ # updated. For more information on what you can do with this method see the
22
+ # following page:
23
+ # http://sequel.rubyforge.org/rdoc/files/doc/validations_rdoc.html
24
+ #
25
+ # If you're used to working with ActiveRecord it's important to remember that
26
+ # these validation methods can't be used in a model's class declaration, they
27
+ # have to be placed inside the #validate() method.
28
+ #
29
+ # @author Yorick Peterse
30
+ # @since 26-09-2011
31
+ #
32
+ def validate
33
+ validates_presence([:title, :body])
34
+ end
35
+ end # Post