Module: DmCutieUI

Defined in:
lib/dm-cutie-ui.rb,
lib/dm-cutie-ui/server.rb,
lib/dm-cutie-ui/version.rb

Defined Under Namespace

Classes: Server

Constant Summary collapse

VERSION =
'0.4.0'.freeze

Class Method Summary collapse

Class Method Details

.connect(connection) ⇒ String

  • connect - Connects to a datamapper repository This takes the password as an additional parameter for ‘security’ reasons since it caches all connection strings for a user

Parameters:

  • connection (Hash)
    • string [String] connection string

    • password [String] connection password

Returns:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/dm-cutie-ui.rb', line 55

def connect( connection )        
  connection_options = DataMapper::Adapters.send(:normalize_options, connection[:string])

  # Cache this before adding the password if the person decided they didn't want it cached by leaving it out
  normalized_uri = begin
    query = connection_options.except(:adapter, :user, :password, :host, :port, :path, :fragment, :scheme, :query, :username, :database)
    query = nil if query.empty?

    DataObjects::URI.new(
      connection_options[:adapter],
      connection_options[:user] || connection_options[:username],
      nil, #Dont put the password in the cache
      connection_options[:host],
      connection_options[:port],
      connection_options[:path] || connection_options[:database],
      query,
      connection_options[:fragment]
    )
  end
  
  # Create a hash of the normalized_uri
  token   = Digest::MD5.hexdigest(normalized_uri.to_s).to_sym

  # Cache the uri
  DmCutieUI.repos[token] = normalized_uri.to_s

  # Add the password if it was provided
  connection_options[:password] = connection[:password] unless connection[:password].blank?
  
  adapter = DataMapper::Adapters.new token, connection_options

  DataMapper::Repository.adapters[adapter.name] = adapter
  
  if DataMapper::Cutie.valid_repo? adapter.name
    return token
  else
    return false
  end
end

.loggerObject



26
27
28
# File 'lib/dm-cutie-ui.rb', line 26

def logger
  @_logger ||= Logger.new(STDOUT)
end

.reposString

  • repos - Cache of connection strings used since boot time

Returns:

  • (String)

    connection string



41
42
43
# File 'lib/dm-cutie-ui.rb', line 41

def repos
  @__repos ||= {}
end

.rootObject



95
96
97
# File 'lib/dm-cutie-ui.rb', line 95

def root
  @_root_path ||= File.expand_path(File.dirname(__FILE__)) / 'dm-cutie-ui'
end

.routesObject

  • routes - Routes for cutie models



34
35
36
# File 'lib/dm-cutie-ui.rb', line 34

def routes
  @__routes ||={}
end

.view_rootObject



29
30
31
# File 'lib/dm-cutie-ui.rb', line 29

def view_root
  @_view_root ||= File.join('', 'tmp', 'dm-cutie-ui', Time.now.to_i.to_s)
end