Class: Firebase
- Inherits:
-
Object
- Object
- Firebase
- Defined in:
- lib/firebase/firebase.rb
Constant Summary collapse
- ERRORS =
{ -9999 => :email_in_use, -2 => :wrong_password, }
Class Method Summary collapse
Instance Method Summary collapse
- #<<(value) ⇒ Object
- #[](*names) ⇒ Object
- #[]=(key, value) ⇒ Object
- #auth(credential, options = {}, &and_then) ⇒ Object
- #auth_state ⇒ Object
- #cancel_disconnect(&and_then) ⇒ Object
- #child(name) ⇒ Object
- #clear!(&and_then) ⇒ Object
- #connected_state ⇒ Object
- #inspect ⇒ Object
- #offline! ⇒ Object
- #old_unauth ⇒ Object
-
#on_auth(options = {}, &block) ⇒ Object
Calls the block when the value is true.
- #on_disconnect(value, priority: priority, &and_then) ⇒ Object
- #online! ⇒ Object
- #priority(value, &and_then) ⇒ Object
- #priority=(value) ⇒ Object
- #push(value, &and_then) ⇒ Object
- #run(options = {}, &transaction) ⇒ Object
- #set(value, priority: priority, &and_then) ⇒ Object
- #to_s ⇒ Object
- #transaction(options = {}, &transaction) ⇒ Object
- #unauth(&block) ⇒ Object
- #update(values, &and_then) ⇒ Object
- #value=(value) ⇒ Object
Class Method Details
.convert_event_type(event_type) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/firebase/firebase.rb', line 7 def self.convert_event_type(event_type) case event_type when :child_added, :added, FEventTypeChildAdded return FEventTypeChildAdded when :child_moved, :moved, FEventTypeChildMoved return FEventTypeChildMoved when :child_changed, :changed, FEventTypeChildChanged return FEventTypeChildChanged when :child_removed, :removed, FEventTypeChildRemoved return FEventTypeChildRemoved when :value, FEventTypeValue return FEventTypeValue else NSLog("Unknown event type #{event_type.inspect}") end return event_type end |
.dispatch_queue=(queue) ⇒ Object
32 33 34 |
# File 'lib/firebase/firebase.rb', line 32 def self.dispatch_queue=(queue) setDispatchQueue(queue) end |
.new(url) ⇒ Object
25 26 27 |
# File 'lib/firebase/firebase.rb', line 25 def self.new(url) alloc.initWithUrl(url) end |
Instance Method Details
#<<(value) ⇒ Object
136 137 138 139 140 |
# File 'lib/firebase/firebase.rb', line 136 def <<(value) ref = childByAutoId ref.set(value) return ref end |
#[](*names) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/firebase/firebase.rb', line 111 def [](*names) if names.length == 0 childByAutoId else childByAppendingPath(names.join('/')) end end |
#[]=(key, value) ⇒ Object
123 124 125 |
# File 'lib/firebase/firebase.rb', line 123 def []=(key, value) childByAppendingPath(key).set(value) end |
#auth(credential, options = {}, &and_then) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/firebase/firebase.rb', line 46 def auth(credential, ={}, &and_then) and_then ||= [:completion] disconnect_block = [:disconnect] authWithCredential(credential, withCompletionBlock: and_then, withCancelBlock: disconnect_block) return self end |
#auth_state ⇒ Object
63 64 65 |
# File 'lib/firebase/firebase.rb', line 63 def auth_state self.root['.info/authenticated'] end |
#cancel_disconnect(&and_then) ⇒ Object
192 193 194 195 196 197 198 199 |
# File 'lib/firebase/firebase.rb', line 192 def cancel_disconnect(&and_then) if block_given? cancelDisconnectOperationsWithCompletionBlock(and_then) else cancelDisconnectOperations end return self end |
#child(name) ⇒ Object
119 120 121 |
# File 'lib/firebase/firebase.rb', line 119 def child(name) childByAppendingPath(name) end |
#clear!(&and_then) ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/firebase/firebase.rb', line 127 def clear!(&and_then) if block_given? removeValueWithCompletionBlock(and_then) else removeValue end return self end |
#connected_state ⇒ Object
67 68 69 |
# File 'lib/firebase/firebase.rb', line 67 def connected_state self.root['.info/connected'] end |
#inspect ⇒ Object
240 241 242 |
# File 'lib/firebase/firebase.rb', line 240 def inspect "#<#{self.class}:0x#{self.object_id.to_s(16)}>" end |
#offline! ⇒ Object
71 72 73 |
# File 'lib/firebase/firebase.rb', line 71 def offline! goOffline end |
#old_unauth ⇒ Object
53 |
# File 'lib/firebase/firebase.rb', line 53 alias_method :old_unauth, :unauth |
#on_auth(options = {}, &block) ⇒ Object
Calls the block when the value is true
202 203 204 |
# File 'lib/firebase/firebase.rb', line 202 def on_auth(={}, &block) auth_state.on(:value, , &block) end |
#on_disconnect(value, priority: priority, &and_then) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/firebase/firebase.rb', line 206 def on_disconnect(value, &and_then) if block_given? if value.nil? onDisconnectRemoveValueWithCompletionBlock(and_then) elsif NSDictionary === value onDisconnectUpdateChildValues(value, withCompletionBlock: and_then) else onDisconnectSetValue(value, withCompletionBlock: and_then) end else if value.nil? onDisconnectRemoveValue elsif NSDictionary === value onDisconnectUpdateChildValues(value) else onDisconnectSetValue(value) end end return self end |
#online! ⇒ Object
75 76 77 |
# File 'lib/firebase/firebase.rb', line 75 def online! goOnline end |
#priority(value, &and_then) ⇒ Object
165 166 167 168 169 170 171 172 |
# File 'lib/firebase/firebase.rb', line 165 def priority(value, &and_then) if block_given? setPriority(value, withCompletionBlock: and_then) else setPriority(value) end return self end |
#priority=(value) ⇒ Object
161 162 163 |
# File 'lib/firebase/firebase.rb', line 161 def priority=(value) priority(value) end |
#push(value, &and_then) ⇒ Object
142 143 144 145 146 |
# File 'lib/firebase/firebase.rb', line 142 def push(value, &and_then) ref = childByAutoId ref.set(value, &and_then) return ref end |
#run(options = {}, &transaction) ⇒ Object
79 80 81 82 |
# File 'lib/firebase/firebase.rb', line 79 def run(={}, &transaction) NSLog('The method ‘Firebase#run’ has been deprecated in favor of ‘Firebase#transaction’') self.transaction(, &transaction) end |
#set(value, priority: priority, &and_then) ⇒ Object
152 153 154 155 156 157 158 159 |
# File 'lib/firebase/firebase.rb', line 152 def set(value, &and_then) if block_given? setValue(value, withCompletionBlock: and_then) else setValue(value) end return self end |
#to_s ⇒ Object
236 237 238 |
# File 'lib/firebase/firebase.rb', line 236 def to_s description end |
#transaction(options = {}, &transaction) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/firebase/firebase.rb', line 84 def transaction(={}, &transaction) transaction = transaction || [:transaction] completion_block = [:completion] with_local_events = [:local] if with_local_events.nil? if block_given? runTransactionBlock(transaction, andCompletionBlock: completion_block) else runTransactionBlock(transaction) end else if block_given? runTransactionBlock(transaction, andCompletionBlock: completion_block, withLocalEvents: with_local_events) else runTransactionBlock(transaction, withLocalEvents: with_local_events) end end end |
#unauth(&block) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/firebase/firebase.rb', line 55 def unauth(&block) if block_given? unauthWithCompletionBlock(block) else old_unauth end end |
#update(values, &and_then) ⇒ Object
183 184 185 186 187 188 189 190 |
# File 'lib/firebase/firebase.rb', line 183 def update(values, &and_then) if block_given? updateChildValues(values, withCompletionBlock: and_then) else updateChildValues(values) end return self end |
#value=(value) ⇒ Object
148 149 150 |
# File 'lib/firebase/firebase.rb', line 148 def value=(value) setValue(value) end |