Module: Medea

Defined in:
lib/medea/jasonobject.rb,
lib/medea.rb,
lib/medea/jasondb.rb,
lib/medea/version.rb,
lib/medea/jason_base.rb,
lib/medea/jasonlistproperty.rb,
lib/medea/jasondeferredquery.rb,
lib/medea/active_model_methods.rb

Overview

Medea/JasonObject - Written by Michael Jensen

Defined Under Namespace

Modules: ActiveModelMethods Classes: JasonBase, JasonDeferredQuery, JasonListProperty, JasonObject

Constant Summary collapse

LOGGER =
DummyLogger.new
VERSION =
"0.6.9"
TEMPLATE_VERSION =

When the templates are changed, this version should be incremented This version is used when uploading/updating the templates

"1.1.0"

Class Method Summary collapse

Class Method Details

.setup_templates(url = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/medea/jasondb.rb', line 33

def Medea::setup_templates url=nil
  template_dir = File.expand_path("./templates", File.dirname(__FILE__))
  name_pattern = /([A-Za-z]+)\.template/
  headers = {:content_type => 'text/plain',
             'X-VERSION' => TEMPLATE_VERSION}
  curr_version = TEMPLATE_VERSION.split "."
  base_url = url ? url : JasonDB::db_auth_url
  Dir.glob(File.expand_path(File.join(template_dir, "*.template"))).select do |file|
    #for each template, we need to post it to ..#{filename}:html_template
    file =~ name_pattern
    template_path = "#{base_url}..#{$1}:html_template"

    #but,check the version first...
    begin
      r = RestClient.get template_path
      if r.code == 200 && r.headers[:http_x_version]
        version = r.headers[:http_x_version].split(".")
        version.each_index do |i|
          if version[i] < curr_version[i]
            RestClient.post template_path, File.read(file), headers
            break
          elsif version[i] > curr_version[i]
            raise "The remote templates are newer than the local ones! Update your gem!"
          end
        end
        next
      end

    rescue RestClient::ResourceNotFound
      #do nothing, it just means that the templates aren't uploaded yet.
    end
    RestClient.post template_path, File.read(file), headers
  end
end