ramaze 2011.01.30 → 2011.07.25

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 (229) hide show
  1. data/.gitignore +2 -1
  2. data/.mailmap +2 -0
  3. data/.rvmrc +1 -0
  4. data/README.md +119 -197
  5. data/Rakefile +14 -97
  6. data/bin/ramaze +6 -14
  7. data/doc/AUTHORS +8 -4
  8. data/doc/CHANGELOG +3784 -3339
  9. data/examples/app/chat/start.rb +2 -2
  10. data/lib/proto/app.rb +2 -3
  11. data/lib/proto/config.ru +4 -5
  12. data/lib/proto/controller/init.rb +11 -4
  13. data/lib/proto/controller/main.rb +12 -7
  14. data/lib/proto/layout/default.xhtml +56 -23
  15. data/lib/proto/model/init.rb +3 -1
  16. data/lib/proto/public/css/grid.css +107 -0
  17. data/lib/proto/public/css/layout.css +81 -0
  18. data/lib/proto/public/css/reset.css +123 -0
  19. data/lib/proto/public/css/text.css +109 -0
  20. data/lib/proto/public/images/bg.png +0 -0
  21. data/lib/proto/spec/main.rb +2 -2
  22. data/lib/proto/start.rb +11 -1
  23. data/lib/proto/view/index.xhtml +27 -23
  24. data/lib/ramaze.rb +0 -1
  25. data/lib/ramaze/app.rb +85 -12
  26. data/lib/ramaze/app_graph.rb +107 -0
  27. data/lib/ramaze/bin/console.rb +87 -0
  28. data/lib/ramaze/bin/create.rb +94 -0
  29. data/lib/ramaze/bin/helper.rb +107 -0
  30. data/lib/ramaze/bin/restart.rb +95 -0
  31. data/lib/ramaze/bin/runner.rb +141 -0
  32. data/lib/ramaze/bin/start.rb +206 -0
  33. data/lib/ramaze/bin/status.rb +152 -0
  34. data/lib/ramaze/bin/stop.rb +112 -0
  35. data/lib/ramaze/cache.rb +9 -4
  36. data/lib/ramaze/cache/localmemcache.rb +10 -13
  37. data/lib/ramaze/cache/lru.rb +49 -7
  38. data/lib/ramaze/cache/memcache.rb +170 -92
  39. data/lib/ramaze/cache/sequel.rb +301 -118
  40. data/lib/ramaze/controller.rb +108 -9
  41. data/lib/ramaze/controller/default.rb +15 -2
  42. data/lib/ramaze/current.rb +14 -2
  43. data/lib/ramaze/dependencies.rb +46 -0
  44. data/lib/ramaze/files.rb +38 -3
  45. data/lib/ramaze/gestalt.rb +12 -12
  46. data/lib/ramaze/helper.rb +0 -2
  47. data/lib/ramaze/helper/auth.rb +30 -23
  48. data/lib/ramaze/helper/blue_form.rb +175 -126
  49. data/lib/ramaze/helper/csrf.rb +76 -91
  50. data/lib/ramaze/helper/email.rb +105 -0
  51. data/lib/ramaze/helper/erector.rb +16 -15
  52. data/lib/ramaze/helper/gestalt.rb +2 -2
  53. data/lib/ramaze/helper/layout.rb +89 -73
  54. data/lib/ramaze/helper/link.rb +7 -6
  55. data/lib/ramaze/helper/localize.rb +6 -5
  56. data/lib/ramaze/helper/markaby.rb +25 -23
  57. data/lib/ramaze/helper/maruku.rb +3 -3
  58. data/lib/ramaze/helper/paginate.rb +19 -27
  59. data/lib/ramaze/helper/remarkably.rb +3 -3
  60. data/lib/ramaze/helper/request_accessor.rb +3 -3
  61. data/lib/ramaze/helper/send_file.rb +12 -8
  62. data/lib/ramaze/helper/simple_captcha.rb +5 -6
  63. data/lib/ramaze/helper/stack.rb +7 -4
  64. data/lib/ramaze/helper/tagz.rb +10 -11
  65. data/lib/ramaze/helper/thread.rb +19 -16
  66. data/lib/ramaze/helper/ultraviolet.rb +7 -4
  67. data/lib/ramaze/helper/user.rb +40 -21
  68. data/lib/ramaze/helper/xhtml.rb +29 -20
  69. data/lib/ramaze/log.rb +3 -11
  70. data/lib/ramaze/log/analogger.rb +5 -4
  71. data/lib/ramaze/log/growl.rb +9 -7
  72. data/lib/ramaze/log/hub.rb +3 -5
  73. data/lib/ramaze/log/informer.rb +15 -12
  74. data/lib/ramaze/log/knotify.rb +3 -5
  75. data/lib/ramaze/log/logger.rb +3 -5
  76. data/lib/ramaze/log/logging.rb +6 -8
  77. data/lib/ramaze/log/rotatinginformer.rb +27 -17
  78. data/lib/ramaze/log/syslog.rb +7 -7
  79. data/lib/ramaze/log/xosd.rb +3 -5
  80. data/lib/ramaze/middleware_compiler.rb +27 -4
  81. data/lib/ramaze/reloader.rb +50 -12
  82. data/lib/ramaze/reloader/watch_inotify.rb +4 -5
  83. data/lib/ramaze/reloader/watch_stat.rb +3 -3
  84. data/lib/ramaze/request.rb +18 -8
  85. data/lib/ramaze/response.rb +38 -7
  86. data/lib/ramaze/rest.rb +36 -0
  87. data/lib/ramaze/setup.rb +101 -31
  88. data/lib/ramaze/spec.rb +1 -1
  89. data/lib/ramaze/spec/bacon.rb +6 -3
  90. data/lib/ramaze/spec/helper/bacon.rb +0 -1
  91. data/lib/ramaze/version.rb +1 -1
  92. data/lib/ramaze/view.rb +2 -11
  93. data/lib/ramaze/view/erector.rb +46 -31
  94. data/lib/ramaze/view/erubis.rb +7 -3
  95. data/lib/ramaze/view/ezamar.rb +7 -3
  96. data/lib/ramaze/view/gestalt.rb +9 -3
  97. data/lib/ramaze/view/haml.rb +7 -3
  98. data/lib/ramaze/view/liquid.rb +3 -3
  99. data/lib/ramaze/view/lokar.rb +7 -3
  100. data/lib/ramaze/view/mustache.rb +11 -5
  101. data/lib/ramaze/view/nagoro.rb +3 -3
  102. data/lib/ramaze/view/sass.rb +1 -1
  103. data/lib/ramaze/view/slippers.rb +40 -13
  104. data/lib/ramaze/view/tagz.rb +9 -5
  105. data/ramaze.gemspec +23 -128
  106. data/spec/helper.rb +5 -0
  107. data/spec/ramaze/bin/app/config.ru +11 -0
  108. data/spec/ramaze/bin/create.rb +28 -0
  109. data/spec/ramaze/bin/runner.rb +30 -0
  110. data/spec/ramaze/bin/start.rb +38 -0
  111. data/spec/ramaze/cache/memcache.rb +10 -3
  112. data/spec/ramaze/cache/sequel.rb +7 -0
  113. data/spec/ramaze/controller/provide_inheritance.rb +0 -10
  114. data/spec/ramaze/dispatcher/file.rb +19 -15
  115. data/spec/ramaze/helper/auth.rb +10 -9
  116. data/spec/ramaze/helper/blue_form.rb +121 -68
  117. data/spec/ramaze/helper/email.rb +69 -0
  118. data/spec/ramaze/helper/layout.rb +12 -15
  119. data/spec/ramaze/helper/layout/alternative.xhtml +5 -0
  120. data/spec/ramaze/helper/user.rb +2 -0
  121. data/spec/ramaze/log/growl.rb +14 -1
  122. data/spec/{contrib → ramaze}/rest.rb +1 -1
  123. data/spec/ramaze/session/memcache.rb +2 -2
  124. data/spec/ramaze/view/sass.rb +1 -1
  125. data/tasks/bacon.rake +3 -3
  126. data/tasks/gem.rake +17 -18
  127. data/tasks/rcov.rake +2 -3
  128. data/tasks/release.rake +8 -65
  129. data/tasks/setup.rake +10 -8
  130. data/tasks/todo.rake +9 -5
  131. data/tasks/yard.rake +3 -2
  132. metadata +105 -397
  133. data/MANIFEST +0 -532
  134. data/TODO.md +0 -19
  135. data/benchmark/bench_templates/bench.rb +0 -67
  136. data/benchmark/bench_templates/view/large.erb +0 -79
  137. data/benchmark/bench_templates/view/large.haml +0 -41
  138. data/benchmark/bench_templates/view/large.lok +0 -79
  139. data/benchmark/bench_templates/view/large.xhtml +0 -79
  140. data/benchmark/bench_templates/view/small.erb +0 -21
  141. data/benchmark/bench_templates/view/small.haml +0 -12
  142. data/benchmark/bench_templates/view/small.lok +0 -21
  143. data/benchmark/bench_templates/view/small.xhtml +0 -21
  144. data/benchmark/results.txt +0 -131
  145. data/benchmark/run.rb +0 -355
  146. data/benchmark/suite/minimal.rb +0 -11
  147. data/benchmark/suite/no_informer.rb +0 -7
  148. data/benchmark/suite/no_sessions.rb +0 -9
  149. data/benchmark/suite/no_template.rb +0 -7
  150. data/benchmark/suite/simple.rb +0 -5
  151. data/benchmark/suite/template_erubis.rb +0 -8
  152. data/benchmark/suite/template_etanni.rb +0 -8
  153. data/benchmark/suite/template_ezamar.rb +0 -8
  154. data/benchmark/suite/template_haml.rb +0 -13
  155. data/benchmark/suite/template_liquid.rb +0 -11
  156. data/benchmark/suite/template_markaby.rb +0 -9
  157. data/benchmark/suite/template_nagoro.rb +0 -8
  158. data/benchmark/suite/template_redcloth.rb +0 -13
  159. data/benchmark/suite/template_tenjin.rb +0 -8
  160. data/benchmark/test.rb +0 -35
  161. data/doc/FAQ +0 -92
  162. data/doc/INSTALL +0 -92
  163. data/doc/TODO +0 -29
  164. data/doc/meta/announcement.txt +0 -119
  165. data/doc/meta/configuration.txt +0 -163
  166. data/doc/meta/internals.txt +0 -278
  167. data/doc/meta/users.kml +0 -64
  168. data/doc/tutorial/todolist.html +0 -1512
  169. data/doc/tutorial/todolist.txt +0 -920
  170. data/examples/app/sourceview/public/coderay.css +0 -104
  171. data/examples/app/sourceview/public/images/file.gif +0 -0
  172. data/examples/app/sourceview/public/images/folder.gif +0 -0
  173. data/examples/app/sourceview/public/images/tv-collapsable-last.gif +0 -0
  174. data/examples/app/sourceview/public/images/tv-collapsable.gif +0 -0
  175. data/examples/app/sourceview/public/images/tv-expandable-last.gif +0 -0
  176. data/examples/app/sourceview/public/images/tv-expandable.gif +0 -0
  177. data/examples/app/sourceview/public/images/tv-item-last.gif +0 -0
  178. data/examples/app/sourceview/public/images/tv-item.gif +0 -0
  179. data/examples/app/sourceview/public/jquery.js +0 -11
  180. data/examples/app/sourceview/public/jquery.treeview.css +0 -48
  181. data/examples/app/sourceview/public/jquery.treeview.js +0 -223
  182. data/examples/app/sourceview/public/sourceview.js +0 -52
  183. data/examples/app/sourceview/start.rb +0 -79
  184. data/examples/app/sourceview/view/index.haml +0 -59
  185. data/examples/helpers/httpdigest.rb +0 -107
  186. data/lib/proto/public/css/screen.css +0 -30
  187. data/lib/proto/public/js/jquery.js +0 -7179
  188. data/lib/ramaze/contrib/addressable_route.rb +0 -56
  189. data/lib/ramaze/contrib/app_graph.rb +0 -64
  190. data/lib/ramaze/contrib/email.rb +0 -88
  191. data/lib/ramaze/contrib/facebook.rb +0 -23
  192. data/lib/ramaze/contrib/facebook/facebook.rb +0 -171
  193. data/lib/ramaze/contrib/gettext.rb +0 -113
  194. data/lib/ramaze/contrib/gettext/mo.rb +0 -155
  195. data/lib/ramaze/contrib/gettext/parser.rb +0 -46
  196. data/lib/ramaze/contrib/gettext/po.rb +0 -109
  197. data/lib/ramaze/contrib/gzip_filter.rb +0 -1
  198. data/lib/ramaze/contrib/maruku_uv.rb +0 -59
  199. data/lib/ramaze/contrib/profiling.rb +0 -36
  200. data/lib/ramaze/contrib/rest.rb +0 -23
  201. data/lib/ramaze/contrib/sequel/create_join.rb +0 -26
  202. data/lib/ramaze/contrib/sequel/form_field.rb +0 -129
  203. data/lib/ramaze/contrib/sequel/image.rb +0 -196
  204. data/lib/ramaze/contrib/sequel/relation.rb +0 -98
  205. data/lib/ramaze/helper/httpdigest.rb +0 -96
  206. data/lib/ramaze/tool/bin.rb +0 -340
  207. data/lib/ramaze/tool/create.rb +0 -48
  208. data/lib/ramaze/tool/project_creator.rb +0 -120
  209. data/lib/ramaze/view/less.rb +0 -12
  210. data/lib/ramaze/view/maruku.rb +0 -15
  211. data/lib/ramaze/view/redcloth.rb +0 -21
  212. data/spec/contrib/addressable_route.rb +0 -30
  213. data/spec/examples/helpers/httpdigest.rb +0 -64
  214. data/spec/examples/templates/template_redcloth.rb +0 -13
  215. data/spec/ramaze/bin/ramaze.rb +0 -96
  216. data/spec/ramaze/helper/httpdigest.rb +0 -176
  217. data/spec/ramaze/view/less.rb +0 -60
  218. data/spec/ramaze/view/less/file.css.less +0 -8
  219. data/spec/ramaze/view/redcloth.rb +0 -66
  220. data/spec/ramaze/view/redcloth/external.redcloth +0 -8
  221. data/tasks/copyright.rake +0 -21
  222. data/tasks/gem_setup.rake +0 -112
  223. data/tasks/git.rake +0 -46
  224. data/tasks/grancher.rake +0 -12
  225. data/tasks/jquery.rake +0 -15
  226. data/tasks/manifest.rake +0 -4
  227. data/tasks/metric_changes.rake +0 -24
  228. data/tasks/reversion.rake +0 -8
  229. data/tasks/traits.rake +0 -21
