Skip to content
Browse files

Make environments a static module variable for Application.

- Retains the static variable so it's not collected.
- Works around GC problems with initialization and attributes for Application.
  • Loading branch information...
1 parent dbe0303 commit 279d7d6cf6bb69397862399d59402f1f97f1a388 @Manfred Manfred committed Jan 11, 2011
View
10 .kick
@@ -12,10 +12,12 @@ module Nu
end
process do |files|
- # Ruby.run_tests(files.take_and_map do |file|
- # case file
- # end
- # end)
+ Ruby.run_tests(files.take_and_map do |file|
+ case file
+ when %r{^test/ppane/test_helper/add_allow_switch.rb$}
+ 'test/ppane/test_helper/add_allow_switch_test.rb'
+ end
+ end)
Nu.run_tests(files.take_and_map do |file|
case file
View
4 Passenger.xcodeproj/project.pbxproj
@@ -481,7 +481,7 @@
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_64_BIT_PRE_XCODE_3_1)";
ARCHS_STANDARD_64_BIT_PRE_XCODE_3_1 = x86_64;
- GCC_ENABLE_OBJC_GC = required;
+ GCC_ENABLE_OBJC_GC = supported;
GCC_MODEL_PPC64 = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
@@ -496,7 +496,7 @@
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_64_BIT_PRE_XCODE_3_1)";
ARCHS_STANDARD_64_BIT_PRE_XCODE_3_1 = x86_64;
- GCC_ENABLE_OBJC_GC = required;
+ GCC_ENABLE_OBJC_GC = supported;
GCC_MODEL_PPC64 = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
View
2 app/controllers/PassengerPref.m
@@ -233,7 +233,7 @@ - (void) reloadApplications {
if (index != -1) {
existingApplication = [applications objectAtIndex:index];
if (![existingApplication isDirty]) {
- [existingApplication updateWithAttributes:[loadedApplication toDictionary]];
+ [existingApplication updateAttributes:[loadedApplication toDictionary]];
[existingApplication didApplyChanges];
}
// Someone added a new applications we didn't know about
View
4 app/models/Application.h
@@ -9,8 +9,6 @@ enum {
@interface Application : NSObject {
id delegate;
- NSArray *environments;
-
NSString *host, *aliases, *path, *configFilename;
NSUInteger environment;
BOOL dirty, valid, fresh;
@@ -28,7 +26,7 @@ enum {
- (id) initWithAttributes:(NSDictionary *)attributes;
- (id) initWithDirectory:(NSString *)aPath;
-- (void) updateWithAttributes:(NSDictionary *)attributes;
+- (void) updateAttributes:(NSDictionary *)attributes;
- (NSMutableDictionary*) toDictionary;
- (NSArray*) toArgumentArray;
- (void) validate;
View
36 app/models/Application.m
@@ -1,5 +1,6 @@
#import "Application.h"
+static NSArray *environments;
@implementation Application
@@ -9,10 +10,14 @@ @implementation Application
@synthesize dirty, valid, fresh;
@synthesize beforeChanges;
++(void) initialize {
+ if (!environments)
+ environments = [NSArray arrayWithObjects:@"development", @"production", nil];
+ [environments retain];
+}
+
- (id) init {
if (self = [super init]) {
- environments = [NSArray arrayWithObjects:@"development", @"production", nil];
-
self.host = @"";
self.aliases = @"";
self.path = @"";
@@ -21,13 +26,13 @@ - (id) init {
self.fresh = YES;
[self validate];
beforeChanges = [self toDictionary];
- }
- return self;
+ }
+ return self;
}
- (id) initWithAttributes:(NSDictionary *)attributes {
if (self = [self init]) {
- [self updateWithAttributes:attributes];
+ [self updateAttributes:attributes];
self.dirty = NO;
self.fresh = NO;
[self validate];
@@ -47,23 +52,29 @@ - (id) initWithDirectory:(NSString *)aPath {
return self;
}
-- (void) updateWithAttributes:(NSDictionary *)attributes {
- NSString *environment = [attributes objectForKey:@"environment"];
+- (void) updateAttributes:(NSDictionary *)attributes {
+ NSString *environmentAsString = [attributes objectForKey:@"environment"];
self.host = [attributes objectForKey:@"host"];
self.aliases = [attributes objectForKey:@"aliases"];
self.path = [attributes objectForKey:@"path"];
- if (environment)
- self.environment = [environments indexOfObject:environment];
+ if (environmentAsString) {
+ self.environment = [environments indexOfObject:environmentAsString];
+ } else {
+ self.environment = 0;
+ }
self.configFilename = [attributes objectForKey:@"config_filename"];
}
- (NSMutableDictionary*) toDictionary {
NSMutableDictionary *data = [NSMutableDictionary dictionary];
-
[data setValue:self.host forKey:@"host"];
[data setValue:self.aliases forKey:@"aliases"];
[data setValue:self.path forKey:@"path"];
- [data setValue:[environments objectAtIndex:environment] forKey:@"environment"];
+ if (environment) {
+ [data setValue:[environments objectAtIndex:environment] forKey:@"environment"];
+ } else {
+ [data setValue:[environments objectAtIndex:0] forKey:@"environment"];
+ }
[data setValue:self.configFilename forKey:@"config_filename"];
return data;
@@ -104,7 +115,7 @@ - (void) didApplyChanges {
}
- (void) revert {
- [self updateWithAttributes:beforeChanges];
+ [self updateAttributes:beforeChanges];
[self validate];
[self checkChanges];
}
@@ -117,7 +128,6 @@ - (void) setPath:(NSString *)newPath {
}
- (void) setValue:(id)value forKey:(NSString*)key {
- NSLog(@"Changing %@ to %@", key, value);
[super setValue:value forKey:key];
[self validate];
[self checkChanges];
View
25 test/passenger_pane/application_test.nu
@@ -23,6 +23,31 @@
(set application ((Application alloc) initWithAttributes:attributes))
(~ application host should be:"test.host")
))
+
+ (it "initializes with a directory" (do ()
+ (set directory "/path/to/test")
+ (set application ((Application alloc) initWithDirectory:directory))
+ (~ application path should be:directory)
+ (~ application host should be:"test.local")
+ ))
+
+ (it "updates its attributes" (do ()
+ (set application ((Application alloc) init))
+ (set attributes (NSMutableDictionary dictionary))
+ (attributes setValue:"test.host" forKey:"host")
+ (attributes setValue:"assets.test.host" forKey:"aliases")
+ (attributes setValue:"/path/to/test" forKey:"path")
+ (attributes setValue:"production" forKey:"environment")
+ (attributes setValue:"/path/to/test.conf" forKey:"config_filename")
+
+ (application updateAttributes:attributes)
+
+ (~ application host should be:"test.host")
+ (~ application aliases should be:"assets.test.host")
+ (~ application path should be:"/path/to/test")
+ (~ application environment should be:1)
+ (~ application configFilename should be:"/path/to/test.conf")
+ ))
))
((Bacon sharedInstance) run)

0 comments on commit 279d7d6

Please sign in to comment.
Something went wrong with that request. Please try again.