Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Puzzling over why ri can open the std ruby/ri .yaml files, but raw yaml can't

Reply
Thread Tools

Puzzling over why ri can open the std ruby/ri .yaml files, but raw yaml can't

 
 
Eric Promislow
Guest
Posts: n/a
 
      10-31-2006
If I run <<ri Abbrev>>, no problem.

But with this code:

##########
require 'yaml'
require 'pp'

class RiFinder
def initialize(sysdir)
@sysdir = sysdir
end

def get_class_info(clsName, info)
clsFile = "#{@sysdir}/#{clsName}/cdesc-#{clsName}.yaml"
puts "About to yaml <<#{clsFile}>>"
clsInfo = File.open(clsFile) { |io| YAML.load(io) }
pp clsInfo
end
end

rifinder = RiFinder.new("c:/ruby/share/ri/1.8/system", nil, nil)
rifinder.get_class_info("Abbrev", nil)

#===========

About to yaml <<c:/ruby/share/ri/1.8/system/Abbrev/cdesc-Abbrev.yaml>>
I get this error:
c:/ruby/lib/ruby/1.8/yaml.rb:133:in `transfer': invalid subclass
(TypeError)
from c:/ruby/lib/ruby/1.8/yaml.rb:133:in `load'
from get_yaml_info.rb:19:in `get_class_info'
from get_yaml_info.rb:19:in `get_class_info'
from get_yaml_info.rb:25

ruby 1.8.4 (2006-04-14) [i386-mswin32]

It's the same code, and I don't see ri setting any options in the YAML
namespace
telling it to process types like "!ruby/struct:SM::Flow:"
differently, although I gather
this is the problem.

Any advice?