@@ -1,5 +1,6 @@
1
1
  module Ramaze
2
2
  class Reloader
3
+ ##
3
4
  # TODO:
4
5
  # * There seems to be a problem somewhere that I couldn't identify yet, a
5
6
  # file has to be modified twice initially to make it show up as
@@ -11,7 +12,6 @@ module Ramaze
11
12
  # NOTE:
12
13
  # * I have changed from using a Mutex to using a Queue, which uses a
13
14
  # Mutex internally.
14
-
15
15
  class WatchInotify
16
16
  POLL_INTERVAL = 2 # seconds
17
17
  NOTIFY_MASK = RInotify::MODIFY | RInotify::IN_ONESHOT
@@ -54,7 +54,6 @@ module Ramaze
54
54
  # FIXME:
55
55
  # Seems like this won't work due to some bug in the rinotify library.
56
56
  # Would be cool if someone could make a FFI version.
57
-
58
57
  def remove_watch(file)
59
58
  @watcher.rm_watch(file)
60
59
  end
@@ -80,6 +79,6 @@ module Ramaze
80
79
  yield(file)
81
80
  end
82
81
  end
83
- end
84
- end
85
- end
82
+ end # WatchInotify
83
+ end # Reloader
84
+ end # Ramaze
@@ -53,6 +53,6 @@ module Ramaze
53
53
  rescue Errno::ENOENT, Errno::ENOTDIR
