ramaze 0.0.6
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 +360 -0
- data/bin/ramaze +152 -0
- data/doc/CHANGELOG +2021 -0
- data/doc/COPYING +56 -0
- data/doc/COPYING.ja +51 -0
- data/doc/README +275 -0
- data/doc/TODO +33 -0
- data/doc/allison/LICENSE +184 -0
- data/doc/allison/README +37 -0
- data/doc/allison/allison.css +300 -0
- data/doc/allison/allison.gif +0 -0
- data/doc/allison/allison.js +307 -0
- data/doc/allison/allison.rb +287 -0
- data/doc/allison/cache/BODY +588 -0
- data/doc/allison/cache/CLASS_INDEX +4 -0
- data/doc/allison/cache/CLASS_PAGE +1 -0
- data/doc/allison/cache/FILE_INDEX +4 -0
- data/doc/allison/cache/FILE_PAGE +1 -0
- data/doc/allison/cache/FONTS +1 -0
- data/doc/allison/cache/FR_INDEX_BODY +1 -0
- data/doc/allison/cache/IMGPATH +1 -0
- data/doc/allison/cache/INDEX +1 -0
- data/doc/allison/cache/JAVASCRIPT +307 -0
- data/doc/allison/cache/METHOD_INDEX +4 -0
- data/doc/allison/cache/METHOD_LIST +1 -0
- data/doc/allison/cache/SRC_PAGE +1 -0
- data/doc/allison/cache/STYLE +322 -0
- data/doc/allison/cache/URL +1 -0
- data/examples/blog/main.rb +16 -0
- data/examples/blog/public/screen.css +106 -0
- data/examples/blog/src/controller.rb +50 -0
- data/examples/blog/src/element.rb +53 -0
- data/examples/blog/src/model.rb +29 -0
- data/examples/blog/template/edit.xhtml +6 -0
- data/examples/blog/template/index.xhtml +24 -0
- data/examples/blog/template/new.xhtml +5 -0
- data/examples/blog/template/view.xhtml +15 -0
- data/examples/blog/test/tc_entry.rb +18 -0
- data/examples/caching.rb +23 -0
- data/examples/element.rb +40 -0
- data/examples/hello.rb +23 -0
- data/examples/simple.rb +60 -0
- data/examples/templates/template/external.haml +21 -0
- data/examples/templates/template/external.liquid +28 -0
- data/examples/templates/template/external.mab +27 -0
- data/examples/templates/template/external.rhtml +29 -0
- data/examples/templates/template/external.rmze +24 -0
- data/examples/templates/template_erubis.rb +50 -0
- data/examples/templates/template_haml.rb +48 -0
- data/examples/templates/template_liquid.rb +64 -0
- data/examples/templates/template_markaby.rb +52 -0
- data/examples/templates/template_ramaze.rb +49 -0
- data/examples/whywiki/main.rb +56 -0
- data/examples/whywiki/template/edit.xhtml +14 -0
- data/examples/whywiki/template/show.xhtml +17 -0
- data/lib/proto/conf/benchmark.yaml +35 -0
- data/lib/proto/conf/debug.yaml +34 -0
- data/lib/proto/conf/live.yaml +33 -0
- data/lib/proto/conf/silent.yaml +31 -0
- data/lib/proto/conf/stage.yaml +33 -0
- data/lib/proto/main.rb +18 -0
- data/lib/proto/public/404.jpg +0 -0
- data/lib/proto/public/css/coderay.css +105 -0
- data/lib/proto/public/css/ramaze_error.css +42 -0
- data/lib/proto/public/error.xhtml +74 -0
- data/lib/proto/public/favicon.ico +0 -0
- data/lib/proto/public/js/jquery.js +1923 -0
- data/lib/proto/public/ramaze.png +0 -0
- data/lib/proto/src/controller/main.rb +7 -0
- data/lib/proto/src/element/page.rb +16 -0
- data/lib/proto/src/model.rb +5 -0
- data/lib/proto/template/index.xhtml +6 -0
- data/lib/ramaze.rb +317 -0
- data/lib/ramaze/adapter/mongrel.rb +111 -0
- data/lib/ramaze/adapter/webrick.rb +161 -0
- data/lib/ramaze/cache.rb +11 -0
- data/lib/ramaze/cache/memcached.rb +52 -0
- data/lib/ramaze/cache/memory.rb +6 -0
- data/lib/ramaze/cache/yaml_store.rb +37 -0
- data/lib/ramaze/controller.rb +10 -0
- data/lib/ramaze/dispatcher.rb +315 -0
- data/lib/ramaze/error.rb +11 -0
- data/lib/ramaze/gestalt.rb +108 -0
- data/lib/ramaze/global.rb +120 -0
- data/lib/ramaze/helper.rb +32 -0
- data/lib/ramaze/helper/aspect.rb +189 -0
- data/lib/ramaze/helper/auth.rb +120 -0
- data/lib/ramaze/helper/cache.rb +52 -0
- data/lib/ramaze/helper/feed.rb +135 -0
- data/lib/ramaze/helper/form.rb +204 -0
- data/lib/ramaze/helper/link.rb +80 -0
- data/lib/ramaze/helper/redirect.rb +48 -0
- data/lib/ramaze/helper/stack.rb +67 -0
- data/lib/ramaze/http_status.rb +66 -0
- data/lib/ramaze/inform.rb +166 -0
- data/lib/ramaze/snippets.rb +5 -0
- data/lib/ramaze/snippets/hash/keys_to_sym.rb +19 -0
- data/lib/ramaze/snippets/kernel/aquire.rb +22 -0
- data/lib/ramaze/snippets/kernel/autoreload.rb +79 -0
- data/lib/ramaze/snippets/kernel/caller_lines.rb +58 -0
- data/lib/ramaze/snippets/kernel/constant.rb +24 -0
- data/lib/ramaze/snippets/kernel/rescue_require.rb +12 -0
- data/lib/ramaze/snippets/kernel/self_method.rb +41 -0
- data/lib/ramaze/snippets/kernel/silently.rb +13 -0
- data/lib/ramaze/snippets/object/traits.rb +60 -0
- data/lib/ramaze/snippets/openstruct/temp.rb +10 -0
- data/lib/ramaze/snippets/string/DIVIDE.rb +16 -0
- data/lib/ramaze/snippets/string/camel_case.rb +14 -0
- data/lib/ramaze/snippets/string/snake_case.rb +12 -0
- data/lib/ramaze/snippets/symbol/to_proc.rb +14 -0
- data/lib/ramaze/snippets/thread/deadQUESTIONMARK.rb +11 -0
- data/lib/ramaze/store/default.rb +48 -0
- data/lib/ramaze/template.rb +102 -0
- data/lib/ramaze/template/amrita2.rb +40 -0
- data/lib/ramaze/template/erubis.rb +58 -0
- data/lib/ramaze/template/haml.rb +65 -0
- data/lib/ramaze/template/haml/actionview_stub.rb +20 -0
- data/lib/ramaze/template/liquid.rb +74 -0
- data/lib/ramaze/template/markaby.rb +68 -0
- data/lib/ramaze/template/ramaze.rb +177 -0
- data/lib/ramaze/template/ramaze/element.rb +166 -0
- data/lib/ramaze/template/ramaze/morpher.rb +156 -0
- data/lib/ramaze/tool/create.rb +70 -0
- data/lib/ramaze/tool/tidy.rb +71 -0
- data/lib/ramaze/trinity.rb +38 -0
- data/lib/ramaze/trinity/request.rb +244 -0
- data/lib/ramaze/trinity/response.rb +41 -0
- data/lib/ramaze/trinity/session.rb +129 -0
- data/lib/ramaze/version.rb +14 -0
- data/spec/spec_all.rb +73 -0
- data/spec/spec_helper.rb +215 -0
- data/spec/tc_adapter_mongrel.rb +24 -0
- data/spec/tc_adapter_webrick.rb +22 -0
- data/spec/tc_cache.rb +79 -0
- data/spec/tc_controller.rb +39 -0
- data/spec/tc_element.rb +100 -0
- data/spec/tc_error.rb +23 -0
- data/spec/tc_gestalt.rb +90 -0
- data/spec/tc_global.rb +46 -0
- data/spec/tc_helper_aspect.rb +65 -0
- data/spec/tc_helper_auth.rb +61 -0
- data/spec/tc_helper_cache.rb +81 -0
- data/spec/tc_helper_feed.rb +129 -0
- data/spec/tc_helper_form.rb +146 -0
- data/spec/tc_helper_link.rb +58 -0
- data/spec/tc_helper_redirect.rb +51 -0
- data/spec/tc_helper_stack.rb +55 -0
- data/spec/tc_morpher.rb +90 -0
- data/spec/tc_params.rb +84 -0
- data/spec/tc_request.rb +111 -0
- data/spec/tc_session.rb +56 -0
- data/spec/tc_store.rb +25 -0
- data/spec/tc_template_amrita2.rb +34 -0
- data/spec/tc_template_erubis.rb +41 -0
- data/spec/tc_template_haml.rb +44 -0
- data/spec/tc_template_liquid.rb +98 -0
- data/spec/tc_template_markaby.rb +74 -0
- data/spec/tc_template_ramaze.rb +54 -0
- data/spec/tc_tidy.rb +14 -0
- data/spec/template/amrita2/data.html +6 -0
- data/spec/template/amrita2/index.html +1 -0
- data/spec/template/amrita2/sum.html +1 -0
- data/spec/template/erubis/sum.rhtml +1 -0
- data/spec/template/haml/index.haml +5 -0
- data/spec/template/haml/with_vars.haml +4 -0
- data/spec/template/liquid/index.liquid +1 -0
- data/spec/template/liquid/products.liquid +45 -0
- data/spec/template/markaby/external.mab +8 -0
- data/spec/template/markaby/sum.mab +1 -0
- data/spec/template/ramaze/file_only.rmze +1 -0
- data/spec/template/ramaze/index.rmze +1 -0
- data/spec/template/ramaze/nested.rmze +1 -0
- data/spec/template/ramaze/sum.rmze +1 -0
- metadata +317 -0
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
module Kernel
|
|
5
|
+
|
|
6
|
+
# Example:
|
|
7
|
+
# aquire 'foo/bar/*'
|
|
8
|
+
# requires all files inside foo/bar - recursive
|
|
9
|
+
# can take multiple parameters, it's mainly used to require all the
|
|
10
|
+
# snippets.
|
|
11
|
+
|
|
12
|
+
def aquire *files
|
|
13
|
+
files.each do |file|
|
|
14
|
+
require file if %w(rb so).any?{|f| File.file?("#{file}.#{f}")}
|
|
15
|
+
$:.each do |path|
|
|
16
|
+
Dir[File.join(path, file, '*.rb')].each do |file|
|
|
17
|
+
require file
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
|
|
8
|
+
# this method loops through all loaded/required files
|
|
9
|
+
# and re-loads them when they are updated.
|
|
10
|
+
# It takes one parameter, which is the interval in seconds
|
|
11
|
+
# with a default of 10.
|
|
12
|
+
# You can also safely kill all threads (except for the main)
|
|
13
|
+
# and it will just restart the autoreloader.
|
|
14
|
+
|
|
15
|
+
def self.autoreload interval = 10
|
|
16
|
+
debug "initialize autoreload with an interval of #{interval} seconds"
|
|
17
|
+
|
|
18
|
+
gatherer = Thread.new do
|
|
19
|
+
this = Thread.current
|
|
20
|
+
this[:task] = :autoreload
|
|
21
|
+
|
|
22
|
+
cache = {}
|
|
23
|
+
file_set = Set.new
|
|
24
|
+
|
|
25
|
+
loop do
|
|
26
|
+
files = file_set.dup
|
|
27
|
+
$LOADED_FEATURES.map do |file|
|
|
28
|
+
file = file.to_s
|
|
29
|
+
paths = $LOAD_PATH + ['']
|
|
30
|
+
correct_path = paths.find{|lp| File.exist?(File.join(lp.to_s, file))}
|
|
31
|
+
correct_file = File.expand_path(File.join(correct_path, file)) if correct_path
|
|
32
|
+
|
|
33
|
+
files << correct_file if correct_file
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
this[:files] = files
|
|
37
|
+
|
|
38
|
+
sleep_interval = this[:interval] ||= interval || 10
|
|
39
|
+
sleep sleep_interval
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
reloader = Thread.new do
|
|
44
|
+
this = Thread.current
|
|
45
|
+
this[:task] = :autoreload
|
|
46
|
+
|
|
47
|
+
cache = {}
|
|
48
|
+
this[:interval] = interval
|
|
49
|
+
sleep 0.1 until gatherer[:files] # wait for the gatherer
|
|
50
|
+
|
|
51
|
+
loop do
|
|
52
|
+
gatherer[:files].each do |file|
|
|
53
|
+
begin
|
|
54
|
+
current_time = File.mtime(file)
|
|
55
|
+
if last_time = cache[file]
|
|
56
|
+
unless last_time == current_time
|
|
57
|
+
Ramaze::Informer.info "autoreload #{file}"
|
|
58
|
+
load(file)
|
|
59
|
+
cache[file] = current_time
|
|
60
|
+
end
|
|
61
|
+
else
|
|
62
|
+
cache[file] = current_time
|
|
63
|
+
end
|
|
64
|
+
rescue Object => ex # catches errors when the load fails
|
|
65
|
+
# in case mtime fails
|
|
66
|
+
unless ex.message =~ /No such file or directory/
|
|
67
|
+
puts ex
|
|
68
|
+
puts ex.backtrace
|
|
69
|
+
end
|
|
70
|
+
# sleep a total of reloader[:interval],
|
|
71
|
+
# but spread it evenly on all files
|
|
72
|
+
end # begin
|
|
73
|
+
sleep_interval = this[:interval].to_f / gatherer[:files].size
|
|
74
|
+
sleep sleep_interval
|
|
75
|
+
end # each
|
|
76
|
+
end # loop
|
|
77
|
+
end # Thread.new
|
|
78
|
+
end # autoreload
|
|
79
|
+
end # Ramaze
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
module Kernel
|
|
5
|
+
# Gives you back the file, line and method of the caller number i
|
|
6
|
+
# Example:
|
|
7
|
+
# __caller_info__(1) # -> ['/usr/lib/ruby/1.8/irb/workspace.rb', '52', 'irb_binding']
|
|
8
|
+
|
|
9
|
+
def __caller_info__(i = 1)
|
|
10
|
+
file, line, meth = caller[i].scan(/(.*?):(\d+):in `(.*?)'/).first
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Gives you some context around a specific line in a file.
|
|
14
|
+
# the size argument works in both directions + the actual line,
|
|
15
|
+
# size = 2 gives you 5 lines of source, the returned array has the
|
|
16
|
+
# following format.
|
|
17
|
+
# [
|
|
18
|
+
# line = [
|
|
19
|
+
# lineno = Integer,
|
|
20
|
+
# line = String,
|
|
21
|
+
# is_searched_line = (lineno == initial_lineno)
|
|
22
|
+
# ],
|
|
23
|
+
# ...,
|
|
24
|
+
# ...
|
|
25
|
+
# ]
|
|
26
|
+
# Example:
|
|
27
|
+
# __caller_lines__('/usr/lib/ruby/1.8/debug.rb', 122, 2) # ->
|
|
28
|
+
# [
|
|
29
|
+
# [ 120, " def check_suspend", false ],
|
|
30
|
+
# [ 121, " return if Thread.critical", false ],
|
|
31
|
+
# [ 122, " while (Thread.critical = true; @suspend_next)", true ],
|
|
32
|
+
# [ 123, " DEBUGGER__.waiting.push Thread.current", false ],
|
|
33
|
+
# [ 124, " @suspend_next = false", false ]
|
|
34
|
+
# ]
|
|
35
|
+
|
|
36
|
+
def __caller_lines__ file, line, size = 4
|
|
37
|
+
return [[0, file, true]] if file == '(eval)'
|
|
38
|
+
lines = File.readlines(file)
|
|
39
|
+
current = line.to_i - 1
|
|
40
|
+
|
|
41
|
+
first = current - size
|
|
42
|
+
first = first < 0 ? 0 : first
|
|
43
|
+
|
|
44
|
+
last = current + size
|
|
45
|
+
last = last > lines.size ? lines.size : last
|
|
46
|
+
|
|
47
|
+
log = lines[first..last]
|
|
48
|
+
|
|
49
|
+
area = []
|
|
50
|
+
|
|
51
|
+
log.each_with_index do |line, index|
|
|
52
|
+
index = index + first + 1
|
|
53
|
+
area << [index, line.chomp, index == current + 1]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
area
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
module Kernel
|
|
5
|
+
# Original from Trans (Facets 1.4.5)
|
|
6
|
+
# This is similar to +Module#const_get+ but is accessible at all levels,
|
|
7
|
+
# and, unlike +const_get+, can handle module hierarchy.
|
|
8
|
+
#
|
|
9
|
+
# constant("Fixnum") # -> Fixnum
|
|
10
|
+
# constant(:Fixnum) # -> Fixnum
|
|
11
|
+
#
|
|
12
|
+
# constant("Process::Sys") # -> Process::Sys
|
|
13
|
+
# constant("Regexp::MULTILINE") # -> 4
|
|
14
|
+
#
|
|
15
|
+
# require 'test/unit'
|
|
16
|
+
# Test.constant("Unit::Assertions") # -> Test::Unit::Assertions
|
|
17
|
+
# Test.constant("::Test::Unit") # -> Test::Unit
|
|
18
|
+
#
|
|
19
|
+
def constant(const)
|
|
20
|
+
const = const.to_s.dup
|
|
21
|
+
base = const.sub!(/^::/, '') ? Object : ( self.kind_of?(Module) ? self : self.class )
|
|
22
|
+
const.split(/::/).inject(base){ |mod, name| mod.const_get(name) }
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
module Kernel
|
|
4
|
+
|
|
5
|
+
# try to require a file, output message if it failes.
|
|
6
|
+
|
|
7
|
+
def rescue_require(sym, message = nil)
|
|
8
|
+
require sym
|
|
9
|
+
rescue LoadError, RuntimeError
|
|
10
|
+
puts message if message
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
module Kernel
|
|
5
|
+
alias_method :method_get, :method unless defined? method_get
|
|
6
|
+
|
|
7
|
+
# get the object of the method you are currently in or any
|
|
8
|
+
# other out of the backtrace, as long as it is in the same
|
|
9
|
+
# instance and retrievable via method_get (which is the old #method).
|
|
10
|
+
#
|
|
11
|
+
# class Foo
|
|
12
|
+
# def bar
|
|
13
|
+
# method
|
|
14
|
+
# end
|
|
15
|
+
# end
|
|
16
|
+
#
|
|
17
|
+
# Foo.new.bar #=> #<Method: Foo#bar>
|
|
18
|
+
|
|
19
|
+
def method(n = 0)
|
|
20
|
+
return method_get(n) unless n.is_a? Integer
|
|
21
|
+
method_get caller.to_s.scan(/`(.*?)'/)[n].first rescue nil
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class Method
|
|
26
|
+
|
|
27
|
+
# name of the Method (example shows combination with the new Kernel#method)
|
|
28
|
+
#
|
|
29
|
+
# class Foo
|
|
30
|
+
# def bar
|
|
31
|
+
# method.name
|
|
32
|
+
# end
|
|
33
|
+
# end
|
|
34
|
+
#
|
|
35
|
+
# Foo.new.bar #=> 'bar'
|
|
36
|
+
|
|
37
|
+
def name
|
|
38
|
+
#<Method: A.d>
|
|
39
|
+
inspect.gsub(/#<Method: .*?[\.#](.*?)>/, '\1')
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
module Kernel
|
|
4
|
+
|
|
5
|
+
# sets $VERBOSE temporarily to nil so you can redefine constants in peace
|
|
6
|
+
|
|
7
|
+
def silently
|
|
8
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
|
9
|
+
yield
|
|
10
|
+
ensure
|
|
11
|
+
$VERBOSE = old_verbose
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
Traits = Hash.new{|h,k| h[k] = {}}
|
|
5
|
+
|
|
6
|
+
class Object
|
|
7
|
+
|
|
8
|
+
# Adds a method to Object to annotate your objects with certain traits.
|
|
9
|
+
# It's basically a simple Hash that takes the current object as key
|
|
10
|
+
#
|
|
11
|
+
# Example:
|
|
12
|
+
#
|
|
13
|
+
# class Foo
|
|
14
|
+
# trait :instance => false
|
|
15
|
+
#
|
|
16
|
+
# def initialize
|
|
17
|
+
# trait :instance => true
|
|
18
|
+
# end
|
|
19
|
+
# end
|
|
20
|
+
#
|
|
21
|
+
# Foo.trait[:instance]
|
|
22
|
+
# # false
|
|
23
|
+
#
|
|
24
|
+
# foo = Foo.new
|
|
25
|
+
# foo.trait[:instance]
|
|
26
|
+
# # true
|
|
27
|
+
|
|
28
|
+
def trait hash = nil
|
|
29
|
+
if hash
|
|
30
|
+
Traits[self].merge! hash
|
|
31
|
+
else
|
|
32
|
+
Traits[self]
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# builds a trait from all the ancestors, closer ancestors
|
|
37
|
+
# overwrite distant ancestors
|
|
38
|
+
#
|
|
39
|
+
# class Foo
|
|
40
|
+
# trait :one => :eins
|
|
41
|
+
# trait :first => :erstes
|
|
42
|
+
# end
|
|
43
|
+
#
|
|
44
|
+
# class Bar < Foo
|
|
45
|
+
# trait :two => :zwei
|
|
46
|
+
# end
|
|
47
|
+
#
|
|
48
|
+
# class Foobar < Bar
|
|
49
|
+
# trait :three => :drei
|
|
50
|
+
# trait :first => :overwritten
|
|
51
|
+
# end
|
|
52
|
+
#
|
|
53
|
+
# Foobar.ancestral_trait
|
|
54
|
+
# {:three=>:drei, :two=>:zwei, :one=>:eins, :first=>:overwritten}
|
|
55
|
+
|
|
56
|
+
def ancestral_trait
|
|
57
|
+
ancs = (ancestors rescue self.class.ancestors)
|
|
58
|
+
ancs.reverse.inject({}){|s,v| s.merge(v.trait)}.merge(trait)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
class OpenStruct
|
|
4
|
+
|
|
5
|
+
# create a new OpenStruct and fill it with a merge of the old @table and the passed hash
|
|
6
|
+
|
|
7
|
+
def temp hash
|
|
8
|
+
self.class.new(@table.merge(hash))
|
|
9
|
+
end
|
|
10
|
+
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
|
+
class String
|
|
5
|
+
|
|
6
|
+
# A convinient way to do File.join
|
|
7
|
+
#
|
|
8
|
+
# Example:
|
|
9
|
+
# 'a' / 'b' # -> 'a/b'
|
|
10
|
+
# File.dirname(__FILE__) / 'bar' # -> "ramaze/snippets/string/bar"
|
|
11
|
+
|
|
12
|
+
def / obj
|
|
13
|
+
File.join(self, obj.to_s)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
class String
|
|
5
|
+
|
|
6
|
+
# simple transformation to CamelCase from snake_case
|
|
7
|
+
#
|
|
8
|
+
# 'foo_bar'.camel_case # => 'FooBar'
|
|
9
|
+
|
|
10
|
+
def camel_case
|
|
11
|
+
split('_').map{|e| e.capitalize}.join
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
class String
|
|
4
|
+
|
|
5
|
+
# convert to snake_case from CamelCase
|
|
6
|
+
#
|
|
7
|
+
# 'FooBar'.snake_case # => 'foo_bar'
|
|
8
|
+
|
|
9
|
+
def snake_case
|
|
10
|
+
gsub(/\B[A-Z]/, '_\&').downcase.gsub(' ', '_')
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
class Symbol
|
|
4
|
+
|
|
5
|
+
# the well-known #to_proc
|
|
6
|
+
# creates a lambda that sends the symbol and any further arguments
|
|
7
|
+
# to the object yielded.
|
|
8
|
+
# [1, 2, 3].map(&:to_s) # => ['1', '2', '3']
|
|
9
|
+
# %w[a b c].map(&:to_sym) # => [:a, :b, :c]
|
|
10
|
+
|
|
11
|
+
def to_proc
|
|
12
|
+
lambda{|o, *args| o.send(self, *args) }
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
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 'yaml/store'
|
|
5
|
+
|
|
6
|
+
module Ramaze
|
|
7
|
+
module Store
|
|
8
|
+
|
|
9
|
+
# A simple wrapper around YAML::Store
|
|
10
|
+
|
|
11
|
+
class Default
|
|
12
|
+
attr_accessor :db
|
|
13
|
+
|
|
14
|
+
# create a new store with a filename
|
|
15
|
+
|
|
16
|
+
def initialize filename = 'db.yaml'
|
|
17
|
+
FileUtils.touch(filename)
|
|
18
|
+
@db = YAML::Store.new(filename)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# pass on all methods inside a transaction
|
|
22
|
+
|
|
23
|
+
def method_missing(meth, *args, &block)
|
|
24
|
+
@db.transaction do
|
|
25
|
+
@db.send(meth, *args, &block)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# the actual content of the store in YAML format
|
|
30
|
+
|
|
31
|
+
def to_yaml
|
|
32
|
+
Db.dump(:x)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# loads the #to_yaml
|
|
36
|
+
|
|
37
|
+
def original
|
|
38
|
+
YAML.load(to_yaml)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# available keys of the store
|
|
42
|
+
|
|
43
|
+
def keys
|
|
44
|
+
original.keys
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|