merb-core 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README +3 -3
- data/Rakefile +144 -33
- data/bin/merb +0 -0
- data/bin/merb-specs +0 -0
- data/docs/bootloading.dox +1 -0
- data/docs/merb-core-call-stack-diagram.mmap +0 -0
- data/docs/merb-core-call-stack-diagram.pdf +0 -0
- data/docs/merb-core-call-stack-diagram.png +0 -0
- data/lib/merb-core.rb +159 -37
- data/lib/merb-core/autoload.rb +1 -0
- data/lib/merb-core/bootloader.rb +208 -92
- data/lib/merb-core/config.rb +20 -6
- data/lib/merb-core/controller/abstract_controller.rb +113 -61
- data/lib/merb-core/controller/exceptions.rb +28 -13
- data/lib/merb-core/controller/merb_controller.rb +73 -44
- data/lib/merb-core/controller/mime.rb +25 -7
- data/lib/merb-core/controller/mixins/authentication.rb +1 -1
- data/lib/merb-core/controller/mixins/controller.rb +44 -8
- data/lib/merb-core/controller/mixins/render.rb +191 -128
- data/lib/merb-core/controller/mixins/responder.rb +65 -63
- data/lib/merb-core/controller/template.rb +103 -54
- data/lib/merb-core/core_ext.rb +7 -12
- data/lib/merb-core/core_ext/kernel.rb +128 -136
- data/lib/merb-core/dispatch/cookies.rb +26 -4
- data/lib/merb-core/dispatch/default_exception/default_exception.rb +93 -0
- data/lib/merb-core/dispatch/default_exception/views/_css.html.erb +198 -0
- data/lib/merb-core/dispatch/default_exception/views/_javascript.html.erb +73 -0
- data/lib/merb-core/dispatch/default_exception/views/index.html.erb +92 -0
- data/lib/merb-core/dispatch/dispatcher.rb +156 -224
- data/lib/merb-core/dispatch/request.rb +126 -25
- data/lib/merb-core/dispatch/router.rb +61 -6
- data/lib/merb-core/dispatch/router/behavior.rb +122 -41
- data/lib/merb-core/dispatch/router/route.rb +147 -22
- data/lib/merb-core/dispatch/session.rb +52 -2
- data/lib/merb-core/dispatch/session/cookie.rb +4 -2
- data/lib/merb-core/dispatch/session/memcached.rb +38 -27
- data/lib/merb-core/dispatch/session/memory.rb +18 -11
- data/lib/merb-core/dispatch/worker.rb +28 -0
- data/lib/merb-core/gem_ext/erubis.rb +58 -0
- data/lib/merb-core/logger.rb +3 -31
- data/lib/merb-core/plugins.rb +25 -3
- data/lib/merb-core/rack.rb +18 -12
- data/lib/merb-core/rack/adapter.rb +10 -8
- data/lib/merb-core/rack/adapter/ebb.rb +2 -2
- data/lib/merb-core/rack/adapter/irb.rb +31 -21
- data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +26 -0
- data/lib/merb-core/rack/adapter/thin.rb +19 -9
- data/lib/merb-core/rack/adapter/thin_turbo.rb +24 -0
- data/lib/merb-core/rack/application.rb +9 -84
- data/lib/merb-core/rack/middleware.rb +26 -0
- data/lib/merb-core/rack/middleware/path_prefix.rb +31 -0
- data/lib/merb-core/rack/middleware/profiler.rb +19 -0
- data/lib/merb-core/rack/middleware/static.rb +45 -0
- data/lib/merb-core/server.rb +27 -9
- data/lib/merb-core/tasks/audit.rake +68 -0
- data/lib/merb-core/tasks/merb.rb +1 -0
- data/lib/merb-core/tasks/merb_rake_helper.rb +12 -0
- data/lib/merb-core/tasks/stats.rake +71 -0
- data/lib/merb-core/test.rb +2 -1
- data/lib/merb-core/test/helpers/multipart_request_helper.rb +3 -3
- data/lib/merb-core/test/helpers/request_helper.rb +66 -24
- data/lib/merb-core/test/matchers/controller_matchers.rb +36 -4
- data/lib/merb-core/test/matchers/route_matchers.rb +12 -3
- data/lib/merb-core/test/matchers/view_matchers.rb +3 -3
- data/lib/merb-core/test/run_specs.rb +1 -0
- data/lib/merb-core/test/tasks/spectasks.rb +13 -5
- data/lib/merb-core/test/test_ext/string.rb +14 -0
- data/lib/merb-core/vendor/facets/dictionary.rb +3 -3
- data/lib/merb-core/vendor/facets/inflect.rb +82 -37
- data/lib/merb-core/version.rb +2 -2
- data/spec/private/config/config_spec.rb +39 -4
- data/spec/private/core_ext/kernel_spec.rb +3 -14
- data/spec/private/dispatch/bootloader_spec.rb +1 -1
- data/spec/private/dispatch/cookies_spec.rb +181 -69
- data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +0 -2
- data/spec/private/dispatch/fixture/app/controllers/foo.rb +0 -2
- data/spec/private/dispatch/fixture/config/rack.rb +10 -0
- data/spec/private/dispatch/fixture/log/merb_test.log +7054 -1802
- data/spec/private/dispatch/route_params_spec.rb +2 -3
- data/spec/private/dispatch/session_mixin_spec.rb +47 -0
- data/spec/private/plugins/plugin_spec.rb +73 -59
- data/spec/private/router/behavior_spec.rb +60 -0
- data/spec/private/router/fixture/log/merb_test.log +1693 -0
- data/spec/private/router/route_spec.rb +414 -0
- data/spec/private/router/router_spec.rb +175 -0
- data/spec/private/vendor/facets/plural_spec.rb +564 -0
- data/spec/private/vendor/facets/singular_spec.rb +489 -0
- data/spec/public/abstract_controller/controllers/cousins.rb +41 -0
- data/spec/public/abstract_controller/controllers/helpers.rb +12 -2
- data/spec/public/abstract_controller/controllers/partial.rb +17 -2
- data/spec/public/abstract_controller/controllers/render.rb +16 -1
- data/spec/public/abstract_controller/controllers/views/helpers/capture_eq/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/helpers/capture_with_args/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_two_throw_contents/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/index.erb +1 -0
- data/spec/public/abstract_controller/filter_spec.rb +20 -1
- data/spec/public/abstract_controller/helper_spec.rb +10 -2
- data/spec/public/abstract_controller/partial_spec.rb +8 -0
- data/spec/public/abstract_controller/render_spec.rb +8 -0
- data/spec/public/abstract_controller/spec_helper.rb +7 -3
- data/spec/public/boot_loader/boot_loader_spec.rb +2 -2
- data/spec/public/controller/base_spec.rb +10 -2
- data/spec/public/controller/config/init.rb +6 -0
- data/spec/public/controller/controllers/authentication.rb +9 -11
- data/spec/public/controller/controllers/base.rb +2 -8
- data/spec/public/controller/controllers/cookies.rb +16 -0
- data/spec/public/controller/controllers/dispatcher.rb +35 -0
- data/spec/public/controller/controllers/display.rb +62 -14
- data/spec/public/controller/controllers/redirect.rb +36 -0
- data/spec/public/controller/controllers/responder.rb +37 -11
- data/spec/public/controller/controllers/views/layout/custom_arg.json.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.xml.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/no_layout.html.erb +1 -0
- data/spec/public/controller/cookies_spec.rb +23 -0
- data/spec/public/controller/dispatcher_spec.rb +411 -0
- data/spec/public/controller/display_spec.rb +43 -10
- data/spec/public/controller/redirect_spec.rb +33 -0
- data/spec/public/controller/responder_spec.rb +79 -11
- data/spec/public/controller/spec_helper.rb +3 -1
- data/spec/public/controller/url_spec.rb +10 -0
- data/spec/public/core/merb_core_spec.rb +11 -0
- data/spec/public/core_ext/fixtures/core_ext_dependency.rb +2 -0
- data/spec/public/core_ext/kernel_spec.rb +9 -0
- data/spec/public/core_ext/spec_helper.rb +1 -0
- data/spec/public/directory_structure/directory/log/merb_test.log +3729 -272
- data/spec/public/directory_structure/directory_spec.rb +3 -4
- data/spec/public/logger/logger_spec.rb +4 -4
- data/spec/public/reloading/directory/log/merb_test.log +288066 -15
- data/spec/public/reloading/reload_spec.rb +49 -27
- data/spec/public/request/multipart_spec.rb +26 -0
- data/spec/public/request/request_spec.rb +21 -2
- data/spec/public/router/fixation_spec.rb +27 -0
- data/spec/public/router/fixture/log/merb_test.log +30050 -0
- data/spec/public/router/nested_matches_spec.rb +97 -0
- data/spec/public/router/resource_spec.rb +1 -9
- data/spec/public/router/resources_spec.rb +0 -20
- data/spec/public/router/spec_helper.rb +27 -9
- data/spec/public/router/special_spec.rb +21 -8
- data/spec/public/template/template_spec.rb +17 -5
- data/spec/public/test/controller_matchers_spec.rb +10 -0
- data/spec/public/test/request_helper_spec.rb +29 -0
- data/spec/public/test/route_helper_spec.rb +18 -1
- data/spec/public/test/route_matchers_spec.rb +28 -1
- data/spec/public/test/view_matchers_spec.rb +3 -3
- data/spec/spec_helper.rb +56 -12
- metadata +89 -47
- data/lib/merb-core/core_ext/class.rb +0 -299
- data/lib/merb-core/core_ext/hash.rb +0 -426
- data/lib/merb-core/core_ext/mash.rb +0 -154
- data/lib/merb-core/core_ext/object.rb +0 -147
- data/lib/merb-core/core_ext/object_space.rb +0 -14
- data/lib/merb-core/core_ext/rubygems.rb +0 -28
- data/lib/merb-core/core_ext/set.rb +0 -46
- data/lib/merb-core/core_ext/string.rb +0 -89
- data/lib/merb-core/core_ext/time.rb +0 -13
- data/lib/merb-core/dispatch/exceptions.html.erb +0 -297
- data/spec/private/core_ext/class_spec.rb +0 -22
- data/spec/private/core_ext/hash_spec.rb +0 -522
- data/spec/private/core_ext/object_spec.rb +0 -121
- data/spec/private/core_ext/set_spec.rb +0 -26
- data/spec/private/core_ext/string_spec.rb +0 -167
- data/spec/private/core_ext/time_spec.rb +0 -16
- data/spec/private/dispatch/dispatch_spec.rb +0 -26
- data/spec/private/dispatch/fixture/log/development.log +0 -1
- data/spec/private/dispatch/fixture/log/merb.4000.pid +0 -1
- data/spec/private/dispatch/fixture/log/production.log +0 -1
- data/spec/private/dispatch/fixture/merb.4000.pid +0 -1
- data/spec/private/rack/application_spec.rb +0 -43
- data/spec/public/controller/log/merb.4000.pid +0 -1
- data/spec/public/directory_structure/directory/log/merb.4000.pid +0 -1
- data/spec/public/directory_structure/directory/merb.4000.pid +0 -1
- data/spec/public/reloading/directory/log/merb.4000.pid +0 -1
- data/spec/public/reloading/directory/merb.4000.pid +0 -1
@@ -1,154 +0,0 @@
|
|
1
|
-
# This class has dubious semantics and we only have it so that people can write
|
2
|
-
# params[:key] instead of params['key'].
|
3
|
-
class Mash < Hash
|
4
|
-
|
5
|
-
# ==== Parameters
|
6
|
-
# constructor<Object>::
|
7
|
-
# The default value for the mash. Defaults to an empty hash.
|
8
|
-
#
|
9
|
-
# ==== Alternatives
|
10
|
-
# If constructor is a Hash, a new mash will be created based on the keys of
|
11
|
-
# the hash and no default value will be set.
|
12
|
-
def initialize(constructor = {})
|
13
|
-
if constructor.is_a?(Hash)
|
14
|
-
super()
|
15
|
-
update(constructor)
|
16
|
-
else
|
17
|
-
super(constructor)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
# ==== Parameters
|
22
|
-
# key<Object>:: The default value for the mash. Defaults to nil.
|
23
|
-
#
|
24
|
-
# ==== Alternatives
|
25
|
-
# If key is a Symbol and it is a key in the mash, then the default value will
|
26
|
-
# be set to the value matching the key.
|
27
|
-
def default(key = nil)
|
28
|
-
if key.is_a?(Symbol) && include?(key = key.to_s)
|
29
|
-
self[key]
|
30
|
-
else
|
31
|
-
super
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
|
36
|
-
alias_method :regular_update, :update unless method_defined?(:regular_update)
|
37
|
-
|
38
|
-
# ==== Parameters
|
39
|
-
# key<Object>:: The key to set. This will be run through convert_key.
|
40
|
-
# value<Object>::
|
41
|
-
# The value to set the key to. This will be run through convert_value.
|
42
|
-
def []=(key, value)
|
43
|
-
regular_writer(convert_key(key), convert_value(value))
|
44
|
-
end
|
45
|
-
|
46
|
-
# ==== Parameters
|
47
|
-
# other_hash<Hash>::
|
48
|
-
# A hash to update values in the mash with. The keys and the values will be
|
49
|
-
# converted to Mash format.
|
50
|
-
#
|
51
|
-
# ==== Returns
|
52
|
-
# Mash:: The updated mash.
|
53
|
-
def update(other_hash)
|
54
|
-
other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
|
55
|
-
self
|
56
|
-
end
|
57
|
-
|
58
|
-
alias_method :merge!, :update
|
59
|
-
|
60
|
-
# ==== Parameters
|
61
|
-
# key<Object>:: The key to check for. This will be run through convert_key.
|
62
|
-
#
|
63
|
-
# ==== Returns
|
64
|
-
# Boolean:: True if the key exists in the mash.
|
65
|
-
def key?(key)
|
66
|
-
super(convert_key(key))
|
67
|
-
end
|
68
|
-
|
69
|
-
# def include? def has_key? def member?
|
70
|
-
alias_method :include?, :key?
|
71
|
-
alias_method :has_key?, :key?
|
72
|
-
alias_method :member?, :key?
|
73
|
-
|
74
|
-
# ==== Parameters
|
75
|
-
# key<Object>:: The key to fetch. This will be run through convert_key.
|
76
|
-
# extras:: Default value.
|
77
|
-
#
|
78
|
-
# ==== Returns
|
79
|
-
# Object:: The value at key or the default value.
|
80
|
-
def fetch(key, *extras)
|
81
|
-
super(convert_key(key), *extras)
|
82
|
-
end
|
83
|
-
|
84
|
-
# ==== Parameters
|
85
|
-
# indices<Array>::
|
86
|
-
# The keys to retrieve values for. These will be run through +convert_key+.
|
87
|
-
def values_at(*indices)
|
88
|
-
indices.collect {|key| self[convert_key(key)]}
|
89
|
-
end
|
90
|
-
|
91
|
-
# ==== Returns
|
92
|
-
# Mash:: A duplicate of this mash.
|
93
|
-
def dup
|
94
|
-
Mash.new(self)
|
95
|
-
end
|
96
|
-
|
97
|
-
# ==== Parameters
|
98
|
-
# hash<Hash>:: The hash to merge with the mash.
|
99
|
-
#
|
100
|
-
# ==== Returns
|
101
|
-
# Mash:: A new mash with the hash values merged in.
|
102
|
-
def merge(hash)
|
103
|
-
self.dup.update(hash)
|
104
|
-
end
|
105
|
-
|
106
|
-
# ==== Parameters
|
107
|
-
# key<Object>::
|
108
|
-
# The key to delete from the mash. This will be run through convert_key.
|
109
|
-
def delete(key)
|
110
|
-
super(convert_key(key))
|
111
|
-
end
|
112
|
-
|
113
|
-
# Used to provide the same interface as Hash.
|
114
|
-
#
|
115
|
-
# ==== Returns
|
116
|
-
# Mash:: This mash unchanged.
|
117
|
-
def stringify_keys!; self end
|
118
|
-
|
119
|
-
# ==== Returns
|
120
|
-
# Hash:: The mash as a Hash with string keys.
|
121
|
-
def to_hash
|
122
|
-
Hash.new(default).merge(self)
|
123
|
-
end
|
124
|
-
|
125
|
-
protected
|
126
|
-
# ==== Parameters
|
127
|
-
# key<Object>:: The key to convert.
|
128
|
-
#
|
129
|
-
# ==== Returns
|
130
|
-
# Object::
|
131
|
-
# The converted key. If the key was a symbol, it will be converted to a
|
132
|
-
# string.
|
133
|
-
def convert_key(key)
|
134
|
-
key.kind_of?(Symbol) ? key.to_s : key
|
135
|
-
end
|
136
|
-
|
137
|
-
# ==== Parameters
|
138
|
-
# value<Object>:: The value to convert.
|
139
|
-
#
|
140
|
-
# ==== Returns
|
141
|
-
# Object::
|
142
|
-
# The converted value. A Hash or an Array of hashes, will be converted to
|
143
|
-
# their Mash equivalents.
|
144
|
-
def convert_value(value)
|
145
|
-
case value
|
146
|
-
when Hash
|
147
|
-
value.to_mash
|
148
|
-
when Array
|
149
|
-
value.collect { |e| convert_value(e) }
|
150
|
-
else
|
151
|
-
value
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
@@ -1,147 +0,0 @@
|
|
1
|
-
class Object
|
2
|
-
# Extracts the singleton class, so that metaprogramming can be done on it.
|
3
|
-
#
|
4
|
-
# ==== Returns
|
5
|
-
# Class:: The meta class.
|
6
|
-
#
|
7
|
-
# ==== Examples
|
8
|
-
# class MyString < String; end
|
9
|
-
#
|
10
|
-
# MyString.instance_eval do
|
11
|
-
# define_method :foo do
|
12
|
-
# puts self
|
13
|
-
# end
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# MyString.meta_class.instance_eval do
|
17
|
-
# define_method :bar do
|
18
|
-
# puts self
|
19
|
-
# end
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
# def String.add_meta_var(var)
|
23
|
-
# self.meta_class.instance_eval do
|
24
|
-
# define_method var do
|
25
|
-
# puts "HELLO"
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
# end
|
29
|
-
#
|
30
|
-
# MyString.new("Hello").foo #=> "Hello"
|
31
|
-
# MyString.new("Hello").bar
|
32
|
-
# #=> NoMethodError: undefined method `bar' for "Hello":MyString
|
33
|
-
# MyString.foo
|
34
|
-
# #=> NoMethodError: undefined method `foo' for MyString:Class
|
35
|
-
# MyString.bar
|
36
|
-
# #=> MyString
|
37
|
-
# String.bar
|
38
|
-
# #=> NoMethodError: undefined method `bar' for String:Class
|
39
|
-
#
|
40
|
-
# MyString.add_meta_var(:x)
|
41
|
-
# MyString.x #=> HELLO
|
42
|
-
#
|
43
|
-
# As you can see, using #meta_class allows you to execute code (and here,
|
44
|
-
# define a method) on the metaclass itself. It also allows you to define
|
45
|
-
# class methods that can be run on subclasses, and then be able to execute
|
46
|
-
# code on the metaclass of the subclass (here MyString).
|
47
|
-
#
|
48
|
-
# In this case, we were able to define a class method (add_meta_var) on
|
49
|
-
# String that was executable by the MyString subclass. It was then able to
|
50
|
-
# define a method on the subclass by adding it to the MyString metaclass.
|
51
|
-
#
|
52
|
-
# For more information, you can check out _why's excellent article at:
|
53
|
-
# http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
|
54
|
-
def meta_class() class << self; self end end
|
55
|
-
|
56
|
-
# ==== Returns
|
57
|
-
# Boolean::
|
58
|
-
# True if the empty? is true or if the object responds to strip (e.g. a
|
59
|
-
# String) and strip.empty? is true, or if !self is true.
|
60
|
-
#
|
61
|
-
# ==== Examples
|
62
|
-
# [].blank? #=> true
|
63
|
-
# [1].blank? #=> false
|
64
|
-
# [nil].blank? #=> false
|
65
|
-
# nil.blank? #=> true
|
66
|
-
# true.blank? #=> false
|
67
|
-
# false.blank? #=> true
|
68
|
-
# "".blank? #=> true
|
69
|
-
# " ".blank? #=> true
|
70
|
-
# " hey ho ".blank? #=> false
|
71
|
-
def blank?
|
72
|
-
if respond_to?(:empty?) && respond_to?(:strip)
|
73
|
-
empty? or strip.empty?
|
74
|
-
elsif respond_to?(:empty?)
|
75
|
-
empty?
|
76
|
-
else
|
77
|
-
!self
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
# ==== Parameters
|
82
|
-
# name<String>:: The name of the constant to get, e.g. "Merb::Router".
|
83
|
-
#
|
84
|
-
# ==== Returns
|
85
|
-
# Object:: The constant corresponding to the name.
|
86
|
-
def full_const_get(name)
|
87
|
-
list = name.split("::")
|
88
|
-
obj = Object
|
89
|
-
list.each {|x| obj = obj.const_get(x) }
|
90
|
-
obj
|
91
|
-
end
|
92
|
-
|
93
|
-
# Defines module from a string name (e.g. Foo::Bar::Baz)
|
94
|
-
# If method already exists, no exception raised.
|
95
|
-
#
|
96
|
-
# ==== Parameters
|
97
|
-
# name<String>:: The name of the full module name to make
|
98
|
-
#
|
99
|
-
# ==== Returns
|
100
|
-
# nil
|
101
|
-
def make_module(str)
|
102
|
-
mod = str.split("::")
|
103
|
-
start = mod.map {|x| "module #{x}"}.join("; ")
|
104
|
-
ender = (["end"] * mod.size).join("; ")
|
105
|
-
self.class_eval <<-HERE
|
106
|
-
#{start}
|
107
|
-
#{ender}
|
108
|
-
HERE
|
109
|
-
end
|
110
|
-
|
111
|
-
# ==== Parameters
|
112
|
-
# duck<Symbol, Class, Array>:: The thing to compare the object to.
|
113
|
-
#
|
114
|
-
# ==== Notes
|
115
|
-
# The behavior of the method depends on the type of duck as follows:
|
116
|
-
# Symbol:: Check whether the object respond_to?(duck).
|
117
|
-
# Class:: Check whether the object is_a?(duck).
|
118
|
-
# Array::
|
119
|
-
# Check whether the object quacks_like? at least one of the options in the
|
120
|
-
# array.
|
121
|
-
#
|
122
|
-
# ==== Returns
|
123
|
-
# Boolean:: True if the object quacks like duck.
|
124
|
-
def quacks_like?(duck)
|
125
|
-
case duck
|
126
|
-
when Symbol
|
127
|
-
self.respond_to?(duck)
|
128
|
-
when Class
|
129
|
-
self.is_a?(duck)
|
130
|
-
when Array
|
131
|
-
duck.any? {|d| self.quacks_like?(d) }
|
132
|
-
else
|
133
|
-
false
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
# ==== Parameters
|
138
|
-
# arrayish<Array>:: Container to check, to see if it includes the object.
|
139
|
-
# more<Objects>:: additional args, will be flattened into arrayish
|
140
|
-
#
|
141
|
-
# ==== Returns
|
142
|
-
# Boolean: True if the object is included in arrayish (+ more)
|
143
|
-
def in?(arrayish,*more)
|
144
|
-
arrayish = more.unshift(arrayish) unless more.empty?
|
145
|
-
arrayish.include?(self)
|
146
|
-
end
|
147
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# this is a temporary workaround until rubygems Does the Right thing here
|
2
|
-
require 'rubygems'
|
3
|
-
module Gem
|
4
|
-
class SourceIndex
|
5
|
-
|
6
|
-
# Overwrite this so that a gem of the same name and version won't push one
|
7
|
-
# from the gems directory out entirely.
|
8
|
-
#
|
9
|
-
# ==== Parameters
|
10
|
-
# gem_spec<Gem::Specification>:: The specification of the gem to add.
|
11
|
-
def add_spec(gem_spec)
|
12
|
-
@gems[gem_spec.full_name] = gem_spec unless @gems[gem_spec.full_name].is_a?(Gem::Specification) && @gems[gem_spec.full_name].installation_path == File.join(defined?(Merb) && Merb.respond_to?(:root) ? Merb.root : Dir.pwd,"gems")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class Specification
|
17
|
-
|
18
|
-
# Overwrite this so that gems in the gems directory get preferred over gems
|
19
|
-
# from any other location. If there are two gems of different versions in
|
20
|
-
# the gems directory, the later one will load as usual.
|
21
|
-
#
|
22
|
-
# ==== Returns
|
23
|
-
# Array[Array]:: The object used for sorting gem specs.
|
24
|
-
def sort_obj
|
25
|
-
[@name, installation_path == File.join(defined?(Merb) && Merb.respond_to?(:root) ? Merb.root : Dir.pwd,"gems") ? 1 : -1, @version.to_ints, @new_platform == Gem::Platform::RUBY ? -1 : 1]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module Merb
|
2
|
-
# Simple set implementation
|
3
|
-
# on top of Hash with mergins support.
|
4
|
-
#
|
5
|
-
# In particular this is used to store
|
6
|
-
# a set of callable actions of controller.
|
7
|
-
class SimpleSet < Hash
|
8
|
-
|
9
|
-
# ==== Parameters
|
10
|
-
# arr<Array>:: Initial set values.
|
11
|
-
#
|
12
|
-
# ==== Returns
|
13
|
-
# Array:: The array the Set was initialized with
|
14
|
-
def initialize(arr = [])
|
15
|
-
arr.each {|x| self[x] = true}
|
16
|
-
end
|
17
|
-
|
18
|
-
# ==== Parameters
|
19
|
-
# value<Object>:: Value to add to set.
|
20
|
-
#
|
21
|
-
# ==== Returns
|
22
|
-
# true
|
23
|
-
def <<(value)
|
24
|
-
self[value] = true
|
25
|
-
end
|
26
|
-
|
27
|
-
# ==== Parameters
|
28
|
-
# arr<Array>:: Values to merge with set.
|
29
|
-
#
|
30
|
-
# ==== Returns
|
31
|
-
# SimpleSet:: The set after the Array was merged in.
|
32
|
-
def merge(arr)
|
33
|
-
super(arr.inject({}) {|s,x| s[x] = true; s })
|
34
|
-
end
|
35
|
-
|
36
|
-
# ==== Returns
|
37
|
-
# String:: A human readable version of the set.
|
38
|
-
def inspect
|
39
|
-
"#<SimpleSet: {#{keys.map {|x| x.inspect}.join(", ")}}>"
|
40
|
-
end
|
41
|
-
|
42
|
-
# def to_a
|
43
|
-
alias_method :to_a, :keys
|
44
|
-
|
45
|
-
end # SimpleSet
|
46
|
-
end # Merb
|
@@ -1,89 +0,0 @@
|
|
1
|
-
require "pathname"
|
2
|
-
|
3
|
-
class String
|
4
|
-
|
5
|
-
# ==== Returns
|
6
|
-
# String:: The string with all regexp special characters escaped.
|
7
|
-
#
|
8
|
-
# ==== Examples
|
9
|
-
# "*?{}.".escape_regexp #=> "\\*\\?\\{\\}\\."
|
10
|
-
def escape_regexp
|
11
|
-
Regexp.escape self
|
12
|
-
end
|
13
|
-
|
14
|
-
# ==== Returns
|
15
|
-
# String:: The string with all regexp special characters unescaped.
|
16
|
-
#
|
17
|
-
# ==== Examples
|
18
|
-
# "\\*\\?\\{\\}\\.".unescape_regexp #=> "*?{}."
|
19
|
-
def unescape_regexp
|
20
|
-
self.gsub(/\\([\.\?\|\(\)\[\]\{\}\^\$\*\+\-])/, '\1')
|
21
|
-
end
|
22
|
-
|
23
|
-
# ==== Returns
|
24
|
-
# String:: The string converted to snake case.
|
25
|
-
#
|
26
|
-
# ==== Examples
|
27
|
-
# "FooBar".snake_case #=> "foo_bar"
|
28
|
-
# "HeadlineCNNNews".snake_case #=> "headline_cnn_news"
|
29
|
-
# "CNN".snake_case #=> "cnn"
|
30
|
-
def snake_case
|
31
|
-
return self.downcase if self =~ /^[A-Z]+$/
|
32
|
-
self.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]/, '_\&') =~ /_*(.*)/
|
33
|
-
return $+.downcase
|
34
|
-
end
|
35
|
-
|
36
|
-
# ==== Returns
|
37
|
-
# String:: The string converted to camel case.
|
38
|
-
#
|
39
|
-
# ==== Examples
|
40
|
-
# "foo_bar".camel_case #=> "FooBar"
|
41
|
-
def camel_case
|
42
|
-
return self if self !~ /_/ && self =~ /[A-Z]+.*/
|
43
|
-
split('_').map{|e| e.capitalize}.join
|
44
|
-
end
|
45
|
-
|
46
|
-
# ==== Returns
|
47
|
-
# String:: The path string converted to a constant name.
|
48
|
-
#
|
49
|
-
# ==== Examples
|
50
|
-
# "merb/core_ext/string".to_const_string #=> "Merb::CoreExt::String"
|
51
|
-
def to_const_string
|
52
|
-
gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
53
|
-
end
|
54
|
-
|
55
|
-
# ==== Returns
|
56
|
-
# String::
|
57
|
-
# The path that is associated with the constantized string, assuming a
|
58
|
-
# conventional structure.
|
59
|
-
#
|
60
|
-
# ==== Examples
|
61
|
-
# "FooBar::Baz".to_const_path # => "foo_bar/baz"
|
62
|
-
def to_const_path
|
63
|
-
snake_case.gsub(/::/, "/")
|
64
|
-
end
|
65
|
-
|
66
|
-
# ==== Parameters
|
67
|
-
# o<String>:: The path component to join with the string.
|
68
|
-
#
|
69
|
-
# ==== Returns
|
70
|
-
# String:: The original path concatenated with o.
|
71
|
-
#
|
72
|
-
# ==== Examples
|
73
|
-
# "merb"/"core_ext" #=> "merb/core_ext"
|
74
|
-
def /(o)
|
75
|
-
File.join(self, o.to_s)
|
76
|
-
end
|
77
|
-
|
78
|
-
# ==== Parameters ====
|
79
|
-
# other<String>:: Base path to calculate against
|
80
|
-
#
|
81
|
-
# ==== Returns ====
|
82
|
-
# String:: Relative path from between the two
|
83
|
-
#
|
84
|
-
# ==== Example ====
|
85
|
-
# "/opt/local/lib".relative_path_from("/opt/local/lib/ruby/site_ruby") # => "../.."
|
86
|
-
def relative_path_from(other)
|
87
|
-
Pathname.new(self).relative_path_from(Pathname.new(other)).to_s
|
88
|
-
end
|
89
|
-
end
|