54
54
  nil
55
55
  end
56
- end
57
- end
58
- end
56
+ end # WatchStat
57
+ end # Reloader
58
+ end # Ramaze
@@ -1,11 +1,11 @@
1
1
  # Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
-
4
3
  module Ramaze
4
+ ##
5
5
  # The purpose of this class is to act as a simple wrapper for Rack::Request
6
6
  # and provide some convinient methods for our own use.
7
7
  class Request < Innate::Request
8
-
8
+ ##
9
9
  # you can access the original @request via this method_missing,
10
10
  # first it tries to match your method with any of the HTTP parameters
11
11
  # then, in case that fails, it will relay to @request
@@ -15,6 +15,7 @@ module Ramaze
15
15
  super
16
16
  end
17
17
 
18
+ ##
18
19
  # Sets any arguments passed as @instance_variables for the current action.
19
20
  #
20
21
  # Usage:
@@ -23,7 +24,7 @@ module Ramaze
23
24
  # @q # => 'google'
24
25
  # @name # => 'manveru'
25
26
  # @lang # => nil
26
-
27
+ #
27
28
  def to_instance_variables(*args)
28
29
  instance = Current.action.instance
29
30
  args.each do |arg|
@@ -39,6 +40,7 @@ module Ramaze
39
40
  charset == '*' ? default : charset
