swivel 0.0.146 → 0.0.149
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -1
- data/Rakefile +1 -1
- data/lib/swivel.rb +1 -1
- data/lib/swivel2/benchmarking.rb +1 -0
- data/lib/swivel2/config.rb +45 -0
- data/lib/swivel2/connection.rb +89 -0
- data/lib/swivel2/formats.rb +11 -0
- data/lib/swivel2/logging.rb +1 -0
- data/lib/swivel2/performance.rb +21 -0
- data/lib/swivel2/response.rb +5 -0
- data/lib/swivel2/swivelrc.default +5 -0
- data/vendor/activeresource-2.0.2-/CHANGELOG +223 -0
- data/vendor/activeresource-2.0.2-/README +165 -0
- data/vendor/activeresource-2.0.2-/Rakefile +133 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource.rb +47 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/base.rb +872 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/connection.rb +172 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/custom_methods.rb +105 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/formats.rb +14 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/formats/json_format.rb +23 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/formats/xml_format.rb +34 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/http_mock.rb +147 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/validations.rb +288 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/version.rb +9 -0
- data/vendor/activeresource-2.0.2-/lib/activeresource.rb +1 -0
- data/vendor/activeresource-2.0.2-/test/abstract_unit.rb +10 -0
- data/vendor/activeresource-2.0.2-/test/authorization_test.rb +82 -0
- data/vendor/activeresource-2.0.2-/test/base/custom_methods_test.rb +96 -0
- data/vendor/activeresource-2.0.2-/test/base/equality_test.rb +43 -0
- data/vendor/activeresource-2.0.2-/test/base/load_test.rb +111 -0
- data/vendor/activeresource-2.0.2-/test/base_errors_test.rb +48 -0
- data/vendor/activeresource-2.0.2-/test/base_test.rb +454 -0
- data/vendor/activeresource-2.0.2-/test/connection_test.rb +170 -0
- data/vendor/activeresource-2.0.2-/test/fixtures/beast.rb +14 -0
- data/vendor/activeresource-2.0.2-/test/fixtures/person.rb +3 -0
- data/vendor/activeresource-2.0.2-/test/fixtures/street_address.rb +4 -0
- data/vendor/activeresource-2.0.2-/test/format_test.rb +42 -0
- data/vendor/activeresource-2.0.2-/test/setter_trap.rb +27 -0
- data/vendor/activesupport-2.0.2-/CHANGELOG +986 -0
- data/vendor/activesupport-2.0.2-/README +43 -0
- data/vendor/activesupport-2.0.2-/lib/active_support.rb +49 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/basic_object.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/buffered_logger.rb +107 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/clean_logger.rb +127 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext.rb +4 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/access.rb +28 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/conversions.rb +94 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/extract_options.rb +19 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/grouping.rb +68 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/random_access.rb +12 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/bigdecimal.rb +2 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/bigdecimal/conversions.rb +6 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/blank.rb +50 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/cgi.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +14 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class.rb +4 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/attribute_accessors.rb +48 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/delegating_attributes.rb +40 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/inheritable_attributes.rb +140 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/removal.rb +24 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date.rb +10 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date/behavior.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date/calculations.rb +188 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date/conversions.rb +98 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date_time.rb +10 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date_time/calculations.rb +77 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date_time/conversions.rb +74 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/duplicable.rb +37 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/enumerable.rb +63 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/exception.rb +33 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/file.rb +21 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/float.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/float/rounding.rb +24 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/conversions.rb +242 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/diff.rb +19 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/except.rb +24 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/indifferent_access.rb +102 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/keys.rb +54 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/reverse_merge.rb +25 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/slice.rb +28 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/integer.rb +7 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/integer/even_odd.rb +24 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/integer/inflections.rb +21 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/agnostics.rb +11 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/daemonizing.rb +15 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/debugger.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/reporting.rb +51 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/requires.rb +24 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/load_error.rb +38 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/logger.rb +16 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module.rb +8 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/aliasing.rb +70 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/attr_accessor_with_default.rb +31 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/attr_internal.rb +31 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/attribute_accessors.rb +48 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/delegation.rb +62 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/inclusion.rb +11 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/introspection.rb +35 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/loading.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/name_error.rb +17 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/numeric.rb +7 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/numeric/bytes.rb +44 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/numeric/time.rb +91 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object.rb +4 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/conversions.rb +14 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/extending.rb +58 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/instance_variables.rb +22 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/misc.rb +59 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/pathname.rb +7 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/pathname/clean_within.rb +14 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/proc.rb +12 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range.rb +11 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/blockless_step.rb +22 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/conversions.rb +23 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/include_range.rb +22 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/overlaps.rb +12 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string.rb +23 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/access.rb +58 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/conversions.rb +28 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/inflections.rb +153 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/iterators.rb +17 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/starts_ends_with.rb +27 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/unicode.rb +42 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/xchar.rb +11 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/symbol.rb +14 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/test.rb +1 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/test/unit/assertions.rb +62 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time.rb +19 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time/behavior.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time/calculations.rb +224 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time/conversions.rb +94 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/dependencies.rb +540 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/deprecation.rb +204 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/duration.rb +96 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/inflections.rb +53 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/inflector.rb +282 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json.rb +31 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/decoding.rb +60 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/date.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/date_time.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/enumerable.rb +12 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/false_class.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/hash.rb +50 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/nil_class.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/numeric.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/object.rb +6 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/regexp.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/string.rb +30 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/symbol.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/time.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/true_class.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoding.rb +38 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/variable.rb +10 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte.rb +9 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/chars.rb +141 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/generators/generate_tables.rb +149 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/handlers/passthru_handler.rb +9 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/handlers/utf8_handler.rb +564 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/handlers/utf8_handler_proc.rb +43 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/option_merger.rb +25 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/ordered_options.rb +49 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/test_case.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/testing.rb +1 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/testing/default.rb +12 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/values/time_zone.rb +181 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/values/unicode_tables.dat +0 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor.rb +14 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/blankslate.rb +113 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +20 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/css.rb +250 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +115 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +139 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +63 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +328 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb +1021 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/version.rb +9 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/whiny_nil.rb +38 -0
- data/vendor/activesupport-2.0.2-/lib/activesupport.rb +1 -0
- metadata +222 -2
@@ -0,0 +1,38 @@
|
|
1
|
+
class MissingSourceFile < LoadError #:nodoc:
|
2
|
+
attr_reader :path
|
3
|
+
def initialize(message, path)
|
4
|
+
super(message)
|
5
|
+
@path = path
|
6
|
+
end
|
7
|
+
|
8
|
+
def is_missing?(path)
|
9
|
+
path.gsub(/\.rb$/, '') == self.path.gsub(/\.rb$/, '')
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.from_message(message)
|
13
|
+
REGEXPS.each do |regexp, capture|
|
14
|
+
match = regexp.match(message)
|
15
|
+
return MissingSourceFile.new(message, match[capture]) unless match.nil?
|
16
|
+
end
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
REGEXPS = [
|
21
|
+
[/^no such file to load -- (.+)$/i, 1],
|
22
|
+
[/^Missing \w+ (file\s*)?([^\s]+.rb)$/i, 2],
|
23
|
+
[/^Missing API definition file in (.+)$/i, 1]
|
24
|
+
] unless defined?(REGEXPS)
|
25
|
+
end
|
26
|
+
|
27
|
+
module ActiveSupport #:nodoc:
|
28
|
+
module CoreExtensions #:nodoc:
|
29
|
+
module LoadErrorExtensions #:nodoc:
|
30
|
+
module LoadErrorClassMethods #:nodoc:
|
31
|
+
def new(*args)
|
32
|
+
(self == LoadError && MissingSourceFile.from_message(args.first)) || super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
::LoadError.extend(LoadErrorClassMethods)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Adds the 'around_level' method to Logger.
|
2
|
+
|
3
|
+
class Logger
|
4
|
+
def self.define_around_helper(level)
|
5
|
+
module_eval <<-end_eval
|
6
|
+
def around_#{level}(before_message, after_message, &block)
|
7
|
+
self.#{level}(before_message)
|
8
|
+
return_value = block.call(self)
|
9
|
+
self.#{level}(after_message)
|
10
|
+
return return_value
|
11
|
+
end
|
12
|
+
end_eval
|
13
|
+
end
|
14
|
+
[:debug, :info, :error, :fatal].each {|level| define_around_helper(level) }
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'active_support/core_ext/module/inclusion'
|
2
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
3
|
+
require 'active_support/core_ext/module/attr_internal'
|
4
|
+
require 'active_support/core_ext/module/attr_accessor_with_default'
|
5
|
+
require 'active_support/core_ext/module/delegation'
|
6
|
+
require 'active_support/core_ext/module/introspection'
|
7
|
+
require 'active_support/core_ext/module/loading'
|
8
|
+
require 'active_support/core_ext/module/aliasing'
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class Module
|
2
|
+
# Encapsulates the common pattern of:
|
3
|
+
#
|
4
|
+
# alias_method :foo_without_feature, :foo
|
5
|
+
# alias_method :foo, :foo_with_feature
|
6
|
+
#
|
7
|
+
# With this, you simply do:
|
8
|
+
#
|
9
|
+
# alias_method_chain :foo, :feature
|
10
|
+
#
|
11
|
+
# And both aliases are set up for you.
|
12
|
+
#
|
13
|
+
# Query and bang methods (foo?, foo!) keep the same punctuation:
|
14
|
+
#
|
15
|
+
# alias_method_chain :foo?, :feature
|
16
|
+
#
|
17
|
+
# is equivalent to
|
18
|
+
#
|
19
|
+
# alias_method :foo_without_feature?, :foo?
|
20
|
+
# alias_method :foo?, :foo_with_feature?
|
21
|
+
#
|
22
|
+
# so you can safely chain foo, foo?, and foo! with the same feature.
|
23
|
+
def alias_method_chain(target, feature)
|
24
|
+
# Strip out punctuation on predicates or bang methods since
|
25
|
+
# e.g. target?_without_feature is not a valid method name.
|
26
|
+
aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
|
27
|
+
yield(aliased_target, punctuation) if block_given?
|
28
|
+
|
29
|
+
with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}"
|
30
|
+
|
31
|
+
alias_method without_method, target
|
32
|
+
alias_method target, with_method
|
33
|
+
|
34
|
+
case
|
35
|
+
when public_method_defined?(without_method)
|
36
|
+
public target
|
37
|
+
when protected_method_defined?(without_method)
|
38
|
+
protected target
|
39
|
+
when private_method_defined?(without_method)
|
40
|
+
private target
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Allows you to make aliases for attributes, which includes
|
45
|
+
# getter, setter, and query methods.
|
46
|
+
#
|
47
|
+
# Example:
|
48
|
+
#
|
49
|
+
# class Content < ActiveRecord::Base
|
50
|
+
# # has a title attribute
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# class Email < Content
|
54
|
+
# alias_attribute :subject, :title
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
# e = Email.find(1)
|
58
|
+
# e.title # => "Superstars"
|
59
|
+
# e.subject # => "Superstars"
|
60
|
+
# e.subject? # => true
|
61
|
+
# e.subject = "Megastars"
|
62
|
+
# e.title # => "Megastars"
|
63
|
+
def alias_attribute(new_name, old_name)
|
64
|
+
module_eval <<-STR, __FILE__, __LINE__+1
|
65
|
+
def #{new_name}; self.#{old_name}; end
|
66
|
+
def #{new_name}?; self.#{old_name}?; end
|
67
|
+
def #{new_name}=(v); self.#{old_name} = v; end
|
68
|
+
STR
|
69
|
+
end
|
70
|
+
end
|
data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/attr_accessor_with_default.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
class Module
|
2
|
+
# Declare an attribute accessor with an initial default return value.
|
3
|
+
#
|
4
|
+
# To give attribute <tt>:age</tt> the initial value <tt>25</tt>:
|
5
|
+
#
|
6
|
+
# class Person
|
7
|
+
# attr_accessor_with_default :age, 25
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# some_person.age
|
11
|
+
# => 25
|
12
|
+
# some_person.age = 26
|
13
|
+
# some_person.age
|
14
|
+
# => 26
|
15
|
+
#
|
16
|
+
# To give attribute <tt>:element_name</tt> a dynamic default value, evaluated
|
17
|
+
# in scope of self:
|
18
|
+
#
|
19
|
+
# attr_accessor_with_default(:element_name) { name.underscore }
|
20
|
+
#
|
21
|
+
def attr_accessor_with_default(sym, default = nil, &block)
|
22
|
+
raise 'Default value or block required' unless !default.nil? || block
|
23
|
+
define_method(sym, block_given? ? block : Proc.new { default })
|
24
|
+
module_eval(<<-EVAL, __FILE__, __LINE__)
|
25
|
+
def #{sym}=(value)
|
26
|
+
class << self; attr_reader :#{sym} end
|
27
|
+
@#{sym} = value
|
28
|
+
end
|
29
|
+
EVAL
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Module
|
2
|
+
# Declare an attribute reader backed by an internally-named instance variable.
|
3
|
+
def attr_internal_reader(*attrs)
|
4
|
+
attrs.each do |attr|
|
5
|
+
module_eval "def #{attr}() #{attr_internal_ivar_name(attr)} end"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
# Declare an attribute writer backed by an internally-named instance variable.
|
10
|
+
def attr_internal_writer(*attrs)
|
11
|
+
attrs.each do |attr|
|
12
|
+
module_eval "def #{attr}=(v) #{attr_internal_ivar_name(attr)} = v end"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Declare attributes backed by 'internal' instance variables names.
|
17
|
+
def attr_internal_accessor(*attrs)
|
18
|
+
attr_internal_reader(*attrs)
|
19
|
+
attr_internal_writer(*attrs)
|
20
|
+
end
|
21
|
+
|
22
|
+
alias_method :attr_internal, :attr_internal_accessor
|
23
|
+
|
24
|
+
private
|
25
|
+
mattr_accessor :attr_internal_naming_format
|
26
|
+
self.attr_internal_naming_format = '@_%s'
|
27
|
+
|
28
|
+
def attr_internal_ivar_name(attr)
|
29
|
+
attr_internal_naming_format % attr
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Extends the module object with module and instance accessors for class attributes,
|
2
|
+
# just like the native attr* accessors for instance attributes.
|
3
|
+
class Module # :nodoc:
|
4
|
+
def mattr_reader(*syms)
|
5
|
+
syms.each do |sym|
|
6
|
+
next if sym.is_a?(Hash)
|
7
|
+
class_eval(<<-EOS, __FILE__, __LINE__)
|
8
|
+
unless defined? @@#{sym}
|
9
|
+
@@#{sym} = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.#{sym}
|
13
|
+
@@#{sym}
|
14
|
+
end
|
15
|
+
|
16
|
+
def #{sym}
|
17
|
+
@@#{sym}
|
18
|
+
end
|
19
|
+
EOS
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def mattr_writer(*syms)
|
24
|
+
options = syms.extract_options!
|
25
|
+
syms.each do |sym|
|
26
|
+
class_eval(<<-EOS, __FILE__, __LINE__)
|
27
|
+
unless defined? @@#{sym}
|
28
|
+
@@#{sym} = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.#{sym}=(obj)
|
32
|
+
@@#{sym} = obj
|
33
|
+
end
|
34
|
+
|
35
|
+
#{"
|
36
|
+
def #{sym}=(obj)
|
37
|
+
@@#{sym} = obj
|
38
|
+
end
|
39
|
+
" unless options[:instance_writer] == false }
|
40
|
+
EOS
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def mattr_accessor(*syms)
|
45
|
+
mattr_reader(*syms)
|
46
|
+
mattr_writer(*syms)
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class Module
|
2
|
+
# Provides a delegate class method to easily expose contained objects' methods
|
3
|
+
# as your own. Pass one or more methods (specified as symbols or strings)
|
4
|
+
# and the name of the target object as the final :to option (also a symbol
|
5
|
+
# or string). At least one method and the :to option are required.
|
6
|
+
#
|
7
|
+
# Delegation is particularly useful with Active Record associations:
|
8
|
+
#
|
9
|
+
# class Greeter < ActiveRecord::Base
|
10
|
+
# def hello() "hello" end
|
11
|
+
# def goodbye() "goodbye" end
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# class Foo < ActiveRecord::Base
|
15
|
+
# belongs_to :greeter
|
16
|
+
# delegate :hello, :to => :greeter
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# Foo.new.hello # => "hello"
|
20
|
+
# Foo.new.goodbye # => NoMethodError: undefined method `goodbye' for #<Foo:0x1af30c>
|
21
|
+
#
|
22
|
+
# Multiple delegates to the same target are allowed:
|
23
|
+
# class Foo < ActiveRecord::Base
|
24
|
+
# belongs_to :greeter
|
25
|
+
# delegate :hello, :goodbye, :to => :greeter
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# Foo.new.goodbye # => "goodbye"
|
29
|
+
#
|
30
|
+
# Methods can be delegated to instance variables, class variables, or constants
|
31
|
+
# by providing the variable as a symbol:
|
32
|
+
# class Foo
|
33
|
+
# CONSTANT_ARRAY = [0,1,2,3]
|
34
|
+
# @@class_array = [4,5,6,7]
|
35
|
+
#
|
36
|
+
# def initialize
|
37
|
+
# @instance_array = [8,9,10,11]
|
38
|
+
# end
|
39
|
+
# delegate :sum, :to => :CONSTANT_ARRAY
|
40
|
+
# delegate :min, :to => :@@class_array
|
41
|
+
# delegate :max, :to => :@instance_array
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# Foo.new.sum # => 6
|
45
|
+
# Foo.new.min # => 4
|
46
|
+
# Foo.new.max # => 11
|
47
|
+
#
|
48
|
+
def delegate(*methods)
|
49
|
+
options = methods.pop
|
50
|
+
unless options.is_a?(Hash) && to = options[:to]
|
51
|
+
raise ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter)."
|
52
|
+
end
|
53
|
+
|
54
|
+
methods.each do |method|
|
55
|
+
module_eval(<<-EOS, "(__DELEGATION__)", 1)
|
56
|
+
def #{method}(*args, &block)
|
57
|
+
#{to}.__send__(#{method.inspect}, *args, &block)
|
58
|
+
end
|
59
|
+
EOS
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Module
|
2
|
+
def included_in_classes
|
3
|
+
classes = []
|
4
|
+
ObjectSpace.each_object(Class) { |k| classes << k if k.included_modules.include?(self) }
|
5
|
+
|
6
|
+
classes.reverse.inject([]) do |unique_classes, klass|
|
7
|
+
unique_classes << klass unless unique_classes.collect { |k| k.to_s }.include?(klass.to_s)
|
8
|
+
unique_classes
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Module
|
2
|
+
# Return the module which contains this one; if this is a root module, such as
|
3
|
+
# +::MyModule+, then Object is returned.
|
4
|
+
def parent
|
5
|
+
parent_name = name.split('::')[0..-2] * '::'
|
6
|
+
parent_name.empty? ? Object : parent_name.constantize
|
7
|
+
end
|
8
|
+
|
9
|
+
# Return all the parents of this module, ordered from nested outwards. The
|
10
|
+
# receiver is not contained within the result.
|
11
|
+
def parents
|
12
|
+
parents = []
|
13
|
+
parts = name.split('::')[0..-2]
|
14
|
+
until parts.empty?
|
15
|
+
parents << (parts * '::').constantize
|
16
|
+
parts.pop
|
17
|
+
end
|
18
|
+
parents << Object unless parents.include? Object
|
19
|
+
parents
|
20
|
+
end
|
21
|
+
|
22
|
+
# Return the constants that have been defined locally by this object and not
|
23
|
+
# in an ancestor. This method may miss some constants if their definition in
|
24
|
+
# the ancestor is identical to their definition in the receiver.
|
25
|
+
def local_constants
|
26
|
+
inherited = {}
|
27
|
+
ancestors.each do |anc|
|
28
|
+
next if anc == self
|
29
|
+
anc.constants.each { |const| inherited[const] = anc.const_get(const) }
|
30
|
+
end
|
31
|
+
constants.select do |const|
|
32
|
+
! inherited.key?(const) || inherited[const].object_id != const_get(const).object_id
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Add a +missing_name+ method to NameError instances.
|
2
|
+
class NameError #:nodoc:
|
3
|
+
# Add a method to obtain the missing name from a NameError.
|
4
|
+
def missing_name
|
5
|
+
$1 if /((::)?([A-Z]\w*)(::[A-Z]\w*)*)$/ =~ message
|
6
|
+
end
|
7
|
+
|
8
|
+
# Was this exception raised because the given name was missing?
|
9
|
+
def missing_name?(name)
|
10
|
+
if name.is_a? Symbol
|
11
|
+
last_name = (missing_name || '').split('::').last
|
12
|
+
last_name == name.to_s
|
13
|
+
else
|
14
|
+
missing_name == name.to_s
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module ActiveSupport #:nodoc:
|
2
|
+
module CoreExtensions #:nodoc:
|
3
|
+
module Numeric #:nodoc:
|
4
|
+
# Enables the use of byte calculations and declarations, like 45.bytes + 2.6.megabytes
|
5
|
+
module Bytes
|
6
|
+
def bytes
|
7
|
+
self
|
8
|
+
end
|
9
|
+
alias :byte :bytes
|
10
|
+
|
11
|
+
def kilobytes
|
12
|
+
self * 1024
|
13
|
+
end
|
14
|
+
alias :kilobyte :kilobytes
|
15
|
+
|
16
|
+
def megabytes
|
17
|
+
self * 1024.kilobytes
|
18
|
+
end
|
19
|
+
alias :megabyte :megabytes
|
20
|
+
|
21
|
+
def gigabytes
|
22
|
+
self * 1024.megabytes
|
23
|
+
end
|
24
|
+
alias :gigabyte :gigabytes
|
25
|
+
|
26
|
+
def terabytes
|
27
|
+
self * 1024.gigabytes
|
28
|
+
end
|
29
|
+
alias :terabyte :terabytes
|
30
|
+
|
31
|
+
def petabytes
|
32
|
+
self * 1024.terabytes
|
33
|
+
end
|
34
|
+
alias :petabyte :petabytes
|
35
|
+
|
36
|
+
def exabytes
|
37
|
+
self * 1024.petabytes
|
38
|
+
end
|
39
|
+
alias :exabyte :exabytes
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|