Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #7 from esminc/deprecated-constants

OrdinarySystemDevelopment is deprecated entirely
  • Loading branch information...
commit 78c161206554aa6a0021e2fce58ae00cc7ef4f06 2 parents 8667e3e + c5cca80
@hibariya hibariya authored
View
20 lib/gyomu_ruby.rb
@@ -1,15 +1,19 @@
# coding: utf-8
require 'gyomu_ruby/core_ext/time'
require 'gyomu_ruby/core_ext/numeric'
+require 'gyomu_ruby/deprecation'
module GyomuRuby
- autoload :AmazonWebService, 'gyomu_ruby/amazon_web_service'
- autoload :MasterData, 'gyomu_ruby/master_data'
- autoload :AddressFormatter, 'gyomu_ruby/address_formatter'
- autoload :Deprecation, 'gyomu_ruby/deprecation'
+ autoload :AmazonWebService, 'gyomu_ruby/amazon_web_service'
+ autoload :MasterData, 'gyomu_ruby/master_data'
+ autoload :AddressFormatter, 'gyomu_ruby/address_formatter'
+ autoload :AllYourSiteAreBelongToSsl, 'gyomu_ruby/all_your_site_are_belong_to_ssl'
+ autoload :Translation, 'gyomu_ruby/translated_from'
+ autoload :WordNormalizer, 'gyomu_ruby/word_normalizer'
+ autoload :AddressFormatter, 'gyomu_ruby/address_formatter'
- # DEPRECATED
- osd_dir = 'gyomu_ruby/ordinary_system_development'
- autoload :OrdinarySystemDevelopment, osd_dir
- autoload :OSD, osd_dir
+ extend GyomuRuby::Deprecation::DeprecatedConstant
+
+ deprecated :OrdinarySystemDevelopment, GyomuRuby
+ deprecated :OSD, GyomuRuby
end
View
21 lib/gyomu_ruby/all_your_site_are_belong_to_ssl.rb
@@ -0,0 +1,21 @@
+# coding:us-ascii
+
+require 'rack'
+
+module GyomuRuby
+ class AllYourSiteAreBelongToSsl
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ if env['HTTPS'] == 'on' || env['HTTP_X_FORWARDED_PROTO'] == 'https'
+ @app.call(env)
+ else
+ url = Rack::Request.new(env).url.sub(/^http:/, 'https:')
+ body = "<html><body>You are being <a href=\"#{url}\">redirected</a>.</body></html>"
+ [301, {'Location' => url, 'Content-Type' => 'text/html'}, [body]]
+ end
+ end
+ end
+end
View
21 lib/gyomu_ruby/deprecation.rb
@@ -1,11 +1,32 @@
module GyomuRuby
module Deprecation
module_function
+
def deprecated_method_warning(method_name, message)
warning = "DEPRECATIOPN WARNING:"
warning = "#{warning} #{method_name} is deprecated and will be removed in the near future"
warning = "#{warning} (#{message})"
STDERR.puts(warning)
end
+
+ module DeprecatedConstant
+ private
+
+ def self.extended(constant)
+ constant.instance_variable_set :@__new_constants, {}
+ end
+
+ def const_missing(name)
+ return super unless constant = @__new_constants[name]
+
+ STDERR.puts "DEPRECATIOPN WARNING: #{self.name}::#{name} is deprecated and will be removed in the near future(use #{constant.name} instead)"
+
+ constant
+ end
+
+ def deprecated(name, new_constant)
+ @__new_constants.update name => new_constant
+ end
+ end
end
end
View
13 lib/gyomu_ruby/ordinary_system_development.rb
@@ -1,13 +0,0 @@
-# coding: utf-8
-
-module GyomuRuby
- module OrdinarySystemDevelopment
- osd_dir = 'gyomu_ruby/ordinary_system_development/'
- autoload 'AllYourSiteAreBelongToSsl', osd_dir + 'all_your_site_are_belong_to_ssl'
- autoload 'Translation', osd_dir + 'translated_from'
- autoload 'WordNormalizer', osd_dir + 'word_normalizer'
- autoload 'AddressFormatter', osd_dir + 'address_formatter'
- end
-
- OSD = OrdinarySystemDevelopment
-end
View
27 lib/gyomu_ruby/ordinary_system_development/address_formatter.rb
@@ -1,27 +0,0 @@
-# coding: utf-8
-
-require 'gyomu_ruby/deprecation'
-
-module GyomuRuby
- module OrdinarySystemDevelopment
- module AddressFormatter
- module_function
-
- def format_zipcode(zipcode_string, blank = '')
- GyomuRuby::Deprecation.deprecated_method_warning(:format_zipcode, "use GyomuRuby::AddressFormatter.format_zipcode instead")
- GyomuRuby::AddressFormatter.format_zipcode(zipcode_string, blank)
- end
-
- def format_tel_no(telno_numeric_string, blank = '')
- GyomuRuby::Deprecation.deprecated_method_warning(:format_tel_no, "use GyomuRuby::AddressFormatter.format_tel_no instead")
- GyomuRuby::AddressFormatter.format_tel_no(telno_numeric_string, blank)
- end
-
- def prefecture_name(prefecture_code, blank = '')
- GyomuRuby::Deprecation.deprecated_method_warning(:prefecture_code, "use GyomuRuby::AddressFormatter.format_prefecture_name instead")
- GyomuRuby::AddressFormatter.prefecture_name(prefecture_code, blank)
- end
-
- end
- end
-end
View
22 lib/gyomu_ruby/ordinary_system_development/all_your_site_are_belong_to_ssl.rb
@@ -1,22 +0,0 @@
-# coding:us-ascii
-require 'rack'
-
-module GyomuRuby
- module OrdinarySystemDevelopment
- class AllYourSiteAreBelongToSsl
- def initialize(app)
- @app = app
- end
-
- def call(env)
- if env['HTTPS'] == 'on' || env['HTTP_X_FORWARDED_PROTO'] == 'https'
- @app.call(env)
- else
- url = Rack::Request.new(env).url.sub(/^http:/, 'https:')
- body = "<html><body>You are being <a href=\"#{url}\">redirected</a>.</body></html>"
- [301, {'Location' => url, 'Content-Type' => 'text/html'}, [body]]
- end
- end
- end
- end
-end
View
64 lib/gyomu_ruby/ordinary_system_development/word_normalizer.rb
@@ -1,64 +0,0 @@
-# coding: utf-8
-require 'moji'
-
-module GyomuRuby
- module OrdinarySystemDevelopment
- module WordNormalizer
- extend self
- def to_doublewidth_hiragana(word)
- normalize_symbol_unicode(Moji.kata_to_hira(Moji.han_to_zen(word || '', Moji::KANA)))
- end
- alias to_kana to_doublewidth_hiragana
-
- def normalize_unconversion_symbol_unicode(word)
- word.tap do |w|
- w.gsub!(/\u2212|\u2012|\u2013|\u2014/){ "\u30fc" }
- w.gsub!(/\u301c/){ "\uff5e" }
- end
- end
-
- def normalize_symbol_unicode(word)
- normalize_unconversion_symbol_unicode(word).tap do |w|
- w.gsub!(/\u002d|\uff0d|\u2015|\u2500/){ "\u30fc" }
- end
- end
-
- def to_time(word)
- if word.acts_like?(:time) && word.acts_like_time?
- word
- else
- Time.parse(word.to_s) rescue nil
- end
- end
-
- def to_date(word)
- if word.acts_like?(:date) && word.acts_like_date?
- word
- elsif word.respond_to?(:to_date)
- word.to_date
- else
- Date.parse(word.to_s) rescue nil
- end
- end
-
- def to_array(words)
- if words.is_a?(Hash)
- words.inject([]){|memo, (k,v)| v.blank? ? memo : memo << k.to_s }
- else
- Array(words)
- end
- end
-
- # XXX 0x20が壊れる詳細を追いかける
- def to_hankaku(word)
- return '' if word.blank?
- Moji.zen_to_han(Moji.han_to_zen(normalize_symbol_unicode(word), Moji::SYMBOL)).gsub(/\uff70/){ "\u002d" }
- end
-
- def to_numeric(word)
- return word.to_s if word.is_a?(Numeric)
- to_hankaku(word || '').scan(/\d/).join
- end
- end
- end
-end
View
3  ...by/ordinary_system_development/translated_from.rb → lib/gyomu_ruby/translated_from.rb
@@ -1,5 +1,6 @@
# coding: utf-8
-module GyomuRuby::OrdinarySystemDevelopment
+
+module GyomuRuby
class Translation
def self.source(word, scope)
new('ja').source(word, scope)
View
63 lib/gyomu_ruby/word_normalizer.rb
@@ -0,0 +1,63 @@
+# coding: utf-8
+
+require 'moji'
+
+module GyomuRuby
+ module WordNormalizer
+ extend self
+ def to_doublewidth_hiragana(word)
+ normalize_symbol_unicode(Moji.kata_to_hira(Moji.han_to_zen(word || '', Moji::KANA)))
+ end
+ alias to_kana to_doublewidth_hiragana
+
+ def normalize_unconversion_symbol_unicode(word)
+ word.tap do |w|
+ w.gsub!(/\u2212|\u2012|\u2013|\u2014/){ "\u30fc" }
+ w.gsub!(/\u301c/){ "\uff5e" }
+ end
+ end
+
+ def normalize_symbol_unicode(word)
+ normalize_unconversion_symbol_unicode(word).tap do |w|
+ w.gsub!(/\u002d|\uff0d|\u2015|\u2500/){ "\u30fc" }
+ end
+ end
+
+ def to_time(word)
+ if word.acts_like?(:time) && word.acts_like_time?
+ word
+ else
+ Time.parse(word.to_s) rescue nil
+ end
+ end
+
+ def to_date(word)
+ if word.acts_like?(:date) && word.acts_like_date?
+ word
+ elsif word.respond_to?(:to_date)
+ word.to_date
+ else
+ Date.parse(word.to_s) rescue nil
+ end
+ end
+
+ def to_array(words)
+ if words.is_a?(Hash)
+ words.inject([]){|memo, (k,v)| v.blank? ? memo : memo << k.to_s }
+ else
+ Array(words)
+ end
+ end
+
+ # XXX 0x20が壊れる詳細を追いかける
+ def to_hankaku(word)
+ return '' if word.blank?
+ Moji.zen_to_han(Moji.han_to_zen(normalize_symbol_unicode(word), Moji::SYMBOL)).gsub(/\uff70/){ "\u002d" }
+ end
+
+ def to_numeric(word)
+ return word.to_s if word.is_a?(Numeric)
+ to_hankaku(word || '').scan(/\d/).join
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.