40
41
  end
41
42
 
43
+ ##
42
44
  # Try to find out which languages the client would like to have and sort
43
45
  # them by weight, (most wanted first).
44
46
  #
@@ -54,6 +56,7 @@ module Ramaze
54
56
  # @return [Array] list of locales
55
57
  # @see Request#accept_language_with_weight
56
58
  # @author manveru
59
+ #
57
60
  def accept_language(string = env['HTTP_ACCEPT_LANGUAGE'])
58
61
  return [] unless string
59
62
 
@@ -61,6 +64,7 @@ module Ramaze
61
64
  end
62
65
  alias locales accept_language
63
66
 
67
+ ##
64
68
  # Transform the HTTP_ACCEPT_LANGUAGE header into an Array with:
65
69
  #
66
70
  # [[lang, weight], [lang, weight], ...]
@@ -76,6 +80,7 @@ module Ramaze
76
80
  # @return [Array] array of [lang, weight] arrays
77
81
  # @see Request#accept_language
78
82
  # @author manveru
83
+ #
79
84
  def accept_language_with_weight(string = env['HTTP_ACCEPT_LANGUAGE'])
80
85
  string.to_s.gsub(/\s+/, '').split(',').
81
86
  map{|chunk| chunk.split(';q=', 2) }.
@@ -102,14 +107,19 @@ module Ramaze
102
107
  # Pretty prints current action with parameters, cookies and enviroment
