[Georuby-devel] post_gis_adapter's to_yaml function

Doug Cole dougcole at gmail.com
Wed May 31 14:26:28 EDT 2006


Hmm, you're right, I spoke too soon.  According to the documentation to yaml
takes a hash of options, so something like .to_yaml( :Indent => 4,
:Separator => '') should work, but I just tried it and it didn't so I'm not
sure.  Since I'm building the entire fixture before using to_yaml, it's not
a problem, but I'm not sure of the best way to do it as a single field in a
fixture, unless someone else can get .to_yaml to use the options hash.
Sorry,
Doug

On 5/31/06, Guilhem Vellut <guilhem.vellut at gmail.com> wrote:
>
>  Well actually, it does not work totally fine when trying to manually
> input a geometry in a fixture (with something like <%= Point.from_x_y(
> 123.4,567.1).to_yaml %>), using the default  "to_yaml" for objects of the
> YAML library. The problems are that the document separator ("---") is output
> and that the components of the Point are not indented, which makes the YAML
> parser crash when reading the fixture. Do you know of options to prevent
> that?
>
>
>
> Therefore for now I will keep the former to_yaml methods specific to
> geometries and rename them "to_fixture_format", so the dumping to YAML
> format can work, as well as the input of geometries in a fixture.
>
>
>
> guilhem
>
>
>  ------------------------------
>
> *From:* Doug Cole [mailto:dougcole at gmail.com]
>
> *Sent:* 31 May 2006 11:00
> *To:* georuby-devel at rubyforge.org
> *Cc:* Guilhem Vellut
> *Subject:* Re: [Georuby-devel] post_gis_adapter's to_yaml function
>
>
>
> Sorry, I should have been more specific.  The code I was looking at that
> has reference to the optional hash array was the yaml code in the ruby
> standard library, where to_yaml is defined for the built in classes
> (yaml/rubytypes.rb)  Here's a reference to the options hash:
> http://yaml4r.sourceforge.net/doc/page/the_options_hash.htm.  I was trying
> to use the spatial adapter's to_yaml to dump part of my database to a yaml
> file, with the ar_fixtures plugin (
> http://nubyonrails.com/articles/2005/12/27/dump-or-slurp-yaml-reference-data)
> basically the call boils down to converting an activeRecord's attributes to
> yaml ( row.attributes.to_yaml).  Like I said, simply removing the to_yaml
> function from the postgis_adapter fixed it for me, as yaml defaults to
> simply outputting all the instance variables, which works fine in my case.
> Doug
>
> -On a related note - I was reading the archives for this mailing list and
> saw that someone was trying to figure out how to get a Geometry column into
> their fixture.  This is probably too late to help here, but Fixtures are run
> through the same interpreter as .rhtml files are so you can always do
> something along the lines of #{ Point.from_x_y(x, y).to_yaml} if you're
> not sure...hope that helps.
>
> On 5/30/06, *Guilhem Vellut* <guilhem.vellut at gmail.com > wrote:
>
> Hello Doug,
>
>
>
> I don't have all the elements to solve your problem. When you write "looking
> through the yaml code it looks like there's an optional options hash", what
> yaml code are you referring to? And how are you trying to use the method?
>
>
>
> If you use it in fixtures, the to_yaml method for geometries is used the
> following way:
>
> first:
>
>   id: 1
>
>   data: HELLO WORLD
>
>   value: 3
>
> geom: <%= Geometry.from_ewkt('POINT(1.4 5.67)').to_yaml %>
>
> And it outputs the canonical representation of the geometry for the target
> database (HexEWKB for PostGIS).
>
>
>
> guilhem
>
>
>
>
>  ------------------------------
>
> *From:* georuby-devel-bounces at rubyforge.org [mailto:georuby-devel-bounces at rubyforge.org]
> *On Behalf Of *Doug Cole
> *Sent:* 31 May 2006 03:26
> *To:* georuby-devel at rubyforge.org
> *Subject:* [Georuby-devel] post_gis_adapter's to_yaml function
>
>
>
> Hello,
>   I just tried to use the to_yaml function in the post_gis_adapter and ran
> across some problems:
>
> -first I got an error related to the number of arguments (1 for 0),
> looking through the yaml code it looks like there's an optional options hash
> so I simply redefined the function as  "to_yaml( opts = {} )"
>
> -after fixing that I recieved the error "wrong argument type String
> (expected Data) (TypeError)" which I haven't tackled.
>
> anyone else run into these problems?  I was trying to dump some point data
> from my postgres database to a fixture for testing.  Simply removing the
> to_yaml definition fixed things, so that's how I've left it, but I thought
> I'd report the problem.
> Doug
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/georuby-devel/attachments/20060531/b210cd17/attachment-0001.htm 


More information about the Georuby-devel mailing list