ramaze 0.1.0 → 0.1.1
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.
- data/Rakefile +4 -12
- data/bin/ramaze +95 -171
- data/doc/CHANGELOG +387 -4
- data/doc/README +81 -13
- data/doc/meta/announcement.txt +51 -8
- data/doc/meta/configuration.txt +17 -34
- data/doc/meta/internals.txt +34 -4
- data/doc/migrate/1110_to_1111.txt +131 -0
- data/doc/readme_chunks/features.txt +81 -12
- data/doc/readme_chunks/installing.txt +0 -1
- data/doc/tutorial/todolist.html +293 -65
- data/doc/tutorial/{todolist.txt → todolist.mkd} +251 -51
- data/examples/blog/main.rb +1 -1
- data/examples/blog/src/model.rb +0 -1
- data/examples/hello.rb +2 -5
- data/examples/templates/template/external.haml +5 -5
- data/examples/templates/template/external.liquid +1 -1
- data/examples/templates/template/external.mab +8 -8
- data/examples/templates/template/external.rem +30 -0
- data/examples/templates/template/external.rhtml +6 -7
- data/examples/templates/template/external.zmr +13 -9
- data/examples/templates/template_amrita2.rb +8 -8
- data/examples/templates/template_erubis.rb +11 -11
- data/examples/templates/template_ezamar.rb +9 -11
- data/examples/templates/template_haml.rb +13 -13
- data/examples/templates/template_liquid.rb +10 -10
- data/examples/templates/template_markaby.rb +13 -10
- data/examples/templates/template_remarkably.rb +59 -0
- data/examples/todolist/main.rb +1 -7
- data/examples/todolist/src/controller/main.rb +26 -13
- data/examples/todolist/src/element/page.rb +5 -0
- data/examples/whywiki/main.rb +1 -1
- data/lib/proto/main.rb +0 -8
- data/lib/proto/public/css/ramaze_error.css +12 -4
- data/lib/proto/public/error.zmr +6 -25
- data/lib/ramaze.rb +35 -245
- data/lib/ramaze/action.rb +21 -0
- data/lib/ramaze/adapter.rb +94 -29
- data/lib/ramaze/adapter/base.rb +57 -0
- data/lib/ramaze/adapter/mongrel.rb +12 -19
- data/lib/ramaze/adapter/webrick.rb +21 -20
- data/lib/ramaze/cache.rb +47 -3
- data/lib/ramaze/cache/memcached.rb +22 -0
- data/lib/ramaze/cache/yaml_store.rb +19 -0
- data/lib/ramaze/controller.rb +47 -271
- data/lib/ramaze/controller/error.rb +43 -0
- data/lib/ramaze/controller/render.rb +90 -0
- data/lib/ramaze/controller/resolve.rb +147 -0
- data/lib/ramaze/dispatcher.rb +41 -9
- data/lib/ramaze/dispatcher/file.rb +1 -1
- data/lib/ramaze/global.rb +73 -158
- data/lib/ramaze/global/dsl.rb +29 -0
- data/lib/ramaze/global/globalstruct.rb +90 -0
- data/lib/ramaze/helper.rb +1 -1
- data/lib/ramaze/helper/aspect.rb +39 -179
- data/lib/ramaze/helper/cache.rb +8 -9
- data/lib/ramaze/helper/cgi.rb +23 -0
- data/lib/ramaze/helper/file.rb +3 -0
- data/lib/ramaze/helper/inform.rb +3 -0
- data/lib/ramaze/helper/link.rb +56 -63
- data/lib/ramaze/helper/nitroform.rb +4 -0
- data/lib/ramaze/helper/redirect.rb +1 -1
- data/lib/ramaze/inform.rb +6 -2
- data/lib/ramaze/inform/analogger.rb +5 -1
- data/lib/ramaze/inform/hub.rb +1 -1
- data/lib/ramaze/inform/informing.rb +7 -0
- data/lib/ramaze/snippets/kernel/aquire.rb +2 -0
- data/lib/ramaze/snippets/kernel/constant.rb +2 -0
- data/lib/ramaze/snippets/kernel/pretty_inspect.rb +2 -0
- data/lib/ramaze/snippets/object/traits.rb +4 -0
- data/lib/ramaze/snippets/openstruct/temp.rb +3 -0
- data/lib/ramaze/snippets/string/DIVIDE.rb +2 -0
- data/lib/ramaze/snippets/string/camel_case.rb +2 -0
- data/lib/ramaze/snippets/string/color.rb +2 -0
- data/lib/ramaze/snippets/string/each.rb +2 -0
- data/lib/ramaze/snippets/string/snake_case.rb +3 -0
- data/lib/ramaze/snippets/struct/fill.rb +8 -2
- data/lib/ramaze/snippets/struct/values_at.rb +16 -0
- data/lib/ramaze/snippets/symbol/to_proc.rb +3 -0
- data/lib/ramaze/sourcereload.rb +89 -0
- data/lib/ramaze/template.rb +21 -12
- data/lib/ramaze/template/amrita2.rb +6 -6
- data/lib/ramaze/template/erubis.rb +4 -9
- data/lib/ramaze/template/ezamar.rb +13 -57
- data/lib/ramaze/template/ezamar/element.rb +10 -12
- data/lib/ramaze/template/ezamar/engine.rb +40 -101
- data/lib/ramaze/template/ezamar/morpher.rb +3 -3
- data/lib/ramaze/template/haml.rb +3 -6
- data/lib/ramaze/template/liquid.rb +4 -9
- data/lib/ramaze/template/markaby.rb +16 -22
- data/lib/ramaze/template/remarkably.rb +28 -0
- data/lib/ramaze/tool/mime.rb +2 -0
- data/lib/ramaze/tool/record.rb +6 -0
- data/lib/ramaze/trinity/request.rb +44 -54
- data/lib/ramaze/trinity/response.rb +1 -1
- data/lib/ramaze/trinity/session.rb +15 -37
- data/lib/ramaze/version.rb +1 -1
- data/rake_tasks/gem.rake +2 -2
- data/rake_tasks/maintaince.rake +42 -1
- data/rake_tasks/spec.rake +45 -0
- data/spec/examples/caching.rb +1 -1
- data/spec/examples/simple.rb +1 -1
- data/spec/examples/templates/template_amrita2.rb +1 -0
- data/spec/examples/templates/template_erubis.rb +2 -1
- data/spec/examples/templates/template_ezamar.rb +1 -1
- data/spec/examples/templates/template_haml.rb +2 -1
- data/spec/examples/templates/template_liquid.rb +2 -1
- data/spec/examples/templates/template_markaby.rb +2 -1
- data/spec/examples/templates/template_remarkably.rb +22 -0
- data/spec/examples/todolist.rb +125 -0
- data/spec/helper.rb +2 -23
- data/spec/helper/minimal.rb +20 -0
- data/spec/helper/mock_http.rb +24 -30
- data/spec/helper/simple_http.rb +2 -2
- data/spec/helper/wrap.rb +6 -9
- data/spec/ramaze/adapter.rb +1 -1
- data/spec/ramaze/adapter/record.rb +31 -0
- data/spec/ramaze/cache.rb +41 -54
- data/spec/ramaze/controller.rb +121 -137
- data/spec/ramaze/controller/template/list.xhtml +1 -0
- data/spec/ramaze/controller/template/other/greet/other.xhtml +1 -0
- data/spec/ramaze/controller/template_resolving.rb +27 -3
- data/spec/ramaze/element.rb +11 -7
- data/spec/ramaze/error.rb +1 -1
- data/spec/ramaze/gestalt.rb +2 -0
- data/spec/ramaze/helper/aspect.rb +30 -21
- data/spec/ramaze/helper/auth.rb +1 -1
- data/spec/ramaze/helper/cache.rb +2 -1
- data/spec/ramaze/helper/form.rb +14 -11
- data/spec/ramaze/helper/link.rb +18 -41
- data/spec/ramaze/localize.rb +29 -2
- data/spec/ramaze/morpher.rb +23 -12
- data/spec/ramaze/params.rb +46 -24
- data/spec/ramaze/request.rb +6 -2
- data/spec/ramaze/store/yaml.rb +5 -0
- data/spec/ramaze/template.rb +22 -27
- data/spec/ramaze/template/amrita2.rb +1 -2
- data/spec/ramaze/template/erubis.rb +1 -1
- data/spec/ramaze/template/ezamar.rb +1 -2
- data/spec/ramaze/template/haml.rb +2 -2
- data/spec/ramaze/template/haml/with_vars.haml +1 -1
- data/spec/ramaze/template/liquid.rb +1 -1
- data/spec/ramaze/template/markaby.rb +1 -1
- data/spec/ramaze/template/remarkably.rb +56 -0
- data/spec/ramaze/template/remarkably/external.rem +8 -0
- data/spec/ramaze/template/remarkably/sum.rem +1 -0
- metadata +38 -63
- data/doc/README.html +0 -637
- data/doc/allison/LICENSE +0 -184
- data/doc/allison/README +0 -37
- data/doc/allison/allison.css +0 -299
- data/doc/allison/allison.gif +0 -0
- data/doc/allison/allison.js +0 -307
- data/doc/allison/allison.rb +0 -287
- data/doc/allison/cache/BODY +0 -588
- data/doc/allison/cache/CLASS_INDEX +0 -4
- data/doc/allison/cache/CLASS_PAGE +0 -1
- data/doc/allison/cache/FILE_INDEX +0 -4
- data/doc/allison/cache/FILE_PAGE +0 -1
- data/doc/allison/cache/FONTS +0 -1
- data/doc/allison/cache/FR_INDEX_BODY +0 -1
- data/doc/allison/cache/IMGPATH +0 -1
- data/doc/allison/cache/INDEX +0 -1
- data/doc/allison/cache/JAVASCRIPT +0 -307
- data/doc/allison/cache/METHOD_INDEX +0 -4
- data/doc/allison/cache/METHOD_LIST +0 -1
- data/doc/allison/cache/SRC_PAGE +0 -1
- data/doc/allison/cache/STYLE +0 -321
- data/doc/allison/cache/URL +0 -1
- data/doc/changes.txt +0 -3375
- data/doc/changes.xml +0 -3378
- data/examples/todolist/conf/benchmark.yaml +0 -35
- data/examples/todolist/conf/debug.yaml +0 -34
- data/examples/todolist/conf/live.yaml +0 -33
- data/examples/todolist/conf/silent.yaml +0 -31
- data/examples/todolist/conf/stage.yaml +0 -33
- data/examples/todolist/public/css/coderay.css +0 -105
- data/examples/todolist/public/css/ramaze_error.css +0 -42
- data/lib/proto/conf/benchmark.yaml +0 -21
- data/lib/proto/conf/debug.yaml +0 -21
- data/lib/proto/conf/live.yaml +0 -21
- data/lib/proto/conf/silent.yaml +0 -21
- data/lib/proto/conf/stage.yaml +0 -21
- data/lib/proto/public/css/coderay.css +0 -105
- data/lib/ramaze/http_status.rb +0 -66
- data/lib/ramaze/snippets/hash/keys_to_sym.rb +0 -19
- data/lib/ramaze/snippets/kernel/method.rb +0 -26
- data/lib/ramaze/snippets/method/name.rb +0 -22
- data/lib/ramaze/snippets/ramaze/autoreload.rb +0 -135
- data/lib/ramaze/snippets/rdoc/usage_no_exit.rb +0 -65
- data/spec/all.rb +0 -32
- data/spec/ramaze/conf/locale_de.yaml +0 -6
- data/spec/ramaze/conf/locale_en.yaml +0 -6
- data/spec/ramaze/dependencies.rb +0 -16
- data/spec/ramaze/global.rb +0 -44
data/lib/ramaze/helper/link.rb
CHANGED
|
@@ -4,87 +4,80 @@
|
|
|
4
4
|
module Ramaze
|
|
5
5
|
# LinkHelper is included into the Controller by default
|
|
6
6
|
#
|
|
7
|
-
#
|
|
8
|
-
# thing is that it looks up controller-paths if you pass it a controller
|
|
9
|
-
# the text shown is always the last segmet of the finished link from split('/')
|
|
10
|
-
#
|
|
11
|
-
# usage is pretty much shown in test/tc_helper
|
|
12
|
-
# however, to give you some idea of how it actually works, some examples:
|
|
13
|
-
#
|
|
14
|
-
# link MainController, :foo #=> '<a href="/foo">foo</a>'
|
|
15
|
-
# link MinorController, :foo #=> '<a href="/minor/foo">foo</a>'
|
|
16
|
-
# link MinorController, :foo, :bar #=> '<a href="/minor/foo/bar">bar</a>'
|
|
17
|
-
# link MainController, :foo, :raw => true #=> '/foo'
|
|
18
|
-
# link MainController, :foo => :bar #=> '/?foo=bar'
|
|
19
|
-
#
|
|
20
|
-
# link_raw MainController, :foo #=> '/foo'
|
|
21
|
-
# link_raw MinorController, :foo #=> '/minor/foo'
|
|
22
|
-
# link_raw MinorController, :foo, :bar #=> '/minor/foo/bar'
|
|
23
|
-
#
|
|
24
|
-
# TODO:
|
|
25
|
-
# - handling of no passed parameters
|
|
26
|
-
# - setting imagelinks
|
|
27
|
-
# - setting of id or class
|
|
28
|
-
# - taking advantae of Gestalt to build links
|
|
29
|
-
# - lots of other minor niceties, for the moment i'm only concerned to keep
|
|
30
|
-
# it as simple as possible
|
|
31
|
-
#
|
|
7
|
+
# Usage is pretty much shown in test/tc_helper and the rdocs below.
|
|
32
8
|
|
|
33
9
|
module LinkHelper
|
|
34
10
|
|
|
35
11
|
private
|
|
36
12
|
|
|
13
|
+
# Builds a basic <a> tag.
|
|
14
|
+
#
|
|
15
|
+
# `title` is mandatory, the second hash of options will be transformed into
|
|
16
|
+
# arguments of the tag, :href is a special case and its segments will be
|
|
17
|
+
# CGI.escaped.
|
|
18
|
+
#
|
|
19
|
+
# If you pass no :href, the title will be run through Rs and its result is
|
|
20
|
+
# used instead. If you really want an empty href, use :href => ''
|
|
21
|
+
#
|
|
37
22
|
# Usage:
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
# link MainController, :foo, :raw => true #=> '/foo'
|
|
42
|
-
# link MainController, :foo, :title => 'a' #=> '<a href="/minor/foo/bar">a</a>'
|
|
43
|
-
# link MainController, :foo => :bar #=> '/?foo=bar'
|
|
23
|
+
# A('title') #=> <a href="/title">title</a>
|
|
24
|
+
# A('foo/bar') #=> <a href="/foo/bar">foo/bar</a>
|
|
25
|
+
# A('Home' :href => Rs(:/)) #=> <a href="/foo/bar">foo/bar</a>
|
|
44
26
|
|
|
45
|
-
def
|
|
46
|
-
hash
|
|
27
|
+
def A(title, hash = {})
|
|
28
|
+
hash[:href] ||= Rs(title)
|
|
29
|
+
hash[:href].to_s.gsub!(/[^\/]+/){|m| CGI.escape(m) }
|
|
47
30
|
|
|
48
|
-
|
|
31
|
+
args = ['']
|
|
32
|
+
hash.each{|k,v| args << %(#{k}="#{v}") if k and v }
|
|
49
33
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
Global.mapping.invert[t] || t
|
|
53
|
-
end
|
|
34
|
+
%(<a#{args.join(' ')}>#{title || hash[:href]}</a>)
|
|
35
|
+
end
|
|
54
36
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
37
|
+
# Builds links out of segments.
|
|
38
|
+
#
|
|
39
|
+
# Pass it strings, symbols, controllers and it will produce a link out of
|
|
40
|
+
# it. Paths to Controllers are obtained from Global.mapping.
|
|
41
|
+
#
|
|
42
|
+
# For brevity, the mapping for the example below is following:
|
|
43
|
+
# { MC => '/', OC => '/o', ODC => '/od' }
|
|
44
|
+
#
|
|
45
|
+
# Usage:
|
|
46
|
+
# R(MC) #=> '/'
|
|
47
|
+
# R(OC) #=> '/o'
|
|
48
|
+
# R(ODC) #=> '/od'
|
|
49
|
+
# R(MC, :foo) #=> '/foo'
|
|
50
|
+
# R(OC, :foo) #=> '/o/foo'
|
|
51
|
+
# R(ODC, :foo) #=> '/od/foo'
|
|
52
|
+
# R(MC, :foo, :bar => :x) #=> '/foo?bar=x'
|
|
59
53
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
54
|
+
def R(*atoms)
|
|
55
|
+
args, atoms = atoms.partition{|a| a.is_a?(Hash) }
|
|
56
|
+
args = args.flatten.inject{|s,v| s.merge!(v) }
|
|
57
|
+
|
|
58
|
+
map = Global.mapping.invert
|
|
59
|
+
atoms.map! do |atom|
|
|
60
|
+
if atom.respond_to?(:new)
|
|
61
|
+
map[atom] || atom
|
|
62
|
+
else
|
|
63
|
+
map[atom.class] || atom
|
|
64
|
+
end
|
|
66
65
|
end
|
|
67
|
-
end
|
|
68
66
|
|
|
69
|
-
|
|
67
|
+
front = atoms.join('/').squeeze('/')
|
|
70
68
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
# R MinorController, :foo, :bar #=> '/minor/foo/bar'
|
|
75
|
-
|
|
76
|
-
def R *to
|
|
77
|
-
if to.last.is_a?(Hash)
|
|
78
|
-
to.last[:raw] = true
|
|
69
|
+
if args
|
|
70
|
+
rear = args.inject('?'){|s,(k,v)| s << "#{k}=#{v};"}[0..-2]
|
|
71
|
+
front + rear
|
|
79
72
|
else
|
|
80
|
-
|
|
73
|
+
front
|
|
81
74
|
end
|
|
82
|
-
|
|
83
|
-
Rlink(*to)
|
|
84
75
|
end
|
|
85
76
|
|
|
86
|
-
|
|
87
|
-
|
|
77
|
+
# Uses R with self as first element.
|
|
78
|
+
|
|
79
|
+
def Rs(*atoms)
|
|
80
|
+
R(self, *atoms)
|
|
88
81
|
end
|
|
89
82
|
end
|
|
90
83
|
end
|
data/lib/ramaze/inform.rb
CHANGED
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
4
|
require 'ramaze/inform/informing'
|
|
5
|
+
require 'ramaze/inform/hub'
|
|
6
|
+
require 'ramaze/inform/informer'
|
|
5
7
|
|
|
6
8
|
module Ramaze
|
|
7
9
|
autoload :Analogger, "ramaze/inform/analogger.rb"
|
|
8
|
-
autoload :Informer, "ramaze/inform/informer.rb"
|
|
9
10
|
autoload :Syslog, "ramaze/inform/syslog.rb"
|
|
10
11
|
autoload :Growl, "ramaze/inform/growl.rb"
|
|
11
12
|
autoload :Xosd, "ramaze/inform/xosd.rb"
|
|
12
|
-
|
|
13
|
+
|
|
14
|
+
unless defined?(Inform)
|
|
15
|
+
Inform = LogHub.new(Informer)
|
|
16
|
+
end
|
|
13
17
|
end
|
|
@@ -8,7 +8,11 @@ module Ramaze
|
|
|
8
8
|
class Analogger < ::Swiftcore::Analogger::Client
|
|
9
9
|
include Informing
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
trait :name => 'walrus'
|
|
12
|
+
trait :host => '127.0.0.1'
|
|
13
|
+
trait :port => 6766
|
|
14
|
+
|
|
15
|
+
def initialize(name = class_trait[:name], host = class_trait[:host], port = class_trait[:port])
|
|
12
16
|
super
|
|
13
17
|
end
|
|
14
18
|
|
data/lib/ramaze/inform/hub.rb
CHANGED
|
@@ -10,9 +10,9 @@ module Ramaze
|
|
|
10
10
|
def initialize(*loggers)
|
|
11
11
|
@loggers = loggers
|
|
12
12
|
@loggers.map! do |logger|
|
|
13
|
+
next(nil) if logger == self
|
|
13
14
|
logger.is_a?(Class) ? logger.new : logger
|
|
14
15
|
end
|
|
15
|
-
@loggers.delete_if {|x| x == self }
|
|
16
16
|
@loggers.uniq!
|
|
17
17
|
@loggers.compact!
|
|
18
18
|
end
|
|
@@ -27,6 +27,7 @@ module Ramaze
|
|
|
27
27
|
def error(ex)
|
|
28
28
|
if ex.respond_to?(:exception)
|
|
29
29
|
message = ex.backtrace[0..Global.backtrace_size]
|
|
30
|
+
message.map!{|m| m.gsub(/^#{Dir.pwd}/, '.') }
|
|
30
31
|
message.unshift(ex.inspect)
|
|
31
32
|
else
|
|
32
33
|
message = ex.to_s
|
|
@@ -40,5 +41,11 @@ module Ramaze
|
|
|
40
41
|
|
|
41
42
|
def shutdown
|
|
42
43
|
end
|
|
44
|
+
|
|
45
|
+
# stub for WEBrick
|
|
46
|
+
|
|
47
|
+
def debug?
|
|
48
|
+
false
|
|
49
|
+
end
|
|
43
50
|
end
|
|
44
51
|
end
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
|
+
# Extensions for Kernel
|
|
5
|
+
|
|
4
6
|
module Kernel
|
|
5
7
|
# Original from Trans (Facets 1.4.5)
|
|
6
8
|
# This is similar to +Module#const_get+ but is accessible at all levels,
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
Traits = Hash.new{|h,k| h[k] = {}} unless defined?(Traits)
|
|
5
5
|
|
|
6
|
+
# Extensions for Object
|
|
7
|
+
|
|
6
8
|
class Object
|
|
7
9
|
|
|
8
10
|
# Adds a method to Object to annotate your objects with certain traits.
|
|
@@ -62,6 +64,8 @@ class Object
|
|
|
62
64
|
ancs.reverse.inject({}){|s,v| s.merge(v.trait)}.merge(trait)
|
|
63
65
|
end
|
|
64
66
|
|
|
67
|
+
# trait for self.class
|
|
68
|
+
|
|
65
69
|
def class_trait
|
|
66
70
|
if respond_to?(:ancestors)
|
|
67
71
|
trait
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
# Extensions for OpenStruct
|
|
5
|
+
|
|
3
6
|
class OpenStruct
|
|
4
7
|
|
|
5
8
|
# create a new OpenStruct and fill it with a merge of the old @table and the passed hash
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
|
+
# Extensions for Struct
|
|
5
|
+
|
|
4
6
|
class Struct
|
|
5
7
|
|
|
6
8
|
# Action = Struct.new('Action', :template, :method, :params)
|
|
@@ -9,7 +11,11 @@ class Struct
|
|
|
9
11
|
# # => #<struct Struct::Action template=nil, method=:meth, params=[1]>
|
|
10
12
|
|
|
11
13
|
def self.fill(hash = {})
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
instance = new
|
|
15
|
+
hash.each do |key, value|
|
|
16
|
+
next unless members.include?(key.to_s)
|
|
17
|
+
instance.send("#{key}=", value)
|
|
18
|
+
end
|
|
19
|
+
instance
|
|
14
20
|
end
|
|
15
21
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
# Extensions for Struct
|
|
5
|
+
|
|
6
|
+
class Struct
|
|
7
|
+
|
|
8
|
+
# Point = Struct.new(:x, :y)
|
|
9
|
+
# point = Point.new(15, 10)
|
|
10
|
+
# point.values_at(:y, :x)
|
|
11
|
+
# # => [10, 15]
|
|
12
|
+
|
|
13
|
+
def values_at(*keys)
|
|
14
|
+
keys.map{|k| self[k.to_sym] }
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
require 'set'
|
|
5
|
+
|
|
6
|
+
module Ramaze
|
|
7
|
+
class SourceReload
|
|
8
|
+
attr_accessor :thread, :interval, :reload_glob, :map
|
|
9
|
+
|
|
10
|
+
def initialize interval = 1, reload_glob = %r{(^\./)|#{Dir.pwd}|ramaze}
|
|
11
|
+
@interval, @reload_glob = interval, reload_glob
|
|
12
|
+
@mtimes, @map = {}, []
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def start
|
|
16
|
+
Inform.debug("initialize automatic source reload every #{interval} seconds")
|
|
17
|
+
@thread = reloader
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.startup options = {}
|
|
21
|
+
interval = Global.sourcereload
|
|
22
|
+
instance = new(interval)
|
|
23
|
+
Thread.main[:sourcereload] = instance
|
|
24
|
+
instance.reload # initial scan of all files
|
|
25
|
+
instance.start if interval
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def reloader
|
|
29
|
+
Thread.new do
|
|
30
|
+
loop do
|
|
31
|
+
reload
|
|
32
|
+
sleep(@interval)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# This method is quite handy if you want direct control over when your code is reloaded
|
|
38
|
+
#
|
|
39
|
+
# Usage example:
|
|
40
|
+
#
|
|
41
|
+
# trap :HUB do
|
|
42
|
+
# Ramaze::Inform.info "reloading source"
|
|
43
|
+
# Thread.main[:sourcereload].reload
|
|
44
|
+
# end
|
|
45
|
+
#
|
|
46
|
+
|
|
47
|
+
def reload
|
|
48
|
+
all_reload_files.each do |file|
|
|
49
|
+
mtime = mtime(file)
|
|
50
|
+
|
|
51
|
+
next if (@mtimes[file] ||= mtime) == mtime
|
|
52
|
+
|
|
53
|
+
Inform.debug("reload #{file}")
|
|
54
|
+
@mtimes[file] = mtime if safe_load(file)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def all_reload_files
|
|
59
|
+
files, paths = $LOADED_FEATURES, Array['', './', *$LOAD_PATH]
|
|
60
|
+
|
|
61
|
+
unless [@files, @paths] == [files, paths]
|
|
62
|
+
@files, @paths = files.dup, paths.dup
|
|
63
|
+
|
|
64
|
+
map = files.map do |file|
|
|
65
|
+
possible = paths.map{|pa| File.join(pa.to_s, file.to_s) }
|
|
66
|
+
possible.find{|po| File.exists?(po) }
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
@map = map.compact
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
m = @map.grep(@reload_glob)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def mtime(file)
|
|
76
|
+
File.mtime(file)
|
|
77
|
+
rescue Errno::ENOENT
|
|
78
|
+
false
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def safe_load(file)
|
|
82
|
+
load(file)
|
|
83
|
+
true
|
|
84
|
+
rescue Object => ex
|
|
85
|
+
Inform.error(ex)
|
|
86
|
+
false
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|