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
data/lib/active_support/i18n.rb
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
#begin
|
2
|
-
# require 'i18n'
|
3
|
-
#rescue LoadError => e
|
4
|
-
# $stderr.puts "You don't have i18n installed in your application. Please add it to your Gemfile and run bundle install"
|
5
|
-
# raise e
|
6
|
-
#end
|
7
|
-
#I18n.load_path << "#{File.dirname(__FILE__)}/locale/en.yml"
|
8
|
-
#ActiveSupport.run_load_hooks(:i18n)
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module ActiveSupport
|
2
|
-
Inflector.inflections do |inflect|
|
3
|
-
inflect.plural(/$/, 's')
|
4
|
-
inflect.plural(/s$/i, 's')
|
5
|
-
inflect.plural(/(ax|test)is$/i, '\1es')
|
6
|
-
inflect.plural(/(octop|vir)us$/i, '\1i')
|
7
|
-
inflect.plural(/(alias|status)$/i, '\1es')
|
8
|
-
inflect.plural(/(bu)s$/i, '\1ses')
|
9
|
-
inflect.plural(/(buffal|tomat)o$/i, '\1oes')
|
10
|
-
inflect.plural(/([ti])um$/i, '\1a')
|
11
|
-
inflect.plural(/sis$/i, 'ses')
|
12
|
-
inflect.plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves')
|
13
|
-
inflect.plural(/(hive)$/i, '\1s')
|
14
|
-
inflect.plural(/([^aeiouy]|qu)y$/i, '\1ies')
|
15
|
-
inflect.plural(/(x|ch|ss|sh)$/i, '\1es')
|
16
|
-
inflect.plural(/(matr|vert|ind)(?:ix|ex)$/i, '\1ices')
|
17
|
-
inflect.plural(/([m|l])ouse$/i, '\1ice')
|
18
|
-
inflect.plural(/^(ox)$/i, '\1en')
|
19
|
-
inflect.plural(/(quiz)$/i, '\1zes')
|
20
|
-
|
21
|
-
inflect.singular(/s$/i, '')
|
22
|
-
inflect.singular(/(n)ews$/i, '\1ews')
|
23
|
-
inflect.singular(/([ti])a$/i, '\1um')
|
24
|
-
inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '\1\2sis')
|
25
|
-
inflect.singular(/(^analy)ses$/i, '\1sis')
|
26
|
-
inflect.singular(/([^f])ves$/i, '\1fe')
|
27
|
-
inflect.singular(/(hive)s$/i, '\1')
|
28
|
-
inflect.singular(/(tive)s$/i, '\1')
|
29
|
-
inflect.singular(/([lr])ves$/i, '\1f')
|
30
|
-
inflect.singular(/([^aeiouy]|qu)ies$/i, '\1y')
|
31
|
-
inflect.singular(/(s)eries$/i, '\1eries')
|
32
|
-
inflect.singular(/(m)ovies$/i, '\1ovie')
|
33
|
-
inflect.singular(/(x|ch|ss|sh)es$/i, '\1')
|
34
|
-
inflect.singular(/([m|l])ice$/i, '\1ouse')
|
35
|
-
inflect.singular(/(bus)es$/i, '\1')
|
36
|
-
inflect.singular(/(o)es$/i, '\1')
|
37
|
-
inflect.singular(/(shoe)s$/i, '\1')
|
38
|
-
inflect.singular(/(cris|ax|test)es$/i, '\1is')
|
39
|
-
inflect.singular(/(octop|vir)i$/i, '\1us')
|
40
|
-
inflect.singular(/(alias|status)es$/i, '\1')
|
41
|
-
inflect.singular(/^(ox)en/i, '\1')
|
42
|
-
inflect.singular(/(vert|ind)ices$/i, '\1ex')
|
43
|
-
inflect.singular(/(matr)ices$/i, '\1ix')
|
44
|
-
inflect.singular(/(quiz)zes$/i, '\1')
|
45
|
-
inflect.singular(/(database)s$/i, '\1')
|
46
|
-
|
47
|
-
inflect.irregular('person', 'people')
|
48
|
-
inflect.irregular('man', 'men')
|
49
|
-
inflect.irregular('child', 'children')
|
50
|
-
inflect.irregular('sex', 'sexes')
|
51
|
-
inflect.irregular('move', 'moves')
|
52
|
-
inflect.irregular('cow', 'kine')
|
53
|
-
|
54
|
-
inflect.uncountable(%w(equipment information rice money species series fish sheep jeans))
|
55
|
-
end
|
56
|
-
end
|
@@ -1,7 +0,0 @@
|
|
1
|
-
# in case active_support/inflector is required without the rest of active_support
|
2
|
-
require 'active_support/inflector/inflections'
|
3
|
-
require 'active_support/inflector/transliterate'
|
4
|
-
require 'active_support/inflector/methods'
|
5
|
-
|
6
|
-
require 'active_support/inflections'
|
7
|
-
require 'active_support/core_ext/string/inflections'
|
@@ -1,211 +0,0 @@
|
|
1
|
-
module ActiveSupport
|
2
|
-
module Inflector
|
3
|
-
# A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
|
4
|
-
# inflection rules. Examples:
|
5
|
-
#
|
6
|
-
# ActiveSupport::Inflector.inflections do |inflect|
|
7
|
-
# inflect.plural /^(ox)$/i, '\1\2en'
|
8
|
-
# inflect.singular /^(ox)en/i, '\1'
|
9
|
-
#
|
10
|
-
# inflect.irregular 'octopus', 'octopi'
|
11
|
-
#
|
12
|
-
# inflect.uncountable "equipment"
|
13
|
-
# end
|
14
|
-
#
|
15
|
-
# New rules are added at the top. So in the example above, the irregular rule for octopus will now be the first of the
|
16
|
-
# pluralization and singularization rules that is runs. This guarantees that your rules run before any of the rules that may
|
17
|
-
# already have been loaded.
|
18
|
-
class Inflections
|
19
|
-
def self.instance
|
20
|
-
@__instance__ ||= new
|
21
|
-
end
|
22
|
-
|
23
|
-
attr_reader :plurals, :singulars, :uncountables, :humans
|
24
|
-
|
25
|
-
def initialize
|
26
|
-
@plurals, @singulars, @uncountables, @humans = [], [], [], []
|
27
|
-
end
|
28
|
-
|
29
|
-
# Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
|
30
|
-
# The replacement should always be a string that may include references to the matched data from the rule.
|
31
|
-
def plural(rule, replacement)
|
32
|
-
@uncountables.delete(rule) if rule.is_a?(String)
|
33
|
-
@uncountables.delete(replacement)
|
34
|
-
@plurals.insert(0, [rule, replacement])
|
35
|
-
end
|
36
|
-
|
37
|
-
# Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
|
38
|
-
# The replacement should always be a string that may include references to the matched data from the rule.
|
39
|
-
def singular(rule, replacement)
|
40
|
-
@uncountables.delete(rule) if rule.is_a?(String)
|
41
|
-
@uncountables.delete(replacement)
|
42
|
-
@singulars.insert(0, [rule, replacement])
|
43
|
-
end
|
44
|
-
|
45
|
-
# Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
|
46
|
-
# for strings, not regular expressions. You simply pass the irregular in singular and plural form.
|
47
|
-
#
|
48
|
-
# Examples:
|
49
|
-
# irregular 'octopus', 'octopi'
|
50
|
-
# irregular 'person', 'people'
|
51
|
-
def irregular(singular, plural)
|
52
|
-
@uncountables.delete(singular)
|
53
|
-
@uncountables.delete(plural)
|
54
|
-
if singular[0,1].upcase == plural[0,1].upcase
|
55
|
-
plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1])
|
56
|
-
plural(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + plural[1..-1])
|
57
|
-
singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1])
|
58
|
-
else
|
59
|
-
plural(Regexp.new("#{singular[0,1].upcase}(?i)#{singular[1..-1]}$"), plural[0,1].upcase + plural[1..-1])
|
60
|
-
plural(Regexp.new("#{singular[0,1].downcase}(?i)#{singular[1..-1]}$"), plural[0,1].downcase + plural[1..-1])
|
61
|
-
plural(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), plural[0,1].upcase + plural[1..-1])
|
62
|
-
plural(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), plural[0,1].downcase + plural[1..-1])
|
63
|
-
singular(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), singular[0,1].upcase + singular[1..-1])
|
64
|
-
singular(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), singular[0,1].downcase + singular[1..-1])
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
# Add uncountable words that shouldn't be attempted inflected.
|
69
|
-
#
|
70
|
-
# Examples:
|
71
|
-
# uncountable "money"
|
72
|
-
# uncountable "money", "information"
|
73
|
-
# uncountable %w( money information rice )
|
74
|
-
def uncountable(*words)
|
75
|
-
(@uncountables << words).flatten!
|
76
|
-
end
|
77
|
-
|
78
|
-
# Specifies a humanized form of a string by a regular expression rule or by a string mapping.
|
79
|
-
# When using a regular expression based replacement, the normal humanize formatting is called after the replacement.
|
80
|
-
# When a string is used, the human form should be specified as desired (example: 'The name', not 'the_name')
|
81
|
-
#
|
82
|
-
# Examples:
|
83
|
-
# human /_cnt$/i, '\1_count'
|
84
|
-
# human "legacy_col_person_name", "Name"
|
85
|
-
def human(rule, replacement)
|
86
|
-
@humans.insert(0, [rule, replacement])
|
87
|
-
end
|
88
|
-
|
89
|
-
# Clears the loaded inflections within a given scope (default is <tt>:all</tt>).
|
90
|
-
# Give the scope as a symbol of the inflection type, the options are: <tt>:plurals</tt>,
|
91
|
-
# <tt>:singulars</tt>, <tt>:uncountables</tt>, <tt>:humans</tt>.
|
92
|
-
#
|
93
|
-
# Examples:
|
94
|
-
# clear :all
|
95
|
-
# clear :plurals
|
96
|
-
def clear(scope = :all)
|
97
|
-
case scope
|
98
|
-
when :all
|
99
|
-
@plurals, @singulars, @uncountables = [], [], []
|
100
|
-
else
|
101
|
-
instance_variable_set "@#{scope}", []
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
# Yields a singleton instance of Inflector::Inflections so you can specify additional
|
107
|
-
# inflector rules.
|
108
|
-
#
|
109
|
-
# Example:
|
110
|
-
# ActiveSupport::Inflector.inflections do |inflect|
|
111
|
-
# inflect.uncountable "rails"
|
112
|
-
# end
|
113
|
-
def inflections
|
114
|
-
if block_given?
|
115
|
-
yield Inflections.instance
|
116
|
-
else
|
117
|
-
Inflections.instance
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
# Returns the plural form of the word in the string.
|
122
|
-
#
|
123
|
-
# Examples:
|
124
|
-
# "post".pluralize # => "posts"
|
125
|
-
# "octopus".pluralize # => "octopi"
|
126
|
-
# "sheep".pluralize # => "sheep"
|
127
|
-
# "words".pluralize # => "words"
|
128
|
-
# "CamelOctopus".pluralize # => "CamelOctopi"
|
129
|
-
def pluralize(word)
|
130
|
-
result = word.to_s.dup
|
131
|
-
|
132
|
-
if word.empty? || inflections.uncountables.include?(result.downcase)
|
133
|
-
result
|
134
|
-
else
|
135
|
-
inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
|
136
|
-
result
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# The reverse of +pluralize+, returns the singular form of a word in a string.
|
141
|
-
#
|
142
|
-
# Examples:
|
143
|
-
# "posts".singularize # => "post"
|
144
|
-
# "octopi".singularize # => "octopus"
|
145
|
-
# "sheep".singularize # => "sheep"
|
146
|
-
# "word".singularize # => "word"
|
147
|
-
# "CamelOctopi".singularize # => "CamelOctopus"
|
148
|
-
def singularize(word)
|
149
|
-
result = word.to_s.dup
|
150
|
-
|
151
|
-
if inflections.uncountables.any? { |inflection| result =~ /#{inflection}\Z/i }
|
152
|
-
result
|
153
|
-
else
|
154
|
-
inflections.singulars.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
|
155
|
-
result
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
# Capitalizes the first word and turns underscores into spaces and strips a
|
160
|
-
# trailing "_id", if any. Like +titleize+, this is meant for creating pretty output.
|
161
|
-
#
|
162
|
-
# Examples:
|
163
|
-
# "employee_salary" # => "Employee salary"
|
164
|
-
# "author_id" # => "Author"
|
165
|
-
def humanize(lower_case_and_underscored_word)
|
166
|
-
result = lower_case_and_underscored_word.to_s.dup
|
167
|
-
|
168
|
-
inflections.humans.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
|
169
|
-
result.gsub(/_id$/, "").gsub(/_/, " ").capitalize
|
170
|
-
end
|
171
|
-
|
172
|
-
# Capitalizes all the words and replaces some characters in the string to create
|
173
|
-
# a nicer looking title. +titleize+ is meant for creating pretty output. It is not
|
174
|
-
# used in the Rails internals.
|
175
|
-
#
|
176
|
-
# +titleize+ is also aliased as as +titlecase+.
|
177
|
-
#
|
178
|
-
# Examples:
|
179
|
-
# "man from the boondocks".titleize # => "Man From The Boondocks"
|
180
|
-
# "x-men: the last stand".titleize # => "X Men: The Last Stand"
|
181
|
-
def titleize(word)
|
182
|
-
humanize(underscore(word)).gsub(/\b('?[a-z])/) { $1.capitalize }
|
183
|
-
end
|
184
|
-
|
185
|
-
# Create the name of a table like Rails does for models to table names. This method
|
186
|
-
# uses the +pluralize+ method on the last word in the string.
|
187
|
-
#
|
188
|
-
# Examples
|
189
|
-
# "RawScaledScorer".tableize # => "raw_scaled_scorers"
|
190
|
-
# "egg_and_ham".tableize # => "egg_and_hams"
|
191
|
-
# "fancyCategory".tableize # => "fancy_categories"
|
192
|
-
def tableize(class_name)
|
193
|
-
pluralize(underscore(class_name))
|
194
|
-
end
|
195
|
-
|
196
|
-
# Create a class name from a plural table name like Rails does for table names to models.
|
197
|
-
# Note that this returns a string and not a Class. (To convert to an actual class
|
198
|
-
# follow +classify+ with +constantize+.)
|
199
|
-
#
|
200
|
-
# Examples:
|
201
|
-
# "egg_and_hams".classify # => "EggAndHam"
|
202
|
-
# "posts".classify # => "Post"
|
203
|
-
#
|
204
|
-
# Singular names are not handled correctly:
|
205
|
-
# "business".classify # => "Busines"
|
206
|
-
def classify(table_name)
|
207
|
-
# strip out any leading schema name
|
208
|
-
camelize(singularize(table_name.to_s.sub(/.*\./, '')))
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
@@ -1,141 +0,0 @@
|
|
1
|
-
module ActiveSupport
|
2
|
-
# The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without,
|
3
|
-
# and class names to foreign keys. The default inflections for pluralization, singularization, and uncountable words are kept
|
4
|
-
# in inflections.rb.
|
5
|
-
#
|
6
|
-
# The Rails core team has stated patches for the inflections library will not be accepted
|
7
|
-
# in order to avoid breaking legacy applications which may be relying on errant inflections.
|
8
|
-
# If you discover an incorrect inflection and require it for your application, you'll need
|
9
|
-
# to correct it yourself (explained below).
|
10
|
-
module Inflector
|
11
|
-
extend self
|
12
|
-
|
13
|
-
# By default, +camelize+ converts strings to UpperCamelCase. If the argument to +camelize+
|
14
|
-
# is set to <tt>:lower</tt> then +camelize+ produces lowerCamelCase.
|
15
|
-
#
|
16
|
-
# +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces.
|
17
|
-
#
|
18
|
-
# Examples:
|
19
|
-
# "active_record".camelize # => "ActiveRecord"
|
20
|
-
# "active_record".camelize(:lower) # => "activeRecord"
|
21
|
-
# "active_record/errors".camelize # => "ActiveRecord::Errors"
|
22
|
-
# "active_record/errors".camelize(:lower) # => "activeRecord::Errors"
|
23
|
-
def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
|
24
|
-
if first_letter_in_uppercase
|
25
|
-
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
26
|
-
else
|
27
|
-
lower_case_and_underscored_word.to_s[0].chr.downcase + camelize(lower_case_and_underscored_word)[1..-1]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
|
32
|
-
#
|
33
|
-
# Changes '::' to '/' to convert namespaces to paths.
|
34
|
-
#
|
35
|
-
# Examples:
|
36
|
-
# "ActiveRecord".underscore # => "active_record"
|
37
|
-
# "ActiveRecord::Errors".underscore # => active_record/errors
|
38
|
-
def underscore(camel_cased_word)
|
39
|
-
word = camel_cased_word.to_s.dup
|
40
|
-
word.gsub!(/::/, '/')
|
41
|
-
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
42
|
-
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
43
|
-
word.tr!("-", "_")
|
44
|
-
word.downcase!
|
45
|
-
word
|
46
|
-
end
|
47
|
-
|
48
|
-
# Replaces underscores with dashes in the string.
|
49
|
-
#
|
50
|
-
# Example:
|
51
|
-
# "puni_puni" # => "puni-puni"
|
52
|
-
def dasherize(underscored_word)
|
53
|
-
underscored_word.gsub(/_/, '-')
|
54
|
-
end
|
55
|
-
|
56
|
-
# Removes the module part from the expression in the string.
|
57
|
-
#
|
58
|
-
# Examples:
|
59
|
-
# "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections"
|
60
|
-
# "Inflections".demodulize # => "Inflections"
|
61
|
-
def demodulize(class_name_in_module)
|
62
|
-
class_name_in_module.to_s.gsub(/^.*::/, '')
|
63
|
-
end
|
64
|
-
|
65
|
-
# Creates a foreign key name from a class name.
|
66
|
-
# +separate_class_name_and_id_with_underscore+ sets whether
|
67
|
-
# the method should put '_' between the name and 'id'.
|
68
|
-
#
|
69
|
-
# Examples:
|
70
|
-
# "Message".foreign_key # => "message_id"
|
71
|
-
# "Message".foreign_key(false) # => "messageid"
|
72
|
-
# "Admin::Post".foreign_key # => "post_id"
|
73
|
-
def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
|
74
|
-
underscore(demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id")
|
75
|
-
end
|
76
|
-
|
77
|
-
# Ruby 1.9 introduces an inherit argument for Module#const_get and
|
78
|
-
# #const_defined? and changes their default behavior.
|
79
|
-
if Module.method(:const_get).arity == 1
|
80
|
-
# Tries to find a constant with the name specified in the argument string:
|
81
|
-
#
|
82
|
-
# "Module".constantize # => Module
|
83
|
-
# "Test::Unit".constantize # => Test::Unit
|
84
|
-
#
|
85
|
-
# The name is assumed to be the one of a top-level constant, no matter whether
|
86
|
-
# it starts with "::" or not. No lexical context is taken into account:
|
87
|
-
#
|
88
|
-
# C = 'outside'
|
89
|
-
# module M
|
90
|
-
# C = 'inside'
|
91
|
-
# C # => 'inside'
|
92
|
-
# "C".constantize # => 'outside', same as ::C
|
93
|
-
# end
|
94
|
-
#
|
95
|
-
# NameError is raised when the name is not in CamelCase or the constant is
|
96
|
-
# unknown.
|
97
|
-
def constantize(camel_cased_word)
|
98
|
-
names = camel_cased_word.split('::')
|
99
|
-
names.shift if names.empty? || names.first.empty?
|
100
|
-
|
101
|
-
constant = Object
|
102
|
-
names.each do |name|
|
103
|
-
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
104
|
-
end
|
105
|
-
constant
|
106
|
-
end
|
107
|
-
else
|
108
|
-
def constantize(camel_cased_word) #:nodoc:
|
109
|
-
names = camel_cased_word.split('::')
|
110
|
-
names.shift if names.empty? || names.first.empty?
|
111
|
-
|
112
|
-
constant = Object
|
113
|
-
names.each do |name|
|
114
|
-
constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name)
|
115
|
-
end
|
116
|
-
constant
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
# Turns a number into an ordinal string used to denote the position in an
|
121
|
-
# ordered sequence such as 1st, 2nd, 3rd, 4th.
|
122
|
-
#
|
123
|
-
# Examples:
|
124
|
-
# ordinalize(1) # => "1st"
|
125
|
-
# ordinalize(2) # => "2nd"
|
126
|
-
# ordinalize(1002) # => "1002nd"
|
127
|
-
# ordinalize(1003) # => "1003rd"
|
128
|
-
def ordinalize(number)
|
129
|
-
if (11..13).include?(number.to_i % 100)
|
130
|
-
"#{number}th"
|
131
|
-
else
|
132
|
-
case number.to_i % 10
|
133
|
-
when 1; "#{number}st"
|
134
|
-
when 2; "#{number}nd"
|
135
|
-
when 3; "#{number}rd"
|
136
|
-
else "#{number}th"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'active_support/core_ext/string/multibyte'
|
3
|
-
|
4
|
-
module ActiveSupport
|
5
|
-
module Inflector
|
6
|
-
|
7
|
-
# Replaces non-ASCII characters with an ASCII approximation, or if none
|
8
|
-
# exists, a replacement character which defaults to "?".
|
9
|
-
#
|
10
|
-
# transliterate("Ærøskøbing")
|
11
|
-
# # => "AEroskobing"
|
12
|
-
#
|
13
|
-
# Default approximations are provided for Western/Latin characters,
|
14
|
-
# e.g, "ø", "ñ", "é", "ß", etc.
|
15
|
-
#
|
16
|
-
# This method is I18n aware, so you can set up custom approximations for a
|
17
|
-
# locale. This can be useful, for example, to transliterate German's "ü"
|
18
|
-
# and "ö" to "ue" and "oe", or to add support for transliterating Russian
|
19
|
-
# to ASCII.
|
20
|
-
#
|
21
|
-
# In order to make your custom transliterations available, you must set
|
22
|
-
# them as the <tt>i18n.transliterate.rule</tt> i18n key:
|
23
|
-
#
|
24
|
-
# # Store the transliterations in locales/de.yml
|
25
|
-
# i18n:
|
26
|
-
# transliterate:
|
27
|
-
# rule:
|
28
|
-
# ü: "ue"
|
29
|
-
# ö: "oe"
|
30
|
-
#
|
31
|
-
# # Or set them using Ruby
|
32
|
-
# I18n.backend.store_translations(:de, :i18n => {
|
33
|
-
# :transliterate => {
|
34
|
-
# :rule => {
|
35
|
-
# "ü" => "ue",
|
36
|
-
# "ö" => "oe"
|
37
|
-
# }
|
38
|
-
# }
|
39
|
-
# })
|
40
|
-
#
|
41
|
-
# The value for <tt>i18n.transliterate.rule</tt> can be a simple Hash that maps
|
42
|
-
# characters to ASCII approximations as shown above, or, for more complex
|
43
|
-
# requirements, a Proc:
|
44
|
-
#
|
45
|
-
# I18n.backend.store_translations(:de, :i18n => {
|
46
|
-
# :transliterate => {
|
47
|
-
# :rule => lambda {|string| MyTransliterator.transliterate(string)}
|
48
|
-
# }
|
49
|
-
# })
|
50
|
-
#
|
51
|
-
# Now you can have different transliterations for each locale:
|
52
|
-
#
|
53
|
-
# I18n.locale = :en
|
54
|
-
# transliterate("Jürgen")
|
55
|
-
# # => "Jurgen"
|
56
|
-
#
|
57
|
-
# I18n.locale = :de
|
58
|
-
# transliterate("Jürgen")
|
59
|
-
# # => "Juergen"
|
60
|
-
def transliterate(string, replacement = "?")
|
61
|
-
I18n.transliterate(ActiveSupport::Multibyte::Unicode.normalize(
|
62
|
-
ActiveSupport::Multibyte::Unicode.tidy_bytes(string), :c),
|
63
|
-
:replacement => replacement)
|
64
|
-
end
|
65
|
-
|
66
|
-
# Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
|
67
|
-
#
|
68
|
-
# ==== Examples
|
69
|
-
#
|
70
|
-
# class Person
|
71
|
-
# def to_param
|
72
|
-
# "#{id}-#{name.parameterize}"
|
73
|
-
# end
|
74
|
-
# end
|
75
|
-
#
|
76
|
-
# @person = Person.find(1)
|
77
|
-
# # => #<Person id: 1, name: "Donald E. Knuth">
|
78
|
-
#
|
79
|
-
# <%= link_to(@person.name, person_path(@person)) %>
|
80
|
-
# # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
|
81
|
-
def parameterize(string, sep = '-')
|
82
|
-
# replace accented chars with their ascii equivalents
|
83
|
-
parameterized_string = transliterate(string)
|
84
|
-
# Turn unwanted chars into the separator
|
85
|
-
parameterized_string.gsub!(/[^a-z0-9\-_]+/i, sep)
|
86
|
-
unless sep.nil? || sep.empty?
|
87
|
-
re_sep = Regexp.escape(sep)
|
88
|
-
# No more than one of the separator in a row.
|
89
|
-
parameterized_string.gsub!(/#{re_sep}{2,}/, sep)
|
90
|
-
# Remove leading/trailing separator.
|
91
|
-
parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/i, '')
|
92
|
-
end
|
93
|
-
parameterized_string.downcase
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
end
|