module Schemas

Public Class Methods

const_missing(name) click to toggle source
# File lib/json_column.rb, line 17
def self.const_missing(name)
  self.const_set(name, self.load_schema_file(name))
end
load_schema_file(name) click to toggle source
# File lib/json_column.rb, line 21
def self.load_schema_file(name)
  file = Dir["#{Rails.root}/app/models/schemas/#{name.to_s.underscore}*"].select {|f| f =~ /.*.(json|ya?ml)\z/ }
  if file.blank?
    raise "no such schema defined: #{name}"
  end
  sch = YAML.load_file(file[0]).with_indifferent_access

  # if we did find the schema file we create a module
  # with the schema accessible in the schema method
  # this looks like if the yml file is in fact a ruby
  # module.
  Module.new do
    @schema = sch
    def self.schema
      @schema
    end
  end
end
schema() click to toggle source
# File lib/json_column.rb, line 34
def self.schema
  @schema
end