lib/firebase/firebase.rb in motion-firebase-2.1.1 vs lib/firebase/firebase.rb in motion-firebase-2.1.2

- old
+ new

@@ -33,24 +33,32 @@ setDispatchQueue(queue) end # @example # firebase = Firebase.new('http://..../') - # firebase.auth('secretkey', completion: ->{}, disconnect:{}) + # firebase.auth('secretkey') do + # # connected + # end + # firebase.auth('secretkey', disconnect: ->{}) do + # # connected + # end + # firebase.auth('secretkey', completion: ->{}, disconnect: ->{}) # # => firebase.authWithCredential(credential) def auth(credential, options={}, &and_then) - and_then = and_then || options[:completion] + and_then ||= options[:completion] disconnect_block = options[:disconnect] authWithCredential(credential, withCompletionBlock: and_then, withCancelBlock: disconnect_block) return self end + alias_method :old_unauth, :unauth + def unauth(&block) - if block + if block_given? unauthWithCompletionBlock(block) else - super() + old_unauth end end def auth_state self.root['.info/authenticated'] @@ -76,17 +84,17 @@ def transaction(options={}, &transaction) transaction = transaction || options[:transaction] completion_block = options[:completion] with_local_events = options[:local] if with_local_events.nil? - if completion_block + if block_given? runTransactionBlock(transaction, andCompletionBlock: completion_block) else runTransactionBlock(transaction) end else - if completion_block + if block_given? runTransactionBlock(transaction, andCompletionBlock: completion_block, withLocalEvents: with_local_events) else runTransactionBlock(transaction, withLocalEvents: with_local_events) end end @@ -115,11 +123,11 @@ def []=(key, value) childByAppendingPath(key).set(value) end def clear!(&and_then) - if and_then + if block_given? removeValueWithCompletionBlock(and_then) else removeValue end return self @@ -140,11 +148,11 @@ def value=(value) setValue(value) end def set(value, &and_then) - if and_then + if block_given? setValue(value, withCompletionBlock: and_then) else setValue(value) end return self @@ -153,38 +161,38 @@ def priority=(value) priority(value) end def priority(value, &and_then) - if and_then + if block_given? setPriority(value, withCompletionBlock: and_then) else setPriority(value) end return self end def set(value, priority: priority, &and_then) - if and_then + if block_given? setValue(value, andPriority: priority, withCompletionBlock: and_then) else setValue(value, andPriority: priority) end return self end def update(values, &and_then) - if and_then + if block_given? updateChildValues(values, withCompletionBlock: and_then) else updateChildValues(values) end return self end def cancel_disconnect(&and_then) - if and_then + if block_given? cancelDisconnectOperationsWithCompletionBlock(and_then) else cancelDisconnectOperations end return self @@ -194,11 +202,11 @@ def on_auth(options={}, &block) auth_state.on(:value, options, &block) end def on_disconnect(value, &and_then) - if and_then + if block_given? if value.nil? onDisconnectRemoveValueWithCompletionBlock(and_then) elsif NSDictionary === value onDisconnectUpdateChildValues(value, withCompletionBlock: and_then) else @@ -215,10 +223,10 @@ end return self end def on_disconnect(value, priority: priority, &and_then) - if and_then + if block_given? onDisconnectSetValue(value, andPriority: priority, withCompletionBlock: and_then) else onDisconnectSetValue(value, andPriority: priority) end return self