I can use yaml.rb to read back files I've written out with it. The
problem is with the
rdoc files. But it works when I go through ri (after adding the bug
fix at line 99
of ri_descriptions.rb given in
http://ruby.about.com/od/gettingstarted/qt/ruby_ri.htm).

Thanks,
Eric

 
Reply With Quote
 
 
 
 
Eric Promislow
Guest
Posts: n/a
 
      10-31-2006
Simple workaround...

clsInfo = YAML.load(File.open(clsFile) { |io| io.read.gsub(/- !.*/, '-
') }

But I'd still appreciate hearing the cause for this bug.

Happens with the stock Ruby 1.8.2 on OS X 10.4 running on an i386,
but with a different error message.

- Eric

>
> def get_class_info(clsName, info)
> clsFile = "#{@sysdir}/#{clsName}/cdesc-#{clsName}.yaml"
> puts "About to yaml <<#{clsFile}>>"
> clsInfo = YAML.load(File.open(clsFile) { |io| io.read.gsub(/- !.*/, '- ') }
> pp clsInfo
> end
> end
>
> rifinder = RiFinder.new("c:/ruby/share/ri/1.8/system", nil, nil)
> rifinder.get_class_info("Abbrev", nil)
>
> #===========
>
> About to yaml <<c:/ruby/share/ri/1.8/system/Abbrev/cdesc-Abbrev.yaml>>
> I get this error:
> c:/ruby/lib/ruby/1.8/yaml.rb:133:in `transfer': invalid subclass
> (TypeError)
> from c:/ruby/lib/ruby/1.8/yaml.rb:133:in `load'
> from get_yaml_info.rb:19:in `get_class_info'
> from get_yaml_info.rb:19:in `get_class_info'
> from get_yaml_info.rb:25
>
> ruby 1.8.4 (2006-04-14) [i386-mswin32]
>
> It's the same code, and I don't see ri setting any options in the YAML
> namespace
> telling it to process types like "!ruby/struct:SM::Flow:"
> differently, although I gather
> this is the problem.
>
> Any advice?
>
> I can use yaml.rb to read back files I've written out with it. The
> problem is with the
> rdoc files. But it works when I go through ri (after adding the bug
> fix at line 99
> of ri_descriptions.rb given in
> http://ruby.about.com/od/gettingstarted/qt/ruby_ri.htm).
>
> Thanks,
> Eric


 
Reply With Quote
 
 
 
 
Ryan Davis
Guest
Posts: n/a
 
      10-31-2006

On Oct 31, 2006, at 1:05 PM, Eric Promislow wrote:

> If I run <<ri Abbrev>>, no problem.
>
> But with this code:
>
> ##########
> require 'yaml'
> require 'pp'
>
> class RiFinder
> def initialize(sysdir)
> @sysdir = sysdir
> end
>
> def get_class_info(clsName, info)
> clsFile = "#{@sysdir}/#{clsName}/cdesc-#{clsName}.yaml"
> puts "About to yaml <<#{clsFile}>>"
> clsInfo = File.open(clsFile) { |io| YAML.load(io) }
> pp clsInfo
> end
> end
>
> rifinder = RiFinder.new("c:/ruby/share/ri/1.8/system", nil, nil)
> rifinder.get_class_info("Abbrev", nil)


Because you need to load/define all the classes it is trying to
deserialize. yaml doesn't know where they are. Just pop in the
appropriate requires up top and get rid of your munger.

FWIW, I went the munging route for risearch and for that matter...
you seem to be writing much of the same sort of thing. Check my blog
for the code. I'll release it to seattlerb sooner or later.


 
Reply With Quote
 
Mauricio Fernandez
Guest
Posts: n/a
 
      10-31-2006
On Wed, Nov 01, 2006 at 06:05:12AM +0900, Eric Promislow wrote:
> About to yaml <<c:/ruby/share/ri/1.8/system/Abbrev/cdesc-Abbrev.yaml>>
> I get this error:
> c:/ruby/lib/ruby/1.8/yaml.rb:133:in `transfer': invalid subclass
> (TypeError)
> from c:/ruby/lib/ruby/1.8/yaml.rb:133:in `load'
> from get_yaml_info.rb:19:in `get_class_info'
> from get_yaml_info.rb:19:in `get_class_info'
> from get_yaml_info.rb:25
>
> ruby 1.8.4 (2006-04-14) [i386-mswin32]
>
> It's the same code, and I don't see ri setting any options in the YAML
> namespace telling it to process types like "!ruby/struct:SM::Flow:"
> differently, although I gather this is the problem.
>
> Any advice?


$ cat ri-problem.rb
require 'yaml'
require 'pp'

class RiFinder
def initialize(sysdir)
@sysdir = sysdir
end

def get_class_info(clsName, info)
clsFile = "#{@sysdir}/#{clsName}/cdesc-#{clsName}.yaml"
puts "About to yaml <<#{clsFile}>>"
clsInfo = File.open(clsFile) { |io| YAML.load(io) }
pp clsInfo
end
end

rifinder = RiFinder.new("/usr/share/ri/1.8/system/")
rifinder.get_class_info("Abbrev", nil)

$ ruby ri-problem.rb
About to yaml <</usr/share/ri/1.8/system//Abbrev/cdesc-Abbrev.yaml>>
/home/batsman/usr//lib/ruby/1.8/yaml.rb:133:in `transfer': invalid subclass (TypeError)
from /home/batsman/usr//lib/ruby/1.8/yaml.rb:133:in `node_import'
from /home/batsman/usr//lib/ruby/1.8/yaml.rb:133:in `load'
from /home/batsman/usr//lib/ruby/1.8/yaml.rb:133:in `load'
from ri-problem.rb:12:in `get_class_info'
from ri-problem.rb:12:in `open'
from ri-problem.rb:12:in `get_class_info'
from ri-problem.rb:18
$ echo 'require "rdoc/ri/ri_reader"' | cat - ri-problem.rb > ri-no-problem.rb
$ ruby ri-no-problem.rb
About to yaml <</usr/share/ri/1.8/system//Abbrev/cdesc-Abbrev.yaml>>
#<RI::ClassDescription:0xa7db27f0
@attributes=[],
@class_methods=[],
@comment=
[#<struct SM::Flow:
body=
"Calculate the set of unique abbreviations for a given set of strings.">,
#<struct SM::Flow::VERB
body=
" require 'abbrev'\n require 'pp'\n\n pp Abbrev::abbrev(['ruby', 'rules']).sort\n">,
#<struct SM::Flow: body="<em>Generates:</em>">,
#<struct SM::Flow::VERB
body=
" [[&quot;rub&quot;, &quot;ruby&quot;],\n [&quot;ruby&quot;, &quot;ruby&quot;],\n [&quot;rul&quot;, &quot;rules&quot;],\n [&quot;rule&quot;, &quot;rules&quot;],\n [&quot;rules&quot;, &quot;rules&quot;]]\n">,
#<struct SM::Flow:
body="Also adds an <tt>abbrev</tt> method to class <tt>Array</tt>.">],
@constants=[],
@full_name="Abbrev",
@includes=[],
@instance_methods=[#<RI::MethodSummary:0xa7db3024 @name="abbrev">],
@name="Abbrev",
@superclass=nil>

--
Mauricio Fernandez - http://eigenclass.org - singular Ruby

 
Reply With Quote
 
Eric Promislow
Guest
Posts: n/a
 
      10-31-2006
Thanks, Ryan,

require 'rdoc/markup/simple_markup/to_flow'

does it, no munging needed. Now if you can tell me how to setup the
current release of cygwin on a win box to build mozilla you'll have
totally made my day. In the meantime, running a find script to zap
all the 13s out of each .sh file seems to be the way to go. Right,
wrong newsgroup...

- Eric

This seems wrong though. I want to load a set of YAML descriptions
I didn't write, and I need to know all possible subtypes
Ryan Davis wrote:
> On Oct 31, 2006, at 1:05 PM, Eric Promislow wrote:
>
> > If I run <<ri Abbrev>>, no problem.
> >
> > But with this code:
> >
> > ##########
> > require 'yaml'
> > require 'pp'
> >
> > class RiFinder
> > def initialize(sysdir)
> > @sysdir = sysdir
> > end
> >
> > def get_class_info(clsName, info)
> > clsFile = "#{@sysdir}/#{clsName}/cdesc-#{clsName}.yaml"
> > puts "About to yaml <<#{clsFile}>>"
> > clsInfo = File.open(clsFile) { |io| YAML.load(io) }
> > pp clsInfo
> > end
> > end
> >
> > rifinder = RiFinder.new("c:/ruby/share/ri/1.8/system", nil, nil)
> > rifinder.get_class_info("Abbrev", nil)

>
> Because you need to load/define all the classes it is trying to
> deserialize. yaml doesn't know where they are. Just pop in the
> appropriate requires up top and get rid of your munger.
>
> FWIW, I went the munging route for risearch and for that matter...
> you seem to be writing much of the same sort of thing. Check my blog
> for the code. I'll release it to seattlerb sooner or later.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VOIP over VPN over TCP over WAP over 3G Theo Markettos UK VOIP 2 02-14-2008 03:27 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
YAML.dump/YAML.load bug Paul Battley Ruby 0 08-03-2005 08:28 PM
YAML Question: Using YAML::YamlNode#transform Method to get float values? RubyQuestions Ruby 0 12-03-2003 02:15 AM



Advertisments