103
108
  # variables.
104
109
  def pretty_print(pp)
105
- pp.object_group(self){
106
- group = { 'params' => params, 'cookies' => cookies, 'env' => http_variables }
110
+ pp.object_group(self) do
111
+ group = {
112
+ 'params' => params,
113
+ 'cookies' => cookies,
114
+ 'env' => http_variables
115
+ }
116
+
107
117
  group.each do |name, hash|
108
118
  pp.breakable
109
119
  pp.text " @#{name}="
110
120
  pp.nest(name.size + 3){ pp.pp_hash(hash) }
111
121
  end
112
- }
122
+ end
113
123
  end
114
- end
115
- end
124
+ end # Request
125
+ end # Ramaze
@@ -1,36 +1,67 @@
1
1
  # Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
-
4
3
  module Ramaze
4
+ ##
5
+ # Ramaze::Response is a small wrapper around Rack::Response that makes it
6
+ # easier to send response data to the browser from a Ramaze application.
7
+ #
8
+ # @author Michael Fellinger
9
+ # @since 01-03-2008
10
+ #
5
11
  class Response < Rack::Response
6
12
  # Alias for Current.response
7
13
  def self.current; Current.response; end
8
14
 
15
+ ##
16
+ # Creates a new instance of the response class and processes the specified
17
+ # parameters. Once this has been done it calls Rack::Response#initialize.
18
+ #
19
+ # @author Michael Fellinger
20
+ # @since 01-03-2008
21
+ # @param [Array] body An array containing the data for the response body.
22
+ # @param [Fixnum] status The HTPP status code for the response.
23
+ # @param [Hash] header A hash containing additional headers and their
24
+ # values.
25
+ # @param [Proc] &block
26
+ #
9
27
  def initialize(body = [], status = 200, header = {}, &block)
