bahuvrihi-syckle 1.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2008, Regents of the University of Colorado.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this
4
+ software and associated documentation files (the "Software"), to deal in the Software
5
+ without restriction, including without limitation the rights to use, copy, modify, merge,
6
+ publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7
+ to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or
10
+ substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
16
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19
+ OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,53 @@
1
+ = {Syckle}[http://bahuvrihi.github.com/syckle]
2
+
3
+ A sick little syck loader.
4
+
5
+ == Description
6
+
7
+ YAML is great and complete, but load relatively slowly in large part because
8
+ it loads everything at once. In cases where you need to quickly load a
9
+ simple YAML configuration file, the overhead is too much.
10
+
11
+ Syckle is a very simple syck binding that can load basic ruby types:
12
+ true, false, nil, numbers, strings, symbols, arrays, and hashes. When
13
+ Syckle.load encounters a more complex object, it autoloads YAML and
14
+ defers to YAML.load. The result is a quicker-loading, seamless
15
+ alternative to using YAML.
16
+
17
+ Benchmarks indicate a require + load using Syckle is about 10x faster than
18
+ the same using YAML, entirely due to the require time.
19
+
20
+ == Usage
21
+
22
+ Simply require syckle instead of yaml. YAML will be set for autoloading
23
+ as necessary, and can be required at a later time if necessary (although
24
+ note that using syckle only provides a load-time benefit up until YAML
25
+ is loaded, duh).
26
+
27
+ start = Time.now
28
+
29
+ require 'syckle'
30
+ Syckle.load("key: value") # => {'key' => 'value'}
31
+
32
+ puts "#{Time.now-start} s"
33
+
34
+ === Bugs/Known Issues
35
+
36
+ - Syckle seems to work on both Ruby 1.8.* and Ruby 1.9.1. It does not work
37
+ on JRuby (I don't think JRuby uses syck). One word of caution, for reasons
38
+ unknown, an autoloading test under 1.9 was found to hang when written one
39
+ way and not when written in what looks to be an identical way. See
40
+ {syckle_allows_subsequent_autoloads_test.rb}[http://github.com/bahuvrihi/syckle/tree/master/test/syckle_allows_subsequent_autoloads_test.rb]
41
+
42
+ == Installation
43
+
44
+ Syckle is available as a gem on GitHub[http://rubyforge.org/projects/tap]. Use:
45
+
46
+ % gem install bahuvrihi-syckle
47
+
48
+ == Info
49
+
50
+ Copyright (c) 2008, Regents of the University of Colorado.
51
+ Developer:: {Simon Chiang}[http://bahuvrihi.wordpress.com], {Biomolecular Structure Program}[http://biomol.uchsc.edu/], {Hansen Lab}[http://hsc-proteomics.uchsc.edu/hansenlab/]
52
+ Support:: CU Denver School of Medicine Deans Academic Enrichment Fund
53
+ Licence:: {MIT-Style}[link:files/MIT-LICENSE.html]
@@ -0,0 +1,85 @@
1
+ require 'syck'
2
+
3
+ # unassign YAML
4
+ Syckle = YAML
5
+ Object.send(:remove_const, :YAML)
6
+
7
+ # setup the load cycle
8
+ $:.unshift File.expand_path(File.dirname(__FILE__))
9
+ autoload(:YAML, "yaml")
10
+
11
+ # === The cyclical syckle load cycle
12
+ #
13
+ # Syckle has a tricky require cycle to load syck without affecting YAML
14
+ # autoloading. Normally requiring 'syck' loads the 'syck.bundle'; this
15
+ # is what happens during the require cycle of YAML itself.
16
+ #
17
+ # Syckle requires 'syck' then unshifts the syckle directory to the top of the
18
+ # load path, so that any subsequent requires of 'syck' will load 'syckle/sick'
19
+ # and not 'syck.bundle' (which has already been loaded). The result is that
20
+ # the normal load cycle for yaml, invoked directly or through an autoload,
21
+ # will cause 'syckle/syck' to be required.
22
+ #
23
+ # Syckle is designed so that 'syckle/syck' tears down Syckle and effectively
24
+ # replaces Syckle.load with YAML.load. If YAML is loaded before Syckle, the
25
+ # syckle load cycle directly calls 'syckle/syck' and the replacement occurs
26
+ # immediately.
27
+ module Syckle
28
+ Syck::DefaultResolver.use_types_at(
29
+ "tag:ruby.yaml.org,2002:symbol" => Symbol,
30
+ "tag:ruby.yaml.org,2002:sym" => Symbol)
31
+ SyckleParser = Syck::Parser.new.set_resolver( Syck::DefaultResolver )
32
+
33
+ # Loads the input string as YAML. If the string has YAML that
34
+ # is too complex for Syckle, YAML itself is loaded and will be
35
+ # used to load the string.
36
+ #
37
+ # Note that only strings are allowed, IO objects will immediately
38
+ # trigger YAML loading.
39
+ def Syckle.load(str)
40
+ begin
41
+ raise Syckle::Error unless str.kind_of?(String)
42
+ yp = SyckleParser.load( str )
43
+
44
+ rescue(Exception)
45
+ require 'yaml'
46
+ load(str)
47
+ end
48
+ end
49
+
50
+ # Raised to trigger YAML loading for a string that is too complex for Syckle.
51
+ class Error < StandardError; end
52
+
53
+ class PrivateType
54
+
55
+ # Raises a Syckle::Error on initialization, and thereby triggers YAML
56
+ # loading. When YAML is loaded, this method is overridden.
57
+ def initialize( domain, type, val )
58
+ raise Syckle::Error
59
+ end
60
+ end
61
+
62
+ class DomainType
63
+
64
+ # Raises a Syckle::Error on initialization, and thereby triggers YAML
65
+ # loading. When YAML is loaded, this method is overridden.
66
+ def initialize( domain, type, val )
67
+ raise Syckle::Error
68
+ end
69
+ end
70
+ end
71
+
72
+ class Symbol
73
+
74
+ # Raises a Syckle::Error on errors, and thereby triggers YAML loading.
75
+ # Otherwise the same as the Symbol.yaml_new defined by YAML itself.
76
+ # When YAML is loaded, this method is overridden.
77
+ def Symbol.yaml_new( klass, tag, val )
78
+ if String === val
79
+ val = Syckle::load( val ) if val =~ /\A(["']).*\1\z/
80
+ val.intern
81
+ else
82
+ raise Syckle::Error
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,24 @@
1
+
2
+ # Reassign unassigned YAML constants. Note that even though
3
+ # PrivateType and DomainType are modified in setup, the changes
4
+ # are effectively rolled back when the rest of YAML is loaded.
5
+ module YAML # :nodoc:
6
+ unless const_defined?(:Syck)
7
+ Syck = Syckle::Syck
8
+ PrivateType = Syckle::PrivateType
9
+ DomainType = Syckle::DomainType
10
+ Object = Syckle::Object
11
+ end
12
+ end if Object.const_defined?(:Syckle)
13
+
14
+ module Syckle
15
+ def Syckle.load(io)
16
+ YAML.load(io)
17
+ end
18
+ end
19
+
20
+ # teardown the load cycle
21
+ $:.delete File.expand_path(File.dirname(__FILE__))
22
+
23
+ # ensure yaml is loaded
24
+ require 'yaml'
data/lib/syckle.rb ADDED
@@ -0,0 +1,5 @@
1
+ if Object.const_defined?(:YAML)
2
+ require 'syckle/syck'
3
+ else
4
+ require 'syckle/setup'
5
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bahuvrihi-syckle
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.0"
5
+ platform: ruby
6
+ authors:
7
+ - Simon Chiang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-22 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: simon.a.chiang@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - MIT-LICENSE
25
+ files:
26
+ - lib/syckle.rb
27
+ - lib/syckle/setup.rb
28
+ - lib/syckle/syck.rb
29
+ - README
30
+ - MIT-LICENSE
31
+ has_rdoc: true
32
+ homepage: http://bahuvrihi.github.com/syckle
33
+ post_install_message:
34
+ rdoc_options:
35
+ - --main
36
+ - README
37
+ - -S
38
+ - -N
39
+ - --title
40
+ - Syckle
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: A sick little syck loader.
62
+ test_files: []
63
+