Sha256: d16acf288e4eab0c90d744da1ee0ad9e88cfe512963936cdb37825b89918c7cf

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

#!/usr/bin/env ruby
require File.expand_path(File.dirname(__FILE__) + '/../spec/spec_helper')
require 'sqlite3'
require 'activerecord'

ActiveRecord::Base.establish_connection(
  :adapter  => 'sqlite3',
  :database => "examples/active_record/active_record.sqlite3"
)

class Waypoint < ActiveRecord::Base
  include ROXML

  belongs_to :route

  xml_attr :isLeg
  xml_attr :lonlatx
  xml_attr :lonlaty
  xml_attr :gridReference
  xml_attr :ascent
  xml_attr :descent
  xml_attr :distance
  xml_attr :bearing
  xml_attr :timemins
end

class Route < ActiveRecord::Base
  include ROXML

  has_many :waypoints

  xml_attr :title
  xml_attr :totalDist
  xml_attr :totalMins
  xml_attr :totalHg
  xml_attr :lonlatx
  xml_attr :lonlaty
  xml_attr :grcenter

  xml_attr :waypoints, :as => [Waypoint], :in => "waypoints"
end

# do a quick pseudo migration.  This should only get executed on the first run
if !Waypoint.table_exists?
  ActiveRecord::Base.connection.create_table(:waypoints) do |t|
    t.column :route_id, :integer
    t.column :isLeg, :string
    t.column :lonlatx, :string
    t.column :lonlaty, :string
    t.column :gridReference, :string
    t.column :ascent, :string
    t.column :descent, :string
    t.column :distance, :string
    t.column :bearing, :string
    t.column :timeMins, :string
  end
end

if !Route.table_exists?
  ActiveRecord::Base.connection.create_table(:routes) do |t|
    t.column :title, :string
    t.column :totalDist, :string
    t.column :totalMins, :string
    t.column :totalHg, :string
    t.column :lonlatx, :string
    t.column :lonlaty, :string
    t.column :grcenter, :string
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roxml-2.5.0 examples/active_record.rb