yaml_waml 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ MIT-LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
@@ -0,0 +1,17 @@
1
+ === Version 0.2.0
2
+
3
+ 2008-09-02.
4
+
5
+ - Applied patch from OHASHI Hideya: YAML.dump support.
6
+
7
+ === Version 0.1.2
8
+
9
+ 2008-09-02.
10
+
11
+ - gemized in http://gems.github.com/
12
+
13
+ === Version 0.1.1
14
+
15
+ 2007-01-05.
16
+
17
+ - initial release.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Akira Ikeda, KAKUTANI Shintaro
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,77 @@
1
+ = YamlWaml
2
+
3
+ YamlWaml is for 'YAML WorkAround for Multibyte Language'.
4
+
5
+ This Rails plugin originated by the blog entry written by Akira Ikeda.
6
+
7
+ (*) http://d.hatena.ne.jp/Rommy/20061229/1167406811
8
+
9
+ == Install
10
+
11
+ === Installing the gem manually
12
+
13
+ gem sources -a http://gems.github.com
14
+ gem install kakutani-yaml_waml
15
+
16
+ in ruby code ...
17
+
18
+ require 'rubygems'
19
+ gem 'kakutani-yaml_waml'
20
+ ...
21
+ require 'yaml_waml'
22
+
23
+ === 2.1.0 <= rails w/ gem dependencies
24
+
25
+ Rails::Initializer.run do |config|
26
+ config.gem 'kakutani-yaml_waml', :version => '~> 0.1.1', :lib => 'yaml_waml',
27
+ :source => 'http://gems.github.com'
28
+ end
29
+
30
+ === 2.1.0 <= rails
31
+
32
+ * script/plugin install git://github.com/kakutani/yaml_waml.git
33
+
34
+ === rails <= 2.0.2
35
+
36
+ * script/plugin install http://yaml-waml.googlecode.com/svn/plugins/yaml_waml
37
+
38
+ == Repositories
39
+
40
+ == Git
41
+
42
+ * git://github.com/kakutani/yaml_waml.git
43
+
44
+ == SVN repository (obsoleted)
45
+
46
+ * http://yaml-waml.googlecode.com/svn/plugins/yaml_waml
47
+
48
+ It will not maintain anymore.
49
+
50
+ == License
51
+
52
+ MIT License
53
+
54
+ == Running the specs
55
+
56
+ In order to run YamlWaml's full suite of specs (rake pre_commit),
57
+ you must install the following gems:
58
+
59
+ * rspec # Tests plugin behaviour
60
+ * rake # Runs the build script
61
+ * rcov # Verifies that the code is 100% covered by specs
62
+
63
+ == Web Site
64
+
65
+ * http://github.com/kakutani/yaml_waml/
66
+
67
+ == Authors
68
+
69
+ Akira Ikeda(pinpon.ikeda at gmail.com), http://d.hatena.ne.jp/Rommy
70
+
71
+ Adapted by KAKUTANI Shintaro(shintaro at kakutani.com), http://kakutani.com
72
+
73
+ Thaks for pathes from followings:
74
+
75
+ * OHASHI Hideya (handling StringIO), http://github.com/ohac
76
+ * Nobuhiro IMAI (DRYied, handling IO), http://github.com/no6v
77
+ * Keiji Yoshimi (benchmark script and some advices), http://github.com/walf443
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ gem 'rspec', '>= 1.1.4'
3
+ require 'rake'
4
+ require 'rake/rdoctask'
5
+ require 'spec/rake/spectask'
6
+ require 'spec/rake/verify_rcov'
7
+
8
+ desc 'Default: run unit tests.'
9
+ task :default => :spec
10
+
11
+ task :pre_commit => [:spec, 'coverage:verify']
12
+
13
+ desc 'Run all specs under spec/**/*_spec.rb'
14
+ Spec::Rake::SpecTask.new(:spec => 'coverage:clean') do |t|
15
+ t.spec_files = FileList['spec/**/*_spec.rb']
16
+ t.spec_opts = ["-c", "--diff"]
17
+ t.rcov = true
18
+ t.rcov_opts = ["--include-file", "lib\/*\.rb", "--exclude", "spec\/"]
19
+ end
20
+
21
+ desc 'Generate documentation for the yaml_waml plugin.'
22
+ Rake::RDocTask.new(:rdoc) do |rdoc|
23
+ rdoc.rdoc_dir = 'rdoc'
24
+ rdoc.title = 'YamlWaml'
25
+ rdoc.options << '--line-numbers' << '--inline-source'
26
+ rdoc.rdoc_files.include('README')
27
+ rdoc.rdoc_files.include('lib/**/*.rb')
28
+ end
29
+
30
+ namespace :coverage do
31
+ desc "Delete aggregate coverage data."
32
+ task(:clean) { rm_f "coverage" }
33
+
34
+ desc "verify coverage threshold via RCov"
35
+ RCov::VerifyTask.new(:verify => :spec) do |t|
36
+ t.threshold = 100.0 # Make sure you have rcov 0.7 or higher!
37
+ t.index_html = 'coverage/index.html'
38
+ end
39
+ end
40
+
41
+ begin
42
+ require 'jeweler'
43
+ Jeweler::Tasks.new do |gem|
44
+ gem.name = "yaml_waml"
45
+ gem.summary = "'to_yaml' workaround for multibyte UTF-8 string."
46
+ gem.description = "Plugin gem to workaround for fixing output result of 'to_yaml' method treats multibyte UTF-8 string(such as japanese) as binary. "
47
+ gem.has_rdoc = false
48
+ gem.email = "shintaro@kakutani.com"
49
+ gem.homepage = "http://github.com/kakutani/yaml_waml"
50
+ gem.authors = ["KAKUTANI Shintaro", "Akira Ikeda"]
51
+ gem.add_development_dependency "rspec", ">= 1.2.9"
52
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
53
+ end
54
+ Jeweler::GemcutterTasks.new
55
+ rescue LoadError
56
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
57
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
@@ -0,0 +1,79 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'benchmark'
3
+ require 'yaml'
4
+
5
+ class String
6
+ def is_binary_data?
7
+ false
8
+ end
9
+ end
10
+
11
+ data = [ "あいうえお漢字" * 10000, "__BBBBBBBBBBBBBBB__", "あいうえお" * 10000 ]
12
+
13
+ yaml_str = data.to_yaml
14
+ Benchmark.bm do |x|
15
+ x.report('original yaml_waml') {
16
+ yaml_str.gsub(/\\x(\w{2})/) {
17
+ [ Regexp.last_match.captures.first.to_i(16)].pack("C")
18
+ }
19
+ }
20
+
21
+ x.report('using $1') {
22
+ yaml_str.gsub(/\\x(\w{2})/) {
23
+ [ $1.to_i(16) ].pack("C")
24
+ }
25
+ }
26
+
27
+ x.report('using $1 w/ H2') {
28
+ yaml_str.gsub(/\\x(\w{2})/){
29
+ [$1].pack("H2")
30
+ }
31
+ }
32
+
33
+ x.report('with memoize') {
34
+ memoize_of = {}
35
+ yaml_str.gsub(/\\x(\w{2})/) {|s|
36
+ memoize_of[s] ||= [ Regexp.last_match.captures.first.to_i(16)].pack("C")
37
+ }
38
+ }
39
+
40
+ x.report('with memoize and $1') {
41
+ memoize_of = {}
42
+ yaml_str.gsub(/\\x(\w{2})/) {|s|
43
+ memoize_of[s] ||= [ $1.to_i(16) ].pack("C")
44
+ }
45
+ }
46
+
47
+ x.report('with symbol table ') {
48
+ memoize_of = {}
49
+ chars = %w( 0 1 2 3 4 5 6 7 8 9 A B C D E F )
50
+ chars.each do |char1|
51
+ chars.each do |char2|
52
+ val = char1 + char2
53
+ memoize_of["\\x#{val}"] = [ val.to_i(16) ].pack("C")
54
+ end
55
+ end
56
+ yaml_str.gsub(/\\x\w{2}/) {|s|
57
+ memoize_of[s]
58
+ }
59
+ }
60
+
61
+ x.report('packing multi chars') {
62
+ regex = /\\x/
63
+ # 100は結構てきとう。無条件に大きすぎると返って遅くなりそうな気がするので適当なサイズにしておく
64
+ yaml_str.gsub(/(?:\\x(\w{2})){0,100}/) {|s|
65
+ s.split(regex).compact.map {|s| s.to_i(16) }.pack("C*").gsub("\0", '')
66
+ }
67
+ }
68
+
69
+ end
70
+
71
+ # result on my environment( MacBook Pro Intel Core Duo 2.5 GHz, 4GB), result is like that
72
+ # user system total real
73
+ # original yaml_waml 1.700000 0.030000 1.730000 ( 2.460140)
74
+ # using $1 1.430000 0.020000 1.450000 ( 2.030178)
75
+ # using $1 w/ H2 1.160000 0.010000 1.170000 ( 1.476650)
76
+ # with memoize 0.770000 0.010000 0.780000 ( 0.972146)
77
+ # with memoize and $1 0.780000 0.010000 0.790000 ( 0.973506)
78
+ # with symbol table 0.770000 0.010000 0.780000 ( 1.102112)
79
+ # packing multi chars 0.740000 0.010000 0.750000 ( 0.908722)
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'yaml_waml'
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,35 @@
1
+ require "yaml"
2
+
3
+ class String
4
+ def is_binary_data?
5
+ false
6
+ end
7
+ end
8
+
9
+ module YamlWaml
10
+ def decode(orig_yamled)
11
+ yamled_str = case orig_yamled
12
+ when String then orig_yamled
13
+ when StringIO then orig_yamled.string
14
+ else return orig_yamled
15
+ end
16
+ yamled_str.gsub!(/\\x(\w{2})/){[$1].pack("H2")}
17
+ return yamled_str
18
+ end
19
+ module_function :decode
20
+ end
21
+
22
+ ObjectSpace.each_object(Class) do |klass|
23
+ klass.class_eval do
24
+ if method_defined?(:to_yaml) && !method_defined?(:to_yaml_with_decode)
25
+ def to_yaml_with_decode(*args)
26
+ io = args.shift if IO === args.first
27
+ yamled_str = YamlWaml.decode(to_yaml_without_decode(*args))
28
+ io.write(yamled_str) if io
29
+ return yamled_str
30
+ end
31
+ alias_method :to_yaml_without_decode, :to_yaml
32
+ alias_method :to_yaml, :to_yaml_with_decode
33
+ end
34
+ end
35
+ end
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/../lib/yaml_waml'
@@ -0,0 +1,93 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + "/spec_helper"
3
+ BLANK = " "
4
+ describe YAML, "#to_yaml" do
5
+ describe "Japanese text" do
6
+ it "String should output string" do
7
+ "あ".to_yaml.should == <<-EXPECTED
8
+ --- "あ"
9
+ EXPECTED
10
+ end
11
+
12
+ it "Array-ed string should output string" do
13
+ ['あ','い'].to_yaml.should == <<-EXPECTED
14
+ ---#{BLANK}
15
+ - "あ"
16
+ - "い"
17
+ EXPECTED
18
+ end
19
+
20
+ it "Hash-ed string should output string" do
21
+ {'日本語' => ['出力']}.to_yaml.should == <<-EXPECTED
22
+ ---#{BLANK}
23
+ "日本語":#{BLANK}
24
+ - "出力"
25
+ EXPECTED
26
+ end
27
+
28
+ it "mixed Array should output string" do
29
+ actual = [["あ", "い"], {"う" => ["え"]}, Struct.new(:name).new("お")]
30
+ actual.to_yaml.should == <<-EXPECTED
31
+ ---#{BLANK}
32
+ - - "あ"
33
+ - "い"
34
+ - "う":#{BLANK}
35
+ - "え"
36
+ - !ruby/struct:#{BLANK}
37
+ name: "お"
38
+ EXPECTED
39
+ end
40
+ end
41
+ end
42
+
43
+ describe YAML, ".dump" do
44
+ it "should output yaml string" do
45
+ YAML.dump("あ").should == <<-EXPECTED
46
+ --- "あ"
47
+ EXPECTED
48
+ end
49
+
50
+ it "should be StringIO-friendly" do
51
+ actual = [["あ", "い"], {"う" => ["え"]}, Struct.new(:name).new("お")]
52
+ io = StringIO.new
53
+ YAML.dump(actual, io)
54
+ io.string.should == <<-EXPECTED
55
+ ---#{BLANK}
56
+ - - "あ"
57
+ - "い"
58
+ - "う":#{BLANK}
59
+ - "え"
60
+ - !ruby/struct:#{BLANK}
61
+ name: "お"
62
+ EXPECTED
63
+ end
64
+
65
+
66
+ require 'fileutils'
67
+
68
+ TEST_FILEPATH = File.expand_path("to_yaml_io.txt", File.dirname(__FILE__))
69
+ before(:all) do
70
+ FileUtils.touch(TEST_FILEPATH)
71
+ end
72
+
73
+ after(:all) do
74
+ FileUtils.rm(TEST_FILEPATH)
75
+ end
76
+
77
+ it "should be IO-friendly" do
78
+ actual = [["や", "む"], {"る" => ["わ", "む"]}, "る"]
79
+ File.open(TEST_FILEPATH, 'w') do |f|
80
+ YAML.dump(actual, f)
81
+ end
82
+ yamled_str = File.read(TEST_FILEPATH)
83
+ yamled_str.should == <<-EXPECTED
84
+ ---#{BLANK}
85
+ - - "や"
86
+ - "む"
87
+ - "る":#{BLANK}
88
+ - "わ"
89
+ - "む"
90
+ - "る"
91
+ EXPECTED
92
+ end
93
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :yaml_waml do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{yaml_waml}
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["KAKUTANI Shintaro", "Akira Ikeda"]
12
+ s.date = %q{2009-10-20}
13
+ s.description = %q{Plugin gem to workaround for fixing output result of 'to_yaml' method treats multibyte UTF-8 string(such as japanese) as binary. }
14
+ s.email = %q{shintaro@kakutani.com}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ ".gitignore",
21
+ "History.txt",
22
+ "MIT-LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "benchmark/huge_yaml_dump.rb",
27
+ "init.rb",
28
+ "install.rb",
29
+ "lib/yaml_waml.rb",
30
+ "spec/spec_helper.rb",
31
+ "spec/to_yaml_spec.rb",
32
+ "tasks/yaml_waml_tasks.rake",
33
+ "yaml_waml.gemspec"
34
+ ]
35
+ s.homepage = %q{http://github.com/kakutani/yaml_waml}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.5}
39
+ s.summary = %q{'to_yaml' workaround for multibyte UTF-8 string.}
40
+ s.test_files = [
41
+ "spec/spec_helper.rb",
42
+ "spec/to_yaml_spec.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
56
+ end
57
+ end
58
+
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yaml_waml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - KAKUTANI Shintaro
8
+ - Akira Ikeda
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-10-20 00:00:00 +09:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ type: :development
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 1.2.9
25
+ version:
26
+ description: "Plugin gem to workaround for fixing output result of 'to_yaml' method treats multibyte UTF-8 string(such as japanese) as binary. "
27
+ email: shintaro@kakutani.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - History.txt
38
+ - MIT-LICENSE
39
+ - README.rdoc
40
+ - Rakefile
41
+ - VERSION
42
+ - benchmark/huge_yaml_dump.rb
43
+ - init.rb
44
+ - install.rb
45
+ - lib/yaml_waml.rb
46
+ - spec/spec_helper.rb
47
+ - spec/to_yaml_spec.rb
48
+ - tasks/yaml_waml_tasks.rake
49
+ - yaml_waml.gemspec
50
+ has_rdoc: true
51
+ homepage: http://github.com/kakutani/yaml_waml
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.3.5
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: "'to_yaml' workaround for multibyte UTF-8 string."
78
+ test_files:
79
+ - spec/spec_helper.rb
80
+ - spec/to_yaml_spec.rb