opal-firebase 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59858440f531b89e5573d8c091d6eedb2c7f8c6e
4
+ data.tar.gz: 78b1d82586365b797c4bc4850fdc8481826d7b3e
5
+ SHA512:
6
+ metadata.gz: 58b5571b225c829734f34658b4c080452fd55663403c4100be3f44868301299aa4519d1a4626ecf3f0c20293bd44cd9cdf30d75601013aec275e7f606fb0acf1
7
+ data.tar.gz: 954fd1a779e3e99967eaa9658ec0c73d0963ed04c6d3fe29cb13eb33eed708e24843b7f6d349f891d0a33e28db29bdc2b95779c6938c897fc4fb22e6e15753de
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # gem 'opal', :github => 'opal/opal'
4
+
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Gabriel Rios
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Opal::Firebase
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'opal-firebase'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install opal-firebase
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ # require 'opal/rspec/rake_task'
6
+
7
+ desc "Build build/opal-firebase.js"
8
+ task :dist do
9
+ require 'fileutils'
10
+ FileUtils.mkdir_p 'build'
11
+
12
+ src = Opal::Builder.build('opal-firebase')
13
+ min = uglify src
14
+ gzp = gzip min
15
+
16
+ File.open('build/opal-firebase.js', 'w+') do |out|
17
+ out << src
18
+ end
19
+
20
+ puts "development: #{src.size}, minified: #{min.size}, gzipped: #{gzp.size}"
21
+ end
22
+
23
+ # Used for uglifying source to minify
24
+ def uglify(str)
25
+ IO.popen('uglifyjs', 'r+') do |i|
26
+ i.puts str
27
+ i.close_write
28
+ return i.read
29
+ end
30
+ rescue Errno::ENOENT
31
+ $stderr.puts '"uglifyjs" command not found (install with: "npm install -g uglify-js")'
32
+ nil
33
+ end
34
+
35
+ # Gzip code to check file size
36
+ def gzip(str)
37
+ IO.popen('gzip -f', 'r+') do |i|
38
+ i.puts str
39
+ i.close_write
40
+ return i.read
41
+ end
42
+ rescue Errno::ENOENT
43
+ $stderr.puts '"gzip" command not found, it is required to produce the .gz version'
44
+ nil
45
+ end
@@ -0,0 +1 @@
1
+ require 'opal/firebase'
@@ -0,0 +1,4 @@
1
+ require 'opal'
2
+ require "opal/firebase/version"
3
+ Opal.append_path File.expand_path('../../../opal', __FILE__).untaint
4
+
@@ -0,0 +1,5 @@
1
+ module Opal
2
+ module Firebase
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'opal/firebase/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "opal-firebase"
8
+ spec.version = Opal::Firebase::VERSION
9
+ spec.authors = ["Gabriel Rios"]
10
+ spec.email = ["gabrielfalcaorios@gmail.com"]
11
+ spec.description = %q{Opal access to Firebase}
12
+ spec.summary = %q{Opal library for Firebase}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_runtime_dependency 'opal', '~> 0.6.0'
24
+ end
@@ -0,0 +1,3 @@
1
+ require 'opal-firebase/data_snapshot'
2
+ require 'opal-firebase/query'
3
+ require 'opal-firebase/firebase'
@@ -0,0 +1,78 @@
1
+ # TODO: Tests, look at https://github.com/opal/opal-jquery/blob/master/spec/event_spec.rb
2
+ # or not if its just delegates
3
+ #
4
+ class DataSnapshot
5
+ include Native
6
+
7
+ def initialize(_native)
8
+ super(_native)
9
+ end
10
+ #
11
+ # Get the Javascript object representation of the DataSnapshot.
12
+ def val
13
+ `#@native.val()`
14
+ end
15
+
16
+ # Get a Hash representantion of the data snapshot
17
+ # TODO: is hash if its an object
18
+ def value
19
+ Native(val)
20
+ end
21
+
22
+ # Get a DataSnapshot for the specified child location.
23
+ def child(childPath)
24
+ %x{ #{ DataSnapshot.new `#@native.child(childPath)` } }
25
+ end
26
+
27
+ # Enumerate through the DataSnapshot’s children.
28
+ #
29
+ def each_child(&block)
30
+ %x{
31
+ #@native.forEach(function(childSnap) {
32
+ #{block.call(DataSnapshot.new %x{childSnap})}
33
+ })
34
+ }
35
+ end
36
+
37
+ # Return true if the specified child exists.
38
+ def has_child?(childPath)
39
+ `#@native.hasChild(childPath)`
40
+ end
41
+
42
+ # Return true if this DataSnapshot has any children.
43
+ def has_children?
44
+ `#@native.hasChildren()`
45
+ end
46
+
47
+ # Get the name of this DataSnapshot's location.
48
+ def name
49
+ `#@native.name()`
50
+ end
51
+
52
+ # Get the number of children for this DataSnapshot.
53
+ def num_children
54
+ `#@native.numChildren()`
55
+ end
56
+
57
+ # Get the Firebase reference for this DataSnapshot's location.
58
+ def reference
59
+ %x{ #{ Firebase.new `#@native.ref().toString()` } }
60
+ end
61
+
62
+ # Get the priority of the data in this DataSnapshot.
63
+ def priority
64
+ `#@native.getPriority()`
65
+ end
66
+
67
+ def export_val # Export data as a Javascript object with priority information.
68
+ `#@native.exportVal()`
69
+ end
70
+
71
+ def inspect
72
+ "#<Firebase::Snapshot name:#{name} value:#{val}>"
73
+ end
74
+
75
+ def to_n
76
+ @native
77
+ end
78
+ end
@@ -0,0 +1,55 @@
1
+ # NOTE: should pass the to_n here
2
+ # TODO: Child should return a firebase instance
3
+ class Firebase < Query
4
+ include Native
5
+
6
+ attr_accessor :url
7
+
8
+ def initialize(url)
9
+ @url = url
10
+ super(ref)
11
+ end
12
+
13
+ def ref
14
+ `new Firebase(#{url})`
15
+ end
16
+
17
+ alias_native :authorize, :auth
18
+ alias_native :authorize_with_token, :authWithCustomToken
19
+ alias_native :unauthorize, :unauth
20
+ alias_native :transaction, :transaction
21
+ alias_native :parent, :parent
22
+ alias_native :root, :root
23
+ alias_native :name, :name
24
+ alias_native :set, :set
25
+ alias_native :update, :update
26
+ alias_native :remove, :remove
27
+ alias_native :set_with_priority, :setWithPriority
28
+ alias_native :priority=, :setPriority
29
+ alias_native :off, :off
30
+ alias_native :go_online, :goOnline
31
+ alias_native :go_offlien, :goOffline
32
+ alias_native :on_disconnect, :onDisconnect
33
+
34
+ def child(path)
35
+ Firebase.new(%x{ #@native.child(#{path}).toString() })
36
+ end
37
+
38
+ # Add data to a list using a unique name.
39
+ def push(value, &callback)
40
+ Firebase.new `#@native.push(#{value.to_n}).toString()`
41
+ end
42
+
43
+ # Get the absolute URL corresponding to this location.
44
+ def to_s
45
+ url
46
+ end
47
+
48
+ def to_n
49
+ @native
50
+ end
51
+
52
+ def inspect
53
+ "#<Firebase url: #{url}>"
54
+ end
55
+ end
@@ -0,0 +1,50 @@
1
+ class Query
2
+ include Native
3
+
4
+ def initialize(_native)
5
+ super(_native)
6
+ end
7
+
8
+ def limit(limit)
9
+ Query.new(%x{ #@native.limit(limit) })
10
+ end
11
+
12
+ def limit_to_first(limit)
13
+ Query.new(%x{ #@native.limitToFirst(limit) })
14
+ end
15
+
16
+ def limit_to_last(limit)
17
+ Query.new(%x{ #@native.limitToLast(limit) })
18
+ end
19
+
20
+ def once(event_type, &callback)
21
+ wrapper = proc {|snapshot|
22
+ snapshot = DataSnapshot.new(`snapshot`)
23
+ callback.call(snapshot)
24
+ }.to_n
25
+
26
+ `#@native.once(#{event_type}, #{wrapper})`
27
+ callback
28
+ end
29
+
30
+ # Attach a callback to read data and receive data changes.
31
+ # Based on
32
+ # https://github.com/opal/opal-jquery/blob/master/opal/opal-jquery/element.rb#L279
33
+ def on(event_type, &callback)
34
+ wrapper = proc{|snapshot|
35
+ snapshot = DataSnapshot.new(%x{ snapshot })
36
+ callback.call(snapshot)
37
+ }.to_n
38
+
39
+ `#@native.on(#{event_type}, #{wrapper})`
40
+ callback
41
+ end
42
+
43
+ def end_at(value, key = nil)
44
+ Query.new %x{ #@native.endAt(#{value.to_n}, #{key}) }
45
+ end
46
+
47
+ def start_at(value, key = nil)
48
+ Query.new %x{ #@native.startAt(#{value.to_n}, #{key}) }
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opal-firebase
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Rios
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: opal
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.6.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.6.0
55
+ description: Opal access to Firebase
56
+ email:
57
+ - gabrielfalcaorios@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/opal-firebase.rb
68
+ - lib/opal/firebase.rb
69
+ - lib/opal/firebase/version.rb
70
+ - opal-firebase.gemspec
71
+ - opal/opal-firebase.rb
72
+ - opal/opal-firebase/data_snapshot.rb
73
+ - opal/opal-firebase/firebase.rb
74
+ - opal/opal-firebase/query.rb
75
+ homepage: ''
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Opal library for Firebase
99
+ test_files: []