--- /dev/null
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
--- /dev/null
+// Place all the styles related to the metadata controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
--- /dev/null
+class MetadataController < ApplicationController
+end
--- /dev/null
+module MetadataHelper
+end
--- /dev/null
+class Metadatum < ActiveRecord::Base
+ serialize :info, Hash
+
+ before_validation :populate_native_target
+ include AssignUuid
+
+ def info
+ @info ||= Hash.new
+ super
+ end
+
+ protected
+
+ def populate_native_target
+ begin
+ class_name = target_kind.
+ sub(/^orvos#/,'').
+ classify
+ self.native_target_type = class_name
+ self.native_target_id = class_name.
+ constantize.
+ where('uuid = ?', target_uuid).
+ first.
+ id
+ rescue
+ self.native_target_type = nil
+ self.native_target_id = nil
+ end
+ end
+end
require File.expand_path('../boot', __FILE__)
require 'rails/all'
+require 'digest'
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
config.middleware.use Rack::Static, :urls => [ '/discovery' ], :root => "public"
config.force_ssl = true
+
+ config.uuid_prefix = Digest::MD5.hexdigest('CHANGE-ME').to_i(16).to_s(36)[0..4]
end
end
--- /dev/null
+require 'assign_uuid'
Server::Application.routes.draw do
+ resources :metadata
+
resources :collections
# The priority is based upon order of creation:
--- /dev/null
+class CreateMetadata < ActiveRecord::Migration
+ def change
+ create_table :metadata do |t|
+ t.string :uuid
+ t.string :created_by_client
+ t.string :created_by_user
+ t.datetime :created_at
+ t.string :modified_by_client
+ t.string :modified_by_user
+ t.datetime :modified_at
+ t.string :target_uuid
+ t.string :target_kind
+ t.references :native_target, :polymorphic => true
+ t.string :metadatum_class
+ t.string :key
+ t.string :value
+ t.text :info # "unlimited length" in postgresql
+
+ t.timestamps
+ end
+ end
+end
+# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20121016005009) do
+ActiveRecord::Schema.define(:version => 20130105203021) do
create_table "collections", :force => true do |t|
t.string "locator"
t.datetime "updated_at"
end
+ create_table "metadata", :force => true do |t|
+ t.string "uuid"
+ t.string "created_by_client"
+ t.string "created_by_user"
+ t.datetime "created_at"
+ t.string "modified_by_client"
+ t.string "modified_by_user"
+ t.datetime "modified_at"
+ t.string "target_uuid"
+ t.string "target_kind"
+ t.integer "native_target_id"
+ t.string "native_target_type"
+ t.string "metadatum_class"
+ t.string "key"
+ t.string "value"
+ t.text "info"
+ t.datetime "updated_at"
+ end
+
end
--- /dev/null
+module AssignUuid
+
+ def self.included(base)
+ base.extend(ClassMethods)
+ base.validates_presence_of :uuid, :if => :respond_to_uuid?
+ base.validates_uniqueness_of :uuid, :if => :respond_to_uuid?
+ base.before_validation :assign_uuid
+ end
+
+ module ClassMethods
+ def uuid_prefix
+ Digest::MD5.hexdigest(self.to_s).to_i(16).to_s(36)[0..4]
+ end
+ end
+
+ protected
+
+ def respond_to_uuid?
+ self.respond_to? :uuid
+ end
+
+ def assign_uuid
+ return true if !self.respond_to_uuid?
+ self.uuid ||= [Server::Application.config.uuid_prefix,
+ self.class.uuid_prefix,
+ rand(2**256).to_s(36)[0..14]].
+ join '-'
+ end
+end
--- /dev/null
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
--- /dev/null
+require 'test_helper'
+
+class MetadataControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
--- /dev/null
+require 'test_helper'
+
+class MetadataHelperTest < ActionView::TestCase
+end
--- /dev/null
+require 'test_helper'
+
+class MetadatumTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end