csd 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +1 -2
- data/README.rdoc +7 -1
- data/Rakefile +7 -2
- data/VERSION +1 -1
- data/csd.gemspec +18 -216
- data/lib/csd.rb +6 -16
- data/lib/csd/application.rb +2 -2
- data/lib/csd/application/default.rb +15 -14
- data/lib/csd/application/default/base.rb +1 -1
- data/lib/csd/application/minisip.rb +43 -11
- data/lib/csd/application/minisip/about.yml +5 -5
- data/lib/csd/application/minisip/base.rb +82 -70
- data/lib/csd/application/minisip/error.rb +1 -1
- data/lib/csd/application/minisip/options/common.rb +1 -1
- data/lib/csd/application/minisip/options/compile.rb +1 -1
- data/lib/csd/application/minisip/options/package.rb +1 -1
- data/lib/csd/application/minisip/unix.rb +40 -27
- data/lib/csd/application/minisip/unix/darwin.rb +12 -0
- data/lib/csd/application/minisip/unix/linux.rb +1 -11
- data/lib/csd/application/minisip/unix/linux/debian.rb +14 -25
- data/lib/csd/application/minisip/unix/linux/debian/ubuntu10.rb +12 -13
- data/lib/csd/applications.rb +5 -5
- data/lib/csd/commands.rb +164 -89
- data/lib/csd/container.rb +61 -0
- data/lib/csd/error.rb +10 -1
- data/lib/csd/extensions.rb +3 -2
- data/lib/csd/extensions/core/array.rb +29 -1
- data/lib/csd/extensions/core/dir.rb +15 -24
- data/lib/csd/extensions/core/object.rb +10 -2
- data/lib/csd/extensions/core/option_parser.rb +22 -3
- data/lib/csd/extensions/core/pathname.rb +30 -2
- data/lib/csd/extensions/core/string.rb +51 -4
- data/lib/csd/extensions/gem/platform.rb +18 -3
- data/lib/csd/{options.rb → options_parser.rb} +16 -20
- data/lib/csd/path_container.rb +24 -0
- data/lib/csd/user_interface.rb +2 -0
- data/lib/csd/user_interface/base.rb +26 -0
- data/lib/csd/user_interface/cli.rb +37 -0
- data/lib/csd/vendor/active_support/MIT-LICENSE +20 -0
- data/lib/csd/vendor/active_support/inflector.rb +155 -0
- data/lib/csd/vendor/term/GPL2-LICENSE +339 -0
- data/lib/csd/vendor/term/ansicolor.rb +113 -0
- data/lib/csd/version.rb +13 -4
- data/test/application/test_minisip.rb +45 -0
- data/test/functional/test_applications.rb +10 -16
- data/test/functional/test_commands.rb +260 -23
- data/test/unit/test_string.rb +1 -1
- metadata +18 -216
- data/lib/active_support.rb +0 -75
- data/lib/active_support/all.rb +0 -3
- data/lib/active_support/backtrace_cleaner.rb +0 -94
- data/lib/active_support/base64.rb +0 -42
- data/lib/active_support/basic_object.rb +0 -21
- data/lib/active_support/benchmarkable.rb +0 -60
- data/lib/active_support/buffered_logger.rb +0 -132
- data/lib/active_support/builder.rb +0 -6
- data/lib/active_support/cache.rb +0 -626
- data/lib/active_support/cache/compressed_mem_cache_store.rb +0 -13
- data/lib/active_support/cache/file_store.rb +0 -188
- data/lib/active_support/cache/mem_cache_store.rb +0 -191
- data/lib/active_support/cache/memory_store.rb +0 -159
- data/lib/active_support/cache/strategy/local_cache.rb +0 -164
- data/lib/active_support/cache/synchronized_memory_store.rb +0 -11
- data/lib/active_support/callbacks.rb +0 -600
- data/lib/active_support/concern.rb +0 -29
- data/lib/active_support/configurable.rb +0 -36
- data/lib/active_support/core_ext.rb +0 -3
- data/lib/active_support/core_ext/array.rb +0 -7
- data/lib/active_support/core_ext/array/access.rb +0 -46
- data/lib/active_support/core_ext/array/conversions.rb +0 -164
- data/lib/active_support/core_ext/array/extract_options.rb +0 -29
- data/lib/active_support/core_ext/array/grouping.rb +0 -100
- data/lib/active_support/core_ext/array/random_access.rb +0 -20
- data/lib/active_support/core_ext/array/uniq_by.rb +0 -17
- data/lib/active_support/core_ext/array/wrap.rb +0 -22
- data/lib/active_support/core_ext/benchmark.rb +0 -7
- data/lib/active_support/core_ext/big_decimal.rb +0 -1
- data/lib/active_support/core_ext/big_decimal/conversions.rb +0 -27
- data/lib/active_support/core_ext/cgi.rb +0 -1
- data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +0 -19
- data/lib/active_support/core_ext/class.rb +0 -4
- data/lib/active_support/core_ext/class/attribute.rb +0 -67
- data/lib/active_support/core_ext/class/attribute_accessors.rb +0 -63
- data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -44
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +0 -232
- data/lib/active_support/core_ext/class/subclasses.rb +0 -55
- data/lib/active_support/core_ext/date/acts_like.rb +0 -8
- data/lib/active_support/core_ext/date/calculations.rb +0 -240
- data/lib/active_support/core_ext/date/conversions.rb +0 -99
- data/lib/active_support/core_ext/date/freeze.rb +0 -31
- data/lib/active_support/core_ext/date_time/acts_like.rb +0 -13
- data/lib/active_support/core_ext/date_time/calculations.rb +0 -113
- data/lib/active_support/core_ext/date_time/conversions.rb +0 -102
- data/lib/active_support/core_ext/date_time/zones.rb +0 -17
- data/lib/active_support/core_ext/enumerable.rb +0 -119
- data/lib/active_support/core_ext/exception.rb +0 -3
- data/lib/active_support/core_ext/file.rb +0 -2
- data/lib/active_support/core_ext/file/atomic.rb +0 -41
- data/lib/active_support/core_ext/file/path.rb +0 -5
- data/lib/active_support/core_ext/float.rb +0 -1
- data/lib/active_support/core_ext/float/rounding.rb +0 -19
- data/lib/active_support/core_ext/hash.rb +0 -8
- data/lib/active_support/core_ext/hash/conversions.rb +0 -150
- data/lib/active_support/core_ext/hash/deep_merge.rb +0 -16
- data/lib/active_support/core_ext/hash/diff.rb +0 -13
- data/lib/active_support/core_ext/hash/except.rb +0 -24
- data/lib/active_support/core_ext/hash/indifferent_access.rb +0 -14
- data/lib/active_support/core_ext/hash/keys.rb +0 -45
- data/lib/active_support/core_ext/hash/reverse_merge.rb +0 -28
- data/lib/active_support/core_ext/hash/slice.rb +0 -38
- data/lib/active_support/core_ext/integer.rb +0 -3
- data/lib/active_support/core_ext/integer/inflections.rb +0 -14
- data/lib/active_support/core_ext/integer/multiple.rb +0 -6
- data/lib/active_support/core_ext/integer/time.rb +0 -39
- data/lib/active_support/core_ext/kernel.rb +0 -5
- data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
- data/lib/active_support/core_ext/kernel/debugger.rb +0 -16
- data/lib/active_support/core_ext/kernel/reporting.rb +0 -62
- data/lib/active_support/core_ext/kernel/requires.rb +0 -26
- data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -13
- data/lib/active_support/core_ext/load_error.rb +0 -23
- data/lib/active_support/core_ext/logger.rb +0 -146
- data/lib/active_support/core_ext/module.rb +0 -12
- data/lib/active_support/core_ext/module/aliasing.rb +0 -70
- data/lib/active_support/core_ext/module/anonymous.rb +0 -24
- data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +0 -31
- data/lib/active_support/core_ext/module/attr_internal.rb +0 -32
- data/lib/active_support/core_ext/module/attribute_accessors.rb +0 -66
- data/lib/active_support/core_ext/module/delegation.rb +0 -146
- data/lib/active_support/core_ext/module/deprecation.rb +0 -9
- data/lib/active_support/core_ext/module/introspection.rb +0 -88
- data/lib/active_support/core_ext/module/method_names.rb +0 -14
- data/lib/active_support/core_ext/module/reachable.rb +0 -10
- data/lib/active_support/core_ext/module/remove_method.rb +0 -6
- data/lib/active_support/core_ext/module/synchronization.rb +0 -42
- data/lib/active_support/core_ext/name_error.rb +0 -18
- data/lib/active_support/core_ext/numeric.rb +0 -2
- data/lib/active_support/core_ext/numeric/bytes.rb +0 -44
- data/lib/active_support/core_ext/numeric/time.rb +0 -77
- data/lib/active_support/core_ext/object.rb +0 -14
- data/lib/active_support/core_ext/object/acts_like.rb +0 -10
- data/lib/active_support/core_ext/object/blank.rb +0 -76
- data/lib/active_support/core_ext/object/conversions.rb +0 -4
- data/lib/active_support/core_ext/object/duplicable.rb +0 -65
- data/lib/active_support/core_ext/object/extending.rb +0 -11
- data/lib/active_support/core_ext/object/instance_variables.rb +0 -67
- data/lib/active_support/core_ext/object/misc.rb +0 -2
- data/lib/active_support/core_ext/object/returning.rb +0 -42
- data/lib/active_support/core_ext/object/to_param.rb +0 -49
- data/lib/active_support/core_ext/object/to_query.rb +0 -27
- data/lib/active_support/core_ext/object/try.rb +0 -36
- data/lib/active_support/core_ext/object/with_options.rb +0 -26
- data/lib/active_support/core_ext/proc.rb +0 -14
- data/lib/active_support/core_ext/process.rb +0 -1
- data/lib/active_support/core_ext/process/daemon.rb +0 -23
- data/lib/active_support/core_ext/range.rb +0 -4
- data/lib/active_support/core_ext/range/blockless_step.rb +0 -29
- data/lib/active_support/core_ext/range/conversions.rb +0 -21
- data/lib/active_support/core_ext/range/include_range.rb +0 -21
- data/lib/active_support/core_ext/range/overlaps.rb +0 -8
- data/lib/active_support/core_ext/regexp.rb +0 -5
- data/lib/active_support/core_ext/rexml.rb +0 -46
- data/lib/active_support/core_ext/string.rb +0 -12
- data/lib/active_support/core_ext/string/access.rb +0 -99
- data/lib/active_support/core_ext/string/behavior.rb +0 -7
- data/lib/active_support/core_ext/string/conversions.rb +0 -61
- data/lib/active_support/core_ext/string/encoding.rb +0 -11
- data/lib/active_support/core_ext/string/exclude.rb +0 -6
- data/lib/active_support/core_ext/string/filters.rb +0 -49
- data/lib/active_support/core_ext/string/inflections.rb +0 -149
- data/lib/active_support/core_ext/string/interpolation.rb +0 -2
- data/lib/active_support/core_ext/string/multibyte.rb +0 -72
- data/lib/active_support/core_ext/string/output_safety.rb +0 -109
- data/lib/active_support/core_ext/string/starts_ends_with.rb +0 -4
- data/lib/active_support/core_ext/string/xchar.rb +0 -18
- data/lib/active_support/core_ext/time/acts_like.rb +0 -8
- data/lib/active_support/core_ext/time/calculations.rb +0 -282
- data/lib/active_support/core_ext/time/conversions.rb +0 -85
- data/lib/active_support/core_ext/time/marshal.rb +0 -56
- data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +0 -10
- data/lib/active_support/core_ext/time/zones.rb +0 -78
- data/lib/active_support/core_ext/uri.rb +0 -22
- data/lib/active_support/dependencies.rb +0 -628
- data/lib/active_support/dependencies/autoload.rb +0 -50
- data/lib/active_support/deprecation.rb +0 -18
- data/lib/active_support/deprecation/behaviors.rb +0 -38
- data/lib/active_support/deprecation/method_wrappers.rb +0 -29
- data/lib/active_support/deprecation/proxy_wrappers.rb +0 -74
- data/lib/active_support/deprecation/reporting.rb +0 -56
- data/lib/active_support/duration.rb +0 -105
- data/lib/active_support/gzip.rb +0 -25
- data/lib/active_support/hash_with_indifferent_access.rb +0 -145
- data/lib/active_support/i18n.rb +0 -8
- data/lib/active_support/inflections.rb +0 -56
- data/lib/active_support/inflector.rb +0 -7
- data/lib/active_support/inflector/inflections.rb +0 -211
- data/lib/active_support/inflector/methods.rb +0 -141
- data/lib/active_support/inflector/transliterate.rb +0 -97
- data/lib/active_support/json.rb +0 -2
- data/lib/active_support/json/backends/jsongem.rb +0 -43
- data/lib/active_support/json/backends/yajl.rb +0 -40
- data/lib/active_support/json/backends/yaml.rb +0 -90
- data/lib/active_support/json/decoding.rb +0 -51
- data/lib/active_support/json/encoding.rb +0 -254
- data/lib/active_support/json/variable.rb +0 -11
- data/lib/active_support/lazy_load_hooks.rb +0 -27
- data/lib/active_support/locale/en.yml +0 -36
- data/lib/active_support/memoizable.rb +0 -103
- data/lib/active_support/message_encryptor.rb +0 -71
- data/lib/active_support/message_verifier.rb +0 -62
- data/lib/active_support/multibyte.rb +0 -44
- data/lib/active_support/multibyte/chars.rb +0 -480
- data/lib/active_support/multibyte/exceptions.rb +0 -8
- data/lib/active_support/multibyte/unicode.rb +0 -393
- data/lib/active_support/multibyte/utils.rb +0 -60
- data/lib/active_support/notifications.rb +0 -81
- data/lib/active_support/notifications/fanout.rb +0 -93
- data/lib/active_support/notifications/instrumenter.rb +0 -56
- data/lib/active_support/option_merger.rb +0 -25
- data/lib/active_support/ordered_hash.rb +0 -158
- data/lib/active_support/ordered_options.rb +0 -27
- data/lib/active_support/railtie.rb +0 -100
- data/lib/active_support/rescuable.rb +0 -114
- data/lib/active_support/ruby/shim.rb +0 -22
- data/lib/active_support/secure_random.rb +0 -199
- data/lib/active_support/string_inquirer.rb +0 -21
- data/lib/active_support/test_case.rb +0 -42
- data/lib/active_support/testing/assertions.rb +0 -82
- data/lib/active_support/testing/declarative.rb +0 -40
- data/lib/active_support/testing/default.rb +0 -9
- data/lib/active_support/testing/deprecation.rb +0 -55
- data/lib/active_support/testing/isolation.rb +0 -154
- data/lib/active_support/testing/pending.rb +0 -48
- data/lib/active_support/testing/performance.rb +0 -455
- data/lib/active_support/testing/setup_and_teardown.rb +0 -111
- data/lib/active_support/time.rb +0 -34
- data/lib/active_support/time/autoload.rb +0 -5
- data/lib/active_support/time_with_zone.rb +0 -341
- data/lib/active_support/values/time_zone.rb +0 -377
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +0 -10
- data/lib/active_support/whiny_nil.rb +0 -60
- data/lib/active_support/xml_mini.rb +0 -158
- data/lib/active_support/xml_mini/jdom.rb +0 -168
- data/lib/active_support/xml_mini/libxml.rb +0 -80
- data/lib/active_support/xml_mini/libxmlsax.rb +0 -85
- data/lib/active_support/xml_mini/nokogiri.rb +0 -78
- data/lib/active_support/xml_mini/nokogirisax.rb +0 -83
- data/lib/active_support/xml_mini/rexml.rb +0 -129
- data/lib/csd/extensions/core/file.rb +0 -14
- data/lib/csd/global_open_struct.rb +0 -19
- data/lib/csd/path.rb +0 -32
- data/lib/csd/ui.rb +0 -2
- data/lib/csd/ui/cli.rb +0 -8
- data/lib/csd/ui/ui.rb +0 -45
- data/lib/term/ansicolor.rb +0 -102
- data/lib/term/ansicolor/.keep +0 -0
- data/lib/term/ansicolor/version.rb +0 -10
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/module/aliasing'
|
2
|
-
require 'active_support/core_ext/module/introspection'
|
3
|
-
require 'active_support/core_ext/module/anonymous'
|
4
|
-
require 'active_support/core_ext/module/reachable'
|
5
|
-
require 'active_support/core_ext/module/attribute_accessors'
|
6
|
-
require 'active_support/core_ext/module/attr_internal'
|
7
|
-
require 'active_support/core_ext/module/attr_accessor_with_default'
|
8
|
-
require 'active_support/core_ext/module/delegation'
|
9
|
-
require 'active_support/core_ext/module/synchronization'
|
10
|
-
require 'active_support/core_ext/module/deprecation'
|
11
|
-
require 'active_support/core_ext/module/remove_method'
|
12
|
-
require 'active_support/core_ext/module/method_names'
|
@@ -1,70 +0,0 @@
|
|
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 # def subject; self.title; end
|
66
|
-
def #{new_name}?; self.#{old_name}?; end # def subject?; self.title?; end
|
67
|
-
def #{new_name}=(v); self.#{old_name} = v; end # def subject=(v); self.title = v; end
|
68
|
-
STR
|
69
|
-
end
|
70
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/object/blank'
|
2
|
-
|
3
|
-
class Module
|
4
|
-
# A module may or may not have a name.
|
5
|
-
#
|
6
|
-
# module M; end
|
7
|
-
# M.name # => "M"
|
8
|
-
#
|
9
|
-
# m = Module.new
|
10
|
-
# m.name # => ""
|
11
|
-
#
|
12
|
-
# A module gets a name when it is first assigned to a constant. Either
|
13
|
-
# via the +module+ or +class+ keyword or by an explicit assignment:
|
14
|
-
#
|
15
|
-
# m = Module.new # creates an anonymous module
|
16
|
-
# M = m # => m gets a name here as a side-effect
|
17
|
-
# m.name # => "M"
|
18
|
-
#
|
19
|
-
def anonymous?
|
20
|
-
# Uses blank? because the name of an anonymous class is an empty
|
21
|
-
# string in 1.8, and nil in 1.9.
|
22
|
-
name.blank?
|
23
|
-
end
|
24
|
-
end
|
@@ -1,31 +0,0 @@
|
|
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__ + 1)
|
25
|
-
def #{sym}=(value) # def age=(value)
|
26
|
-
class << self; attr_reader :#{sym} end # class << self; attr_reader :age end
|
27
|
-
@#{sym} = value # @age = value
|
28
|
-
end # end
|
29
|
-
EVAL
|
30
|
-
end
|
31
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
class Module
|
2
|
-
# Declares 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", __FILE__, __LINE__
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
# Declares 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", __FILE__, __LINE__
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# Declares an attribute reader and writer backed by an internally-named instance
|
17
|
-
# variable.
|
18
|
-
def attr_internal_accessor(*attrs)
|
19
|
-
attr_internal_reader(*attrs)
|
20
|
-
attr_internal_writer(*attrs)
|
21
|
-
end
|
22
|
-
|
23
|
-
alias_method :attr_internal, :attr_internal_accessor
|
24
|
-
|
25
|
-
class << self; attr_accessor :attr_internal_naming_format end
|
26
|
-
self.attr_internal_naming_format = '@_%s'
|
27
|
-
|
28
|
-
private
|
29
|
-
def attr_internal_ivar_name(attr)
|
30
|
-
Module.attr_internal_naming_format % attr
|
31
|
-
end
|
32
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/array/extract_options'
|
2
|
-
|
3
|
-
class Module
|
4
|
-
def mattr_reader(*syms)
|
5
|
-
options = syms.extract_options!
|
6
|
-
syms.each do |sym|
|
7
|
-
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
8
|
-
unless defined? @@#{sym}
|
9
|
-
@@#{sym} = nil
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.#{sym}
|
13
|
-
@@#{sym}
|
14
|
-
end
|
15
|
-
EOS
|
16
|
-
|
17
|
-
unless options[:instance_reader] == false
|
18
|
-
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
19
|
-
def #{sym}
|
20
|
-
@@#{sym}
|
21
|
-
end
|
22
|
-
EOS
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def mattr_writer(*syms)
|
28
|
-
options = syms.extract_options!
|
29
|
-
syms.each do |sym|
|
30
|
-
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
31
|
-
unless defined? @@#{sym}
|
32
|
-
@@#{sym} = nil
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.#{sym}=(obj)
|
36
|
-
@@#{sym} = obj
|
37
|
-
end
|
38
|
-
EOS
|
39
|
-
|
40
|
-
unless options[:instance_writer] == false
|
41
|
-
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
42
|
-
def #{sym}=(obj)
|
43
|
-
@@#{sym} = obj
|
44
|
-
end
|
45
|
-
EOS
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# Extends the module object with module and instance accessors for class attributes,
|
51
|
-
# just like the native attr* accessors for instance attributes.
|
52
|
-
#
|
53
|
-
# module AppConfiguration
|
54
|
-
# mattr_accessor :google_api_key
|
55
|
-
# self.google_api_key = "123456789"
|
56
|
-
#
|
57
|
-
# mattr_accessor :paypal_url
|
58
|
-
# self.paypal_url = "www.sandbox.paypal.com"
|
59
|
-
# end
|
60
|
-
#
|
61
|
-
# AppConfiguration.google_api_key = "overriding the api key!"
|
62
|
-
def mattr_accessor(*syms)
|
63
|
-
mattr_reader(*syms)
|
64
|
-
mattr_writer(*syms)
|
65
|
-
end
|
66
|
-
end
|
@@ -1,146 +0,0 @@
|
|
1
|
-
require "active_support/core_ext/module/remove_method"
|
2
|
-
|
3
|
-
class Module
|
4
|
-
# Provides a delegate class method to easily expose contained objects' methods
|
5
|
-
# as your own. Pass one or more methods (specified as symbols or strings)
|
6
|
-
# and the name of the target object via the <tt>:to</tt> option (also a symbol
|
7
|
-
# or string). At least one method and the <tt>:to</tt> option are required.
|
8
|
-
#
|
9
|
-
# Delegation is particularly useful with Active Record associations:
|
10
|
-
#
|
11
|
-
# class Greeter < ActiveRecord::Base
|
12
|
-
# def hello
|
13
|
-
# "hello"
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# def goodbye
|
17
|
-
# "goodbye"
|
18
|
-
# end
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# class Foo < ActiveRecord::Base
|
22
|
-
# belongs_to :greeter
|
23
|
-
# delegate :hello, :to => :greeter
|
24
|
-
# end
|
25
|
-
#
|
26
|
-
# Foo.new.hello # => "hello"
|
27
|
-
# Foo.new.goodbye # => NoMethodError: undefined method `goodbye' for #<Foo:0x1af30c>
|
28
|
-
#
|
29
|
-
# Multiple delegates to the same target are allowed:
|
30
|
-
#
|
31
|
-
# class Foo < ActiveRecord::Base
|
32
|
-
# belongs_to :greeter
|
33
|
-
# delegate :hello, :goodbye, :to => :greeter
|
34
|
-
# end
|
35
|
-
#
|
36
|
-
# Foo.new.goodbye # => "goodbye"
|
37
|
-
#
|
38
|
-
# Methods can be delegated to instance variables, class variables, or constants
|
39
|
-
# by providing them as a symbols:
|
40
|
-
#
|
41
|
-
# class Foo
|
42
|
-
# CONSTANT_ARRAY = [0,1,2,3]
|
43
|
-
# @@class_array = [4,5,6,7]
|
44
|
-
#
|
45
|
-
# def initialize
|
46
|
-
# @instance_array = [8,9,10,11]
|
47
|
-
# end
|
48
|
-
# delegate :sum, :to => :CONSTANT_ARRAY
|
49
|
-
# delegate :min, :to => :@@class_array
|
50
|
-
# delegate :max, :to => :@instance_array
|
51
|
-
# end
|
52
|
-
#
|
53
|
-
# Foo.new.sum # => 6
|
54
|
-
# Foo.new.min # => 4
|
55
|
-
# Foo.new.max # => 11
|
56
|
-
#
|
57
|
-
# Delegates can optionally be prefixed using the <tt>:prefix</tt> option. If the value
|
58
|
-
# is <tt>true</tt>, the delegate methods are prefixed with the name of the object being
|
59
|
-
# delegated to.
|
60
|
-
#
|
61
|
-
# Person = Struct.new(:name, :address)
|
62
|
-
#
|
63
|
-
# class Invoice < Struct.new(:client)
|
64
|
-
# delegate :name, :address, :to => :client, :prefix => true
|
65
|
-
# end
|
66
|
-
#
|
67
|
-
# john_doe = Person.new("John Doe", "Vimmersvej 13")
|
68
|
-
# invoice = Invoice.new(john_doe)
|
69
|
-
# invoice.client_name # => "John Doe"
|
70
|
-
# invoice.client_address # => "Vimmersvej 13"
|
71
|
-
#
|
72
|
-
# It is also possible to supply a custom prefix.
|
73
|
-
#
|
74
|
-
# class Invoice < Struct.new(:client)
|
75
|
-
# delegate :name, :address, :to => :client, :prefix => :customer
|
76
|
-
# end
|
77
|
-
#
|
78
|
-
# invoice = Invoice.new(john_doe)
|
79
|
-
# invoice.customer_name # => "John Doe"
|
80
|
-
# invoice.customer_address # => "Vimmersvej 13"
|
81
|
-
#
|
82
|
-
# If the delegate object is +nil+ an exception is raised, and that happens
|
83
|
-
# no matter whether +nil+ responds to the delegated method. You can get a
|
84
|
-
# +nil+ instead with the +:allow_nil+ option.
|
85
|
-
#
|
86
|
-
# class Foo
|
87
|
-
# attr_accessor :bar
|
88
|
-
# def initialize(bar = nil)
|
89
|
-
# @bar = bar
|
90
|
-
# end
|
91
|
-
# delegate :zoo, :to => :bar
|
92
|
-
# end
|
93
|
-
#
|
94
|
-
# Foo.new.zoo # raises NoMethodError exception (you called nil.zoo)
|
95
|
-
#
|
96
|
-
# class Foo
|
97
|
-
# attr_accessor :bar
|
98
|
-
# def initialize(bar = nil)
|
99
|
-
# @bar = bar
|
100
|
-
# end
|
101
|
-
# delegate :zoo, :to => :bar, :allow_nil => true
|
102
|
-
# end
|
103
|
-
#
|
104
|
-
# Foo.new.zoo # returns nil
|
105
|
-
#
|
106
|
-
def delegate(*methods)
|
107
|
-
options = methods.pop
|
108
|
-
unless options.is_a?(Hash) && to = options[:to]
|
109
|
-
raise ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter)."
|
110
|
-
end
|
111
|
-
|
112
|
-
if options[:prefix] == true && options[:to].to_s =~ /^[^a-z_]/
|
113
|
-
raise ArgumentError, "Can only automatically set the delegation prefix when delegating to a method."
|
114
|
-
end
|
115
|
-
|
116
|
-
prefix = options[:prefix] && "#{options[:prefix] == true ? to : options[:prefix]}_"
|
117
|
-
|
118
|
-
file, line = caller.first.split(':', 2)
|
119
|
-
line = line.to_i
|
120
|
-
|
121
|
-
methods.each do |method|
|
122
|
-
on_nil =
|
123
|
-
if options[:allow_nil]
|
124
|
-
'return'
|
125
|
-
else
|
126
|
-
%(raise "#{self}##{prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}")
|
127
|
-
end
|
128
|
-
|
129
|
-
module_eval(<<-EOS, file, line - 5)
|
130
|
-
if instance_methods(false).map(&:to_s).include?("#{prefix}#{method}")
|
131
|
-
remove_possible_method("#{prefix}#{method}")
|
132
|
-
end
|
133
|
-
|
134
|
-
def #{prefix}#{method}(*args, &block) # def customer_name(*args, &block)
|
135
|
-
#{to}.__send__(#{method.inspect}, *args, &block) # client.__send__(:name, *args, &block)
|
136
|
-
rescue NoMethodError # rescue NoMethodError
|
137
|
-
if #{to}.nil? # if client.nil?
|
138
|
-
#{on_nil} # return # depends on :allow_nil
|
139
|
-
else # else
|
140
|
-
raise # raise
|
141
|
-
end # end
|
142
|
-
end # end
|
143
|
-
EOS
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
class Module
|
2
|
-
# Declare that a method has been deprecated.
|
3
|
-
# deprecate :foo
|
4
|
-
# deprecate :bar => 'message'
|
5
|
-
# deprecate :foo, :bar, :baz => 'warning!', :qux => 'gone!'
|
6
|
-
def deprecate(*method_names)
|
7
|
-
ActiveSupport::Deprecation.deprecate_methods(self, *method_names)
|
8
|
-
end
|
9
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'active_support/inflector'
|
2
|
-
|
3
|
-
class Module
|
4
|
-
# Returns the name of the module containing this one.
|
5
|
-
#
|
6
|
-
# M::N.parent_name # => "M"
|
7
|
-
def parent_name
|
8
|
-
unless defined? @parent_name
|
9
|
-
@parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil
|
10
|
-
end
|
11
|
-
@parent_name
|
12
|
-
end
|
13
|
-
|
14
|
-
# Returns the module which contains this one according to its name.
|
15
|
-
#
|
16
|
-
# module M
|
17
|
-
# module N
|
18
|
-
# end
|
19
|
-
# end
|
20
|
-
# X = M::N
|
21
|
-
#
|
22
|
-
# M::N.parent # => M
|
23
|
-
# X.parent # => M
|
24
|
-
#
|
25
|
-
# The parent of top-level and anonymous modules is Object.
|
26
|
-
#
|
27
|
-
# M.parent # => Object
|
28
|
-
# Module.new.parent # => Object
|
29
|
-
#
|
30
|
-
def parent
|
31
|
-
parent_name ? ActiveSupport::Inflector.constantize(parent_name) : Object
|
32
|
-
end
|
33
|
-
|
34
|
-
# Returns all the parents of this module according to its name, ordered from
|
35
|
-
# nested outwards. The receiver is not contained within the result.
|
36
|
-
#
|
37
|
-
# module M
|
38
|
-
# module N
|
39
|
-
# end
|
40
|
-
# end
|
41
|
-
# X = M::N
|
42
|
-
#
|
43
|
-
# M.parents # => [Object]
|
44
|
-
# M::N.parents # => [M, Object]
|
45
|
-
# X.parents # => [M, Object]
|
46
|
-
#
|
47
|
-
def parents
|
48
|
-
parents = []
|
49
|
-
if parent_name
|
50
|
-
parts = parent_name.split('::')
|
51
|
-
until parts.empty?
|
52
|
-
parents << ActiveSupport::Inflector.constantize(parts * '::')
|
53
|
-
parts.pop
|
54
|
-
end
|
55
|
-
end
|
56
|
-
parents << Object unless parents.include? Object
|
57
|
-
parents
|
58
|
-
end
|
59
|
-
|
60
|
-
if RUBY_VERSION < '1.9'
|
61
|
-
# Returns the constants that have been defined locally by this object and
|
62
|
-
# not in an ancestor. This method is exact if running under Ruby 1.9. In
|
63
|
-
# previous versions it may miss some constants if their definition in some
|
64
|
-
# ancestor is identical to their definition in the receiver.
|
65
|
-
def local_constants
|
66
|
-
inherited = {}
|
67
|
-
|
68
|
-
ancestors.each do |anc|
|
69
|
-
next if anc == self
|
70
|
-
anc.constants.each { |const| inherited[const] = anc.const_get(const) }
|
71
|
-
end
|
72
|
-
|
73
|
-
constants.select do |const|
|
74
|
-
!inherited.key?(const) || inherited[const].object_id != const_get(const).object_id
|
75
|
-
end
|
76
|
-
end
|
77
|
-
else
|
78
|
-
def local_constants #:nodoc:
|
79
|
-
constants(false)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
# Returns the names of the constants defined locally rather than the
|
84
|
-
# constants themselves. See <tt>local_constants</tt>.
|
85
|
-
def local_constant_names
|
86
|
-
local_constants.map { |c| c.to_s }
|
87
|
-
end
|
88
|
-
end
|