10
28
  modified_header = Ramaze.options.header.merge(header)
11
29
  header.merge!(modified_header)
12
30
  super
13
31
  end
14
32
 
15
- # Build/replace this responses data
33
+ ##
34
+ # Updates the body, status and headers.
35
+ #
36
+ # @author Michael Fellinger
37
+ # @since 01-03-2008
38
+ # @see Ramaze::Response#initialize
39
+ #
16
40
  def build(new_body = nil, new_status = nil, new_header = nil)
17
41
  self.header.merge!(new_header) if new_header
18
42
 
19
- self.body = new_body if new_body
43
+ self.body = new_body if new_body
20
44
  self.status = new_status if new_status
21
45
  end
22
46
 
47
+ ##
48
+ # Sets the body of the response to the given object.
49
+ #
50
+ # @author Michael Fellinger
51
+ # @since 01-03-2008
52
+ # @param [Object] obj The object to use as the response body.
53
+ #
23
54
  def body=(obj)
24
55
  if obj.respond_to?(:stat)
25
56
  @length = obj.stat.size
26
- @body = obj
57
+ @body = obj
27
58
  elsif obj.respond_to?(:size)
28
- @body = []
59
+ @body = []
29
60
  @length = 0
30
61
  write(obj)
31
62
  else
32
63
  raise(ArgumentError, "Invalid body: %p" % obj)
33
64
  end
34
65
  end
35
- end
36
- end
66
+ end # Response
67
+ end # Ramaze
@@ -0,0 +1,36 @@
1
+ ##
2
+ # The code in this file adds an extra option and a route to Ramaze that allows
3
+ # REST like HTTP requests. For example, when this file is loaded a GET request
4
+ # to a controller will be mapped to the "show" method while a POST request will
5
+ # be mapped to "create". In order to use this extension you have to load it
6
+ # manually:
7
+ #
8
+ # require 'ramaze/rest'
9
+ #
10
+ # From this point on you can customize the route as following:
11
+ #
12
+ # Ramaze.options.rest_rewrite['GET'] = 'another_method'
13
+ #
14
+ module Ramaze
15
+ # Don't use one option per method, we don't want to turn request_method into a
16
+ # symbol, together with MethodOverride this could lead to a memory leak.
17
+ options.o(
18
+ 'REST rewrite mapping',
19
+ :rest_rewrite,
20
+ {
21
+ 'GET' => 'show',
22
+ 'POST' => 'create',
23
+ 'PUT' => 'update',
24
+ 'DELETE' => 'destroy'
25
+ }
26
+ )
27
+
28
+ # Re-write the URLs according to the settings set above
29
+ Rewrite['REST dispatch'] = lambda do |path, request|
30
+ if suffix = Ramaze.options[:rest_rewrite][request.request_method]
31
+ "#{path}/#{suffix}".squeeze('/')
32
+ else
33
+ path
34
+ end
35
+ end
36
+ end # Ramaze
data/lib/ramaze/setup.rb CHANGED
@@ -1,35 +1,47 @@
1
1
  module Ramaze
