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
-
.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.
-
- .logger ⇒ Object
-
.repos ⇒ String
-
repos - Cache of connection strings used since boot time.
-
- .root ⇒ Object
-
.routes ⇒ Object
-
routes - Routes for cutie models.
-
- .view_root ⇒ Object
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
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 ) = 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 = .except(:adapter, :user, :password, :host, :port, :path, :fragment, :scheme, :query, :username, :database) query = nil if query.empty? DataObjects::URI.new( [:adapter], [:user] || [:username], nil, #Dont put the password in the cache [:host], [:port], [:path] || [:database], query, [: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 [:password] = connection[:password] unless connection[:password].blank? adapter = DataMapper::Adapters.new token, DataMapper::Repository.adapters[adapter.name] = adapter if DataMapper::Cutie.valid_repo? adapter.name return token else return false end end |
.logger ⇒ Object
26 27 28 |
# File 'lib/dm-cutie-ui.rb', line 26 def logger @_logger ||= Logger.new(STDOUT) end |
.repos ⇒ String
-
repos - Cache of connection strings used since boot time
41 42 43 |
# File 'lib/dm-cutie-ui.rb', line 41 def repos @__repos ||= {} end |
.root ⇒ Object
95 96 97 |
# File 'lib/dm-cutie-ui.rb', line 95 def root @_root_path ||= File.(File.dirname(__FILE__)) / 'dm-cutie-ui' end |
.routes ⇒ Object
-
routes - Routes for cutie models
34 35 36 |
# File 'lib/dm-cutie-ui.rb', line 34 def routes @__routes ||={} end |
.view_root ⇒ Object
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 |