Class: Firebase

Inherits:
Object
  • Object
show all
Defined in:
lib/firebase/firebase.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.convert_event_type(event_type) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/firebase/firebase.rb', line 3

def self.convert_event_type(event_type)
  case event_type
  when :child_added, :added
    return FEventTypeChildAdded
  when :child_moved, :moved
    FEventTypeChildMoved
  when :child_changed, :changed
    return FEventTypeChildChanged
  when :child_removed, :removed
    return FEventTypeChildRemoved
  when :value
    return FEventTypeValue
  else
    NSLog("Unknown event type #{event_type.inspect}")
  end
  return event_type
end

.dispatch_queue=(queue) ⇒ Object

Examples:

Firebase.dispatch_queue(queue)
# => Firebase.setDispatchQueue(queue)


28
29
30
# File 'lib/firebase/firebase.rb', line 28

def self.dispatch_queue=(queue)
  setDispatchQueue(queue)
end

.new(url) ⇒ Object



21
22
23
# File 'lib/firebase/firebase.rb', line 21

def self.new(url)
  alloc.initWithUrl(url)
end

Instance Method Details

#<<(value) ⇒ Object



91
92
93
94
95
# File 'lib/firebase/firebase.rb', line 91

def <<(value)
  ref = childByAutoId
  ref.update(value)
  return ref
end

#[](*names) ⇒ Object

Examples:

firebase = Firebase.new('http://..../')
firebase[]  # => childByAutoId
firebase['fred']  # => childByAppendingPath('fred')
firebase['fred', 'name', 'first']  # => childByAppendingPath('fred/name/first')
firebase['fred']['name']['first']
# => childByAppendingPath('fred').childByAppendingPath('name').childByAppendingPath('first'),
# same as => childByAppendingPath('fred/name/first')


70
71
72
73
74
75
76
# File 'lib/firebase/firebase.rb', line 70

def [](*names)
  if names.length == 0
    childByAutoId
  else
    childByAppendingPath(names.join('/'))
  end
end

#[]=(key, value) ⇒ Object



78
79
80
# File 'lib/firebase/firebase.rb', line 78

def []=(key, value)
  childByAppendingPath(key).set(value)
end

#auth(credential, options = {}, &and_then) ⇒ Object

Examples:

firebase = Firebase.new('http://..../')
firebase.auth('secretkey', then: ->{}, disconnect:{})
# => firebase.authWithCredential(credential)


36
37
38
39
40
41
# File 'lib/firebase/firebase.rb', line 36

def auth(credential, options={}, &and_then)
  and_then = and_then || options[:completion]
  disconnect_block = options[:disconnect]
  authWithCredential(credential, withCompletionBlock:and_then, withCancelBlock:disconnect_block)
  return self
end

#auth_stateObject



43
44
45
# File 'lib/firebase/firebase.rb', line 43

def auth_state
  self.root[".info/authenticated"]
end

#cancel_disconnect(&and_then) ⇒ Object



141
142
143
144
145
146
147
148
# File 'lib/firebase/firebase.rb', line 141

def cancel_disconnect(&and_then)
  if and_then
    cancelDisconnectOperationsWithCompletionBlock(and_then)
  else
    cancelDisconnectOperations
  end
  return self
end

#clear!(&and_then) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/firebase/firebase.rb', line 82

def clear!(&and_then)
  if and_then
    removeValueWithCompletionBlock(and_then)
  else
    removeValue
  end
  return self
end

#inspectObject



184
185
186
# File 'lib/firebase/firebase.rb', line 184

def inspect
  "#<#{self.class}:0x#{self.object_id.to_s(16)}>"
end

#on_auth(options = {}, &block) ⇒ Object



150
151
152
# File 'lib/firebase/firebase.rb', line 150

def on_auth(options={}, &block)
  auth_state.on(:value, options, &block)
end

#on_disconnect(value, priority: priority, &and_then) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/firebase/firebase.rb', line 154

def on_disconnect(value, &and_then)
  if and_then
    if value.nil?
      onDisconnectRemoveValueWithCompletionBlock(and_then)
    elsif NSDictionary === value
      onDisconnectUpdateChildValues(value, withCompletionBlock:and_then)
    else
      onDisconnectSetValue(value, withCompletionBlock:and_then)
    end
  else
    if value == :remove
      onDisconnectRemoveValue
    elsif NSDictionary === value
      onDisconnectUpdateChildValues(value)
    else
      onDisconnectSetValue(value)
    end
  end
  return self
end

#priority(value, &and_then) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/firebase/firebase.rb', line 114

def priority(value, &and_then)
  if and_then
    setPriority(value, withCompletionBlock:and_then)
  else
    setPriority(value)
  end
  return self
end

#priority=(value) ⇒ Object



110
111
112
# File 'lib/firebase/firebase.rb', line 110

def priority=(value)
  priority(value)
end

#run(options = {}, &transaction) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/firebase/firebase.rb', line 47

def run(options={}, &transaction)
  transaction = transaction || options[:transaction]
  completion_block = options[:completion]
  with_local_events = options[:local]
  if with_local_events.nil?
    if completion_block
      runTransactionBlock(transaction, andCompletionBlock:completion_block)
    else
      runTransactionBlock(transaction)
    end
  else
    runTransactionBlock(transaction, andCompletionBlock:completion_block, withLocalEvents:with_local_events)
  end
end

#set(value, priority: priority, &and_then) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/firebase/firebase.rb', line 101

def set(value, &and_then)
  if and_then
    setValue(value, withCompletionBlock:and_then)
  else
    setValue(value)
  end
  return self
end

#update(values, &and_then) ⇒ Object



132
133
134
135
136
137
138
139
# File 'lib/firebase/firebase.rb', line 132

def update(values, &and_then)
  if and_then
    updateChildValues(values, withCompletionBlock:and_then)
  else
    updateChildValues(values)
  end
  return self
end

#value=(value) ⇒ Object



97
98
99
# File 'lib/firebase/firebase.rb', line 97

def value=(value)
  setValue(value)
end