2
+ ##
2
3
  # Convenient setup and activation of gems from different sources and specific
3
- # versions.
4
- # It's almost like Kernel#gem but also installs automatically if a gem is
5
- # missing.
4
+ # versions. It's almost like Kernel#gem but also installs automatically if a
5
+ # gem is missing.
6
6
  #
7
7
  # @example
8
+ # Ramaze.setup :verbose => true do
9
+ # # gem and specific version
10
+ # gem 'makura', '>=2009.01'
8
11
  #
9
- # Ramaze.setup :verbose => true do
10
- # # gem and specific version
11
- # gem 'makura', '>=2009.01'
12
+ # # gem and name for require
13
+ # gem 'aws-s3', :lib => 'aws/s3'
12
14
  #
13
- # # gem and name for require
14
- # gem 'aws-s3', :lib => 'aws/s3'
15
+ # # gem with specific version from rubyforge (default)
16
+ # gem 'json', :version => '=1.1.3', :source => rubyforge
17
+ # end
15
18
  #
16
- # # gem with specific version from rubyforge (default)
17
- # gem 'json', :version => '=1.1.3', :source => rubyforge
18
- #
19
- # # gem from github
20
- # gem 'manveru-org', :lib => 'org', :source => github
21
- # end
22
- #
23
- # @option options [boolean] (true) verbose
24
- # @option options [String] (nil) extconf
25
- # @yield block
26
- # @see GemSetup#initialize
27
19
  # @author manveru
20
+ # @since 19-05-2009
21
+ # @see GemSetup#initialize
22
+ #
28
23
  def self.setup(options = {:verbose => true}, &block)
29
24
  GemSetup.new(options, &block)
30
25
  end
31
26
 
27
+ ##
28
+ # Class responsible for installing and loading all the gems.
29
+ #
30
+ # @author Michael Fellinger (manveru)
31
+ # @since 19-05-2009
32
+ #
32
33
  class GemSetup
34
+ ##
35
+ # Creates a new instance of the class and saves the parameters that were set.
36
+ #
37
+ # @author Michael Fellinger (manveru)
38
+ # @since 19-05-2009
39
+ # @param [Hash] options Hash containing various options to pass to the
40
+ # GemSetup class.
41
+ # @option options :verbose When set to true Ramaze will log
42
+ # various actions such as messages about the installation process.
43
+ # @yield block
44
+ #
33
45
  def initialize(options = {}, &block)
34
46
  @gems = []
35
47
  @options = options.dup
@@ -38,12 +50,33 @@ module Ramaze
38
50
  run(&block)
39
51
  end
40
52
 
53
+ ##
54
+ # Executes the data inside the block, loading all the gems and optionally
55
+ # installing them.
56
+ #
57
+ # @author Michael Fellinger (manveru)
58
+ # @since 19-05-2009
59
+ # @param [Proc] block A block containing all the calls to gem().
60
+ #
41
61
  def run(&block)
42
62
  return unless block_given?
43
63
  instance_eval(&block)
44
64
  setup
45
65
  end
46
66
 
67
+ ##
68
+ # Adds the given gem to the list of required gems.
69
+ #
70
+ # @example
71
+ # gem('json', '>=1.5.1')
72
+ #
73
+ # @author Michael Fellinger (manveru)
74
+ # @since 19-05-2009
75
+ # @param [String] name The name of the gem to load.
76
+ # @param [String] version The version of the gem.
77
+ # @param [Hash] options Additional options to use when loading the gem.
78
+ # @option options :lib The name to load the gem as.
79
+ #
47
80
  def gem(name, version = nil, options = {})
48
81
  if version.respond_to?(:merge!)
49
82
  options = version
@@ -54,7 +87,12 @@ module Ramaze
54
87
  @gems << [name, options]
