Category Archives: Ruby

As I blogged about before, I’ve implemented the current drafts of CSV on the Web in the rdf-tabular gem. The gem is is available from rdf-tabular repo and is in the public domain (Unlicense) and is freely usable by anyone wishing to get a start on their own implementation. For those wishing to take an incremental approach, this post describes the basic workings of the gem, highlights more advanced cases necessary to pass the Test Suite and attempts to provide some insight into the process of implementing the specifications.

As many who follow me know, I’ve long been involved in the Linked Data and Semantic Web movements. It’s been my privilege to work on several successful projects, notably RDFa, Microdata RDF, and JSON-LD. For the past several months I’ve actively been working with the W3C CSV on the Web Working Group to help define a mechanism for transforming tabular data into RDF and JSON.

I’m happy to announce release 1.1.0 of the Ruby RDF suite, this includes support for RDF 1.1 Concepts and syntaxes, including RDF Literal changes, N-Triples, N-Quads, TriG and JSON-LD. Additionally, the SPARQL gem has been updated to support RDF 1.1 differences (mainly differences in plain literals vs those with xsd:string datatypes and the fact that language-tagged literals now have the rdf:langString datatype).

I added some minor updates to RDF.rb and re-issued versions 0.3.5 for the rdf and linkeddata gems. These updates are mostly to better support HTTP content negotaion and to find appropriate readers and writers based on file extension, mime-type, and content sniffing. There are also some minor fixes to aid jRuby and Ruby 1.9.3 support.

With the release of RDF::Turtle, starting with version 0.3.5, RDF::N3 no longer asserts that it is a reader for Turtle. This includes MIME Types text/turtle, application/turtle, application/x-turtle. Or the .ttl extension or :ttl or :turtle formats. Of course, N3 remains reasonably compatible with Turtle, but the recent RDF 1.1 Working Group publication of the Turtle Specification has caused some divergence.

I just released version 0.5.4 of RdfContext to GitHub and GemCutter. This version is notable for including support for RDFa 1.1 parsing. This is still based on an Working Draft, so it will likely change in the future.

Just pushed version 0.5.1 of RdfContext to GitHub and Gemcutter. This version includes a Serializer framework, including a AbstractSerializer, RecursiveSerializer and Turtle and RDF/XML serializers based on these. The RDF/XML serializer is a big improvement over the previous version, including Typed element names an RDF Container folding using parseType="collection".

This version of 0.5.0 adds support for Ruby 1.9 and 1.8.6 in addition to 1.8.7. Full unicode character escapes are supported in Ruby 1.9. The N3 parser has been substantially re-written and updated to be compliant with W3C SWAP, CWM and Turtle test suites, although it is supported only to the N3-rdf level, with variables and formulae not yet supported.

I’ve released version 0.4.4 of the RdfContext gem. As the name implies, RdfContext supports contextual data-stores bound to graphs, along with a ConjunctiveGraph providing the union of contexts within a given data-store.

Recently, I’ve been playing with RSpec to run RDFa test cases. The suite has accepted and unreviewed test cases. My general way of testing is to parse the suite, and run each test through a generated spec as follows:

I just released version 0.1.0 of the rdfa_parser_gem. This parser is written in Ruby and uses Nokogiri XML parsing. It passes all XHTML1 test cases and most of the existing test cases for HTML4 and HTML5.

After a fair amount of work, I’m happy to report that HTTP Digest Authentication is now a part of Rails 2.3. Although I put the finishing touches to get this into the release, it is based on work done by Dan Manges and Xavier Shay . Also, thanks to Don Parish for bug fixes and improvements after original acceptance.

Caching actions without layout can be complicated when multiple request formats are used. In particular, an HTML response may use a dynamic layout, in which case you want to use the :layout => false option. However, other formats (such as XML) don’t use a layout, but the :layout => false option to _caches_action_ does not properly cache the body in this case. To solve the problem, create two caches action statements:

Rails offers three forms of caching within your controller: page, action and fragment. Page caching results in the fastest access times, as the results of the first call to an action are saved in a file so that subsequent accesses never even hit rails. However, for most applications, this isn’t useful, as there may be dynamic content on a page, and this does not allow for authentication. Fragment caching is the most detailed, and allows different parts of a page to be cached and allows you to check for the presence of a cached fragment within your controller (or view), but it requires the most maintenance of cache keys. Action caching is a nice compromise between the two. It allows the controller to get into the action but takes care of cache key creation. It also allows for a dynamic layout using the :layout option. However, in some actions, the amount of work done by the controller may be non-trivial, so it would be nice to check for the presence of the cache within the body of the controller action. This can be solved by borrowing some code from within ActionController::Caching::Actions.

Recently, I was creating some in_place_editors for a polymorphic controller I’m working on. Although the problems not particular to polymorphic controllers, I didn’t want to embed too much model information within the controller. I came up with a way to use meathod_missing to define the in_place_editor_for on demand:

Related to the interesting talk at a recent NBRug meeting on Ruport, I’ve been looking at doing data warehousing in Ruby. Fortunately, Anthony Eden has beaten me to the punch with ActiveWarehouse. For those unfamiliar with Data Warehousing, the concepts are basically to create a series of facts that are indexed buy multiple dimensions.

EagerFinderSql allows custom SQL to be specified when doing eager loading of associations through the :include option to find. This allows for purpose-constructed queries to be used and still result in a fully linked object model.