Permalink
Browse files

Refactor this to use a simple YAML file. Now to figure out why Cocoa …

…is choking on a dictionary key read...right now Railcar is broken :(
  • Loading branch information...
1 parent 2adb7a0 commit 0fd1ca631c159849731e3291a80b1e768f94359a @jm jm committed Apr 24, 2012
Showing with 24 additions and 17 deletions.
  1. +24 −17 Railcar/RCApplicationManager.rb
@@ -7,33 +7,41 @@
#
class RCApplicationManager
+ def appsFile
+ File.join((ENV['RAILCAR_PATH'] || NSBundle.mainBundle.bundlePath), "application.yml")
+ end
+
def applications
- NSUserDefaults.standardUserDefaults['railcar.linkedApplications'] ||= {}
- NSUserDefaults.standardUserDefaults['railcar.linkedApplications']
+ if File.exist?(appsFile)
+ YAML.load_file(appsFile)
+ else
+ saveApplicationsList({})
+ {}
+ end
+ end
+
+ def saveApplicationsList(data)
+ File.open(appsFile, "w") do |f|
+ f.write(YAML.dump(data))
+ end
end
# We do the persistentDomainForName song and dance so the CLI can use this same code
def addApplicationToList(data)
- defaults = NSUserDefaults.standardUserDefaults.persistentDomainForName("com.arcturo.railcar")
+ newAppData = {}
+ newAppData[uniqueId(data)] = data
- hsh = defaults.dup
- hsh['railcar.linkedApplications'][uniqueId(data)] = data
-
- NSUserDefaults.standardUserDefaults.setPersistentDomain(hsh, forName: "com.arcturo.railcar")
+ saveApplicationsList(applications.merge(newAppData))
end
def appDataForPath(path)
- appList = NSUserDefaults.standardUserDefaults.persistentDomainForName("com.arcturo.railcar")['railcar.linkedApplications']
-
- appList.values.select do |data|
+ applications.values.select do |data|
data[:path] == path
end.first
end
def appDataForName(name)
- appList = NSUserDefaults.standardUserDefaults.persistentDomainForName("com.arcturo.railcar")['railcar.linkedApplications']
-
- appList.values.select do |data|
+ applications.values.select do |data|
data[:name] == name
end.first
end
@@ -42,17 +50,16 @@ def uniqueId(data)
"#{Time.now.to_i}-#{data[:name].gsub(/\W/, '')}-#{data[:path].gsub(/\W/, '')}"
end
- # We do the persistentDomainForName song and dance so the CLI can use this same code
def add(path, data = {})
if isRailsApp?(path)
- defaults = NSUserDefaults.standardUserDefaults.persistentDomainForName("com.arcturo.railcar")
-
+ newAppPort = (applications.empty? ? (applications.length + 3001) : 3000)
+
addApplicationToList({
:name => discernAppName(path),
:path => path,
:rubyVersion => DEFAULT_RUBY_VERSION,
:environment => "development",
- :port => (defaults['railcar.linkedApplications'].length + 3001).to_s
+ :port => ().to_s
}.merge(data))
true

0 comments on commit 0fd1ca6

Please sign in to comment.