dry-observer-rails 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
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/Cakefile ADDED
@@ -0,0 +1,25 @@
1
+ fs = require 'fs'
2
+ {exec, spawn} = require 'child_process'
3
+ {series} = require 'async'
4
+
5
+ packageLocation = "#{__dirname}/node_modules/dry-observer"
6
+
7
+ sh = (command) -> (k) ->
8
+ console.log "Executing #{command}"
9
+ exec command, (err, sout, serr) ->
10
+ console.log err if err
11
+ console.log sout if sout
12
+ console.log serr if serr
13
+ do k
14
+
15
+ getVersion = ->
16
+ packageJson = JSON.parse fs.readFileSync "#{packageLocation}/package.json", 'utf-8'
17
+ packageJson.version
18
+
19
+ task 'build', 'build a new version of the asset gem', ->
20
+ series [
21
+ (sh "npm install dry-observer")
22
+ (sh "rm vendor/assets/javascripts/dry-observer.js")
23
+ (sh "cp #{packageLocation}/observer.js vendor/assets/javascripts/dry-observer.js")
24
+ (sh "gem bump --version #{getVersion()} --no-commit")
25
+ ]
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dry-observers-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Austin Bales
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,34 @@
1
+ # DryObserver::Rails
2
+
3
+ A Rails asset gem for `dry-observers`
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'dry-observer-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install dry-observer-rails
18
+
19
+ ## Usage
20
+ ```coffeescript
21
+ #= require 'dry-observer'
22
+
23
+ class MyView extends Backbone.View
24
+ # …
25
+
26
+ _.extend MyView::, Observers
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/dry-observer-rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Austin Bales"]
6
+ gem.email = ["austin@do.com"]
7
+ gem.description = %q{A rails asset gem for dry-observer}
8
+ gem.summary = %q{A rails asset gem for dry-observer}
9
+ gem.homepage = "https://github.com/arbales/dry-observers"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "dry-observer-rails"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = DryObserver::Rails::VERSION
17
+ end
@@ -0,0 +1,8 @@
1
+ require "dry-observers-rails/version"
2
+
3
+ module DryObserver
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module DryObserver
2
+ module Rails
3
+ VERSION = "0.2.2"
4
+ end
5
+ end
data/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "dry-observer-rails",
3
+ "version": "0.0.1",
4
+ "private": "true"
5
+ "keywords": [
6
+ "events observer backbone eventemitter"
7
+ ],
8
+ "description": "A utility to setup DRY event listeners.",
9
+ "licenses": [
10
+ {
11
+ "type": "MIT",
12
+ "url": "http://github.com/arbales/dry-observer/raw/master/LICENSE"
13
+ }
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git://github.com/arbales/dry-observer.git"
18
+ },
19
+ "dependencies": {
20
+ "underscore": "latest",
21
+ "async": "latest"
22
+ },
23
+ "devDependencies": {
24
+ "coffee-script": "1.3.3"
25
+ }
26
+ }
27
+
@@ -0,0 +1,210 @@
1
+ // Generated by CoffeeScript 1.3.3
2
+
3
+ /*
4
+ dry-observer
5
+ v0.2.2
6
+
7
+ LICENSE: http://github.com/arbales/dry-observer/raw/master/LICENSE
8
+ */
9
+
10
+
11
+ (function() {
12
+ var InvalidBindingError, Observers, capitalize, createListener, deprecatedBackbone, destroyListener, eventSplitter, exports, root, _,
13
+ __hasProp = {}.hasOwnProperty,
14
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
15
+ __slice = [].slice;
16
+
17
+ root = this;
18
+
19
+ _ = root._;
20
+
21
+ if (!_ && (typeof require !== "undefined" && require !== null)) {
22
+ _ = require('underscore');
23
+ }
24
+
25
+ InvalidBindingError = (function(_super) {
26
+
27
+ __extends(InvalidBindingError, _super);
28
+
29
+ function InvalidBindingError(event, handler) {
30
+ this.name = "InvalidBindingError";
31
+ this.message = "Unable create binding for `" + event + "` due unimplemented handler: `#" + handler + "`";
32
+ }
33
+
34
+ return InvalidBindingError;
35
+
36
+ })(Error);
37
+
38
+ capitalize = function(string) {
39
+ if (!string) {
40
+ return "";
41
+ }
42
+ return string.charAt(0).toUpperCase() + string.slice(1);
43
+ };
44
+
45
+ deprecatedBackbone = (typeof Backbone !== "undefined" && Backbone !== null) && parseFloat(Backbone.VERSION) < 0.9;
46
+
47
+ eventSplitter = /\s+/;
48
+
49
+ createListener = function(target, events, callback, context) {
50
+ var event, _i, _j, _len, _len1, _ref, _ref1, _results, _results1;
51
+ if (target.addListener) {
52
+ _ref = events.split(eventSplitter);
53
+ _results = [];
54
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
55
+ event = _ref[_i];
56
+ _results.push(target.addListener(event, callback));
57
+ }
58
+ return _results;
59
+ } else if (deprecatedBackbone) {
60
+ _ref1 = events.split(eventSplitter);
61
+ _results1 = [];
62
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
63
+ event = _ref1[_j];
64
+ _results1.push(target.bind(event, callback, context));
65
+ }
66
+ return _results1;
67
+ } else if (target.on) {
68
+ return target.on(events, handler, context);
69
+ } else {
70
+ throw new TypeError("Expected an EventEmitter or Backbone.Events-compatible target.");
71
+ }
72
+ };
73
+
74
+ destroyListener = function(target, events, callback) {
75
+ var event, _i, _j, _len, _len1, _ref, _ref1, _results, _results1;
76
+ if (target.removeListener) {
77
+ _ref = events.split(eventSplitter);
78
+ _results = [];
79
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
80
+ event = _ref[_i];
81
+ _results.push(target.removeListener(event, callback));
82
+ }
83
+ return _results;
84
+ } else if (deprecatedBackbone) {
85
+ _ref1 = events.split(eventSplitter);
86
+ _results1 = [];
87
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
88
+ event = _ref1[_j];
89
+ _results1.push(target.unbind(event, callback));
90
+ }
91
+ return _results1;
92
+ } else if (target.off) {
93
+ return target.off(events, handler);
94
+ } else {
95
+ throw new TypeError("Expected an EventEmitter or Backbone.Events-compatible target.");
96
+ }
97
+ };
98
+
99
+ Observers = {
100
+ _observedObjects: null,
101
+ _observers: null,
102
+ observe: function() {
103
+ var context, event, events, handler, parsedEvents, target, targetEvents, _base, _name,
104
+ _this = this;
105
+ target = arguments[0], events = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
106
+ context = null;
107
+ this._eventHandlerPrefix || (this._eventHandlerPrefix = 'on');
108
+ if (events.length === 1) {
109
+ if ((_(events[0])).isString()) {
110
+ events = events[0].split(" ");
111
+ }
112
+ if ((_(events[0])).isObject()) {
113
+ events = events[0];
114
+ }
115
+ } else if (_.isObject(_.last(events))) {
116
+ context = events.pop();
117
+ }
118
+ if (_.isString(events[0])) {
119
+ parsedEvents = {};
120
+ _.each(events, function(e) {
121
+ var action, handler, scope, _ref;
122
+ _ref = e.split(':'), action = _ref[0], scope = _ref[1];
123
+ handler = [_this._eventHandlerPrefix, capitalize(action), capitalize(scope)].join('');
124
+ handler = _this[handler] || _this[e] || (function() {
125
+ throw new InvalidBindingError(e, handler);
126
+ })();
127
+ return parsedEvents[e] = handler;
128
+ });
129
+ events = parsedEvents;
130
+ }
131
+ if (!_.isObject(events)) {
132
+ throw new TypeError("Observe accepts either a String, an Array of Strings, or an Object.");
133
+ }
134
+ if (!target.cid) {
135
+ target.cid = _.uniqueId('observed');
136
+ }
137
+ this._observedObjects = _.union((this._observedObjects || (this._observedObjects = [])), target);
138
+ targetEvents = (_base = (this._observers || (this._observers = {})))[_name = target.cid] || (_base[_name] = {});
139
+ for (event in events) {
140
+ if (!__hasProp.call(events, event)) continue;
141
+ handler = events[event];
142
+ createListener(target, event, handler, context);
143
+ (targetEvents[event] || (targetEvents[event] = [])).push(handler);
144
+ }
145
+ return true;
146
+ },
147
+ stopObserving: function(target) {
148
+ var event, events, handler, handlers, index, _i, _j, _len, _len1, _ref;
149
+ if (target == null) {
150
+ target = false;
151
+ }
152
+ if (!(this._observedObjects && this._observers)) {
153
+ return false;
154
+ }
155
+ if (!target) {
156
+ _ref = this._observedObjects;
157
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
158
+ target = _ref[_i];
159
+ if (target) {
160
+ this.stopObserving(target);
161
+ }
162
+ }
163
+ return false;
164
+ }
165
+ events = this._observers[target.cid];
166
+ for (event in events) {
167
+ if (!__hasProp.call(events, event)) continue;
168
+ handlers = events[event];
169
+ for (index = _j = 0, _len1 = handlers.length; _j < _len1; index = ++_j) {
170
+ handler = handlers[index];
171
+ destroyListener(target, event, handler);
172
+ delete [handlers][index];
173
+ }
174
+ }
175
+ delete this._observedObjects[_.indexOf(this._observedObjects, target)];
176
+ delete this._observers[target.cid];
177
+ return true;
178
+ },
179
+ removeObserver: function(target, event, handlerToRemove) {
180
+ var events, handler, handlers, index, _i, _j, _len, _len1, _ref;
181
+ if (!target) {
182
+ _ref = this._observedObjects;
183
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
184
+ target = _ref[_i];
185
+ this.removeObserver(target);
186
+ }
187
+ }
188
+ events = _observers[target.cid];
189
+ for (event in events) {
190
+ if (!__hasProp.call(events, event)) continue;
191
+ handlers = events[event];
192
+ for (index = _j = 0, _len1 = handlers.length; _j < _len1; index = ++_j) {
193
+ handler = handlers[index];
194
+ if (handlerToRemove && handler !== handlerToRemove) {
195
+ continue;
196
+ }
197
+ target.off(event, handler);
198
+ events[event][index] = null;
199
+ delete events[event][index];
200
+ }
201
+ }
202
+ return true;
203
+ }
204
+ };
205
+
206
+ exports = (typeof module !== "undefined" && module !== null ? module.exports : void 0) || this;
207
+
208
+ exports.Observers = Observers;
209
+
210
+ }).call(this);
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dry-observer-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Austin Bales
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-01 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A rails asset gem for dry-observer
15
+ email:
16
+ - austin@do.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Cakefile
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - dry-observer-rails.gemspec
28
+ - lib/dry-observer-rails.rb
29
+ - lib/dry-observer-rails/version.rb
30
+ - package.json
31
+ - vendor/assets/javascripts/dry-observer.js
32
+ homepage: https://github.com/arbales/dry-observers
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.24
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: A rails asset gem for dry-observer
56
+ test_files: []
57
+ has_rdoc: