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 35 36 37 |
# File 'lib/firebase/firebase.rb', line 32 def self.dispatch_queue=(queue) if queue.is_a?(Dispatch::Queue) queue = queue.dispatch_object end 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
139 140 141 142 143 |
# File 'lib/firebase/firebase.rb', line 139 def <<(value) ref = childByAutoId ref.set(value) return ref end |
#[](*names) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/firebase/firebase.rb', line 114 def [](*names) if names.length == 0 childByAutoId else childByAppendingPath(names.join('/')) end end |
#[]=(key, value) ⇒ Object
126 127 128 |
# File 'lib/firebase/firebase.rb', line 126 def []=(key, value) childByAppendingPath(key).set(value) end |
#auth(credential, options = {}, &and_then) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/firebase/firebase.rb', line 49 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
66 67 68 |
# File 'lib/firebase/firebase.rb', line 66 def auth_state self.root['.info/authenticated'] end |
#cancel_disconnect(&and_then) ⇒ Object
195 196 197 198 199 200 201 202 |
# File 'lib/firebase/firebase.rb', line 195 def cancel_disconnect(&and_then) if block_given? cancelDisconnectOperationsWithCompletionBlock(and_then) else cancelDisconnectOperations end return self end |
#child(name) ⇒ Object
122 123 124 |
# File 'lib/firebase/firebase.rb', line 122 def child(name) childByAppendingPath(name) end |
#clear!(&and_then) ⇒ Object
130 131 132 133 134 135 136 137 |
# File 'lib/firebase/firebase.rb', line 130 def clear!(&and_then) if block_given? removeValueWithCompletionBlock(and_then) else removeValue end return self end |
#connected_state ⇒ Object
70 71 72 |
# File 'lib/firebase/firebase.rb', line 70 def connected_state self.root['.info/connected'] end |
#inspect ⇒ Object
243 244 245 |
# File 'lib/firebase/firebase.rb', line 243 def inspect "#<#{self.class}:0x#{self.object_id.to_s(16)}>" end |
#offline! ⇒ Object
74 75 76 |
# File 'lib/firebase/firebase.rb', line 74 def offline! goOffline end |
#old_unauth ⇒ Object
56 |
# File 'lib/firebase/firebase.rb', line 56 alias_method :old_unauth, :unauth |
#on_auth(options = {}, &block) ⇒ Object
Calls the block when the value is true
205 206 207 |
# File 'lib/firebase/firebase.rb', line 205 def on_auth(={}, &block) auth_state.on(:value, , &block) end |
#on_disconnect(value, priority: priority, &and_then) ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/firebase/firebase.rb', line 209 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
78 79 80 |
# File 'lib/firebase/firebase.rb', line 78 def online! goOnline end |
#priority(value, &and_then) ⇒ Object
168 169 170 171 172 173 174 175 |
# File 'lib/firebase/firebase.rb', line 168 def priority(value, &and_then) if block_given? setPriority(value, withCompletionBlock: and_then) else setPriority(value) end return self end |
#priority=(value) ⇒ Object
164 165 166 |
# File 'lib/firebase/firebase.rb', line 164 def priority=(value) priority(value) end |
#push(value, &and_then) ⇒ Object
145 146 147 148 149 |
# File 'lib/firebase/firebase.rb', line 145 def push(value, &and_then) ref = childByAutoId ref.set(value, &and_then) return ref end |
#run(options = {}, &transaction) ⇒ Object
82 83 84 85 |
# File 'lib/firebase/firebase.rb', line 82 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
155 156 157 158 159 160 161 162 |
# File 'lib/firebase/firebase.rb', line 155 def set(value, &and_then) if block_given? setValue(value, withCompletionBlock: and_then) else setValue(value) end return self end |
#to_s ⇒ Object
239 240 241 |
# File 'lib/firebase/firebase.rb', line 239 def to_s description end |
#transaction(options = {}, &transaction) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/firebase/firebase.rb', line 87 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
58 59 60 61 62 63 64 |
# File 'lib/firebase/firebase.rb', line 58 def unauth(&block) if block_given? unauthWithCompletionBlock(block) else old_unauth end end |
#update(values, &and_then) ⇒ Object
186 187 188 189 190 191 192 193 |
# File 'lib/firebase/firebase.rb', line 186 def update(values, &and_then) if block_given? updateChildValues(values, withCompletionBlock: and_then) else updateChildValues(values) end return self end |
#value=(value) ⇒ Object
151 152 153 |
# File 'lib/firebase/firebase.rb', line 151 def value=(value) setValue(value) end |