55
88
  end
56
89
 
57
- # all gems defined, let's try to load/install them
90
+ ##
91
+ # Tries to install all the gems.
92
+ #
93
+ # @author Michael Fellinger (manveru)
94
+ # @since 19-05-2009
95
+ #
58
96
  def setup
59
97
  require 'rubygems'
60
98
  require 'rubygems/dependency_installer'
@@ -64,35 +102,55 @@ module Ramaze
64
102
  end
65
103
  end
66
104
 
67
- # first try to activate, install and try to activate again if activation
68
- # fails the first time
105
+ ##
106
+ # First try to activate, install and try to activate again if activation
107
+ # fails the first time.
108
+ #
109
+ # @author Michael Fellinger (manveru)
110
+ # @since 19-05-2009
111
+ # @param [String] name The name of the gem to activate.
112
+ # @param [Hash] options The options from GemSetup#initialize.
113
+ #
69
114
  def setup_gem(name, options)
70
- version = [options[:version]].compact
115
+ version = [options[:version]].compact
71
116
  lib_name = options[:lib] || name
72
117
 
73
- log "activating #{name}"
118
+ log "Activating gem #{name}"
74
119
 
75
120
  Gem.activate(name, *version)
76
121
  require(lib_name)
77
122
 
123
+ # Gem not installed yet
78
124
  rescue LoadError
79
-
80
125
  install_gem(name, options)
81
126
  Gem.activate(name, *version)
82
127
  require(lib_name)
83
128
  end
84
129
 
85
- # tell rubygems to install a gem
130
+ ##
131
+ # Tell Rubygems to install a gem.
132
+ #
133
+ # @author Michael Fellinger (manveru)
134
+ # @since 19-05-2009
135
+ # @param [String] name The name of the gem to activate.
136
+ # @param [Hash] options The options to use for installing the gem.
137
+ #
86
138
  def install_gem(name, options)
87
139
  installer = Gem::DependencyInstaller.new(options)
88
140
 
89
141
  temp_argv(options[:extconf]) do
90
- log "Installing #{name}"
142
+ log "Installing gem #{name}"
91
143
  installer.install(name, options[:version])
92
144
  end
93
145
  end
94
146
 
95
- # prepare ARGV for rubygems installer
147
+ ##
148
+ # Prepare ARGV for rubygems installer
149
+ #
150
+ # @author Michael Fellinger (manveru)
151
+ # @since 19-05-2009
152
+ # @param [String] extconf
153
+ #
96
154
  def temp_argv(extconf)
97
155
  if extconf ||= @options[:extconf]
98
156
  old_argv = ARGV.clone
@@ -107,6 +165,13 @@ module Ramaze
107
165
 
108
166
  private
109
167
 
168
+ ##
169
+ # Writes the message to the logger.
170
+ #
171
+ # @author Michael Fellinger (manveru)
172
+ # @since 19-05-2009
173
+ # @param [String] msg The message to write to the logger.
174
+ #
110
175
  def log(msg)
111
176
  return unless @verbose
112
177
 
@@ -117,7 +182,12 @@ module Ramaze
117
182
  end
118
183
  end
119
184
 
185
+ ##
186
+ # Installs a gem from Rubyforge.
187
+ #
188
+ # @author Michael Fellinger (manveru)
189
+ # @since 19-05-2009
190
+ #
120
191
  def rubyforge; 'http://gems.rubyforge.org/' end
121
- def github; 'http://gems.github.com/' end
122
- end
123
- end
192
+ end # GemSetup
193
+ end # Ramaze
data/lib/ramaze/spec.rb CHANGED
@@ -2,7 +2,7 @@ require File.expand_path('../', __FILE__) unless defined?(Ramaze)
2
2
 
3
3
  def spec_requires(*libs)
4
4
  spec_precondition 'require' do
5
- libs.each{|lib| require(lib) }
5
+ libs.each { |lib| require(lib) }
6
6
  end
7
7
  end
8
8
  alias spec_require spec_requires