smap_rails 0.1.0

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: 13bd04f06106ea1d2073b37de74afe497849c50c
4
+ data.tar.gz: e74cebb5e1eb01c8ad3fac64380b051a78741533
5
+ SHA512:
6
+ metadata.gz: 8e43b9f2c02b5eb828752d7e269146b4c58ad397a8aaf4c3dbdf861b48aaf0d466b2d510c292050dcd9c694d606fd0d0385bba711eed139f4a8841f8f0cb4c71
7
+ data.tar.gz: 83ba00a03480e9d5de3e45ef44921a5cef7f2911ce111567499d9d129c794c5b1d9181c5cfb66d774bf622bed4f38450d03fb8dbc1982b1e8b545145fd583442
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in smap_rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Robert Greene
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # SmapRails - a forward polyfill for ES6 Maps packaged for the Rails asset pipeline
2
+
3
+ ES6 Maps with a bunch of convenience methods packaged for the Rails asset pipeline. Smap.js was created by the awesome developer, [Eric Wendelin](http://github.com/eriwen). You can take a look at the original repo hosted here [https://github.com/eriwen/smap.js](https://github.com/eriwen/smap.js).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'smap_rails'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install smap_rails
20
+
21
+ ## Usage
22
+
23
+ Check out the smap js repo [https://github.com/eriwen/smap.js](https://github.com/eriwen/smap.js).
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rardoz/smap_rails.
34
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,287 @@
1
+ //! Copyright 2012 Eric Wendelin - MIT License
2
+
3
+ /**
4
+ * es6-map-shim.js is a DESTRUCTIVE shim that follows the latest Map specification as closely as possible.
5
+ * It is destructive in the sense that it overrides native implementations.
6
+ *
7
+ * This library assumes ES5 functionality: Object.create, Object.defineProperty, Array.indexOf, Function.bind
8
+ */
9
+ (function(module) {
10
+ function Map(iterable) {
11
+ var _items = [];
12
+ var _keys = [];
13
+ var _values = [];
14
+
15
+ // Object.is polyfill, courtesy of @WebReflection
16
+ var is = Object.is || function(a, b) {
17
+ return a === b ?
18
+ a !== 0 || 1 / a == 1 / b :
19
+ a != a && b != b;
20
+ };
21
+
22
+ // More reliable indexOf, courtesy of @WebReflection
23
+ var betterIndexOf = function(value) {
24
+ if(value != value || value === 0) {
25
+ for(var i = this.length; i-- && !is(this[i], value);){}
26
+ } else {
27
+ i = [].indexOf.call(this, value);
28
+ }
29
+ return i;
30
+ };
31
+
32
+ var MapIterator = function MapIterator(map, kind) {
33
+ var _index = 0;
34
+
35
+ return Object.create({}, {
36
+ next: {
37
+ value: function() {
38
+ // check if index is within bounds
39
+ if (_index < map.items().length) {
40
+ switch(kind) {
41
+ case 'keys': return map.keys()[_index++];
42
+ case 'values': return map.values()[_index++];
43
+ case 'keys+values': return [].slice.call(map.items()[_index++]);
44
+ default: throw new TypeError('Invalid iterator type');
45
+ }
46
+ }
47
+ // TODO: make sure I'm interpreting the spec correctly here
48
+ throw new Error('Stop Iteration');
49
+ }
50
+ },
51
+ iterator: {
52
+ value: function() {
53
+ return this;
54
+ }
55
+ },
56
+ toString: {
57
+ value: function() {
58
+ return '[object Map Iterator]';
59
+ }
60
+ }
61
+ });
62
+ };
63
+
64
+ var _set = function(key, value) {
65
+ // check if key exists and overwrite
66
+ var index = betterIndexOf.call(_keys, key);
67
+ if (index > -1) {
68
+ _items[index] = value;
69
+ _values[index] = value;
70
+ } else {
71
+ _items.push([key, value]);
72
+ _keys.push(key);
73
+ _values.push(value);
74
+ }
75
+ };
76
+
77
+ var setItem = function(item) {
78
+ if (item.length !== 2) {
79
+ throw new TypeError('Invalid iterable passed to Map constructor');
80
+ }
81
+
82
+ _set(item[0], item[1]);
83
+ };
84
+
85
+ // FIXME: accommodate any class that defines an @@iterator method that returns
86
+ // an iterator object that produces two element array-like objects
87
+ if (Array.isArray(iterable)) {
88
+ iterable.forEach(setItem);
89
+ } else if (iterable !== undefined) {
90
+ throw new TypeError('Invalid Map');
91
+ }
92
+
93
+ return Object.create(MapPrototype, {
94
+ items:{
95
+ value:function() {
96
+ return [].slice.call(_items);
97
+ }
98
+ },
99
+ keys:{
100
+ value:function() {
101
+ return [].slice.call(_keys);
102
+ }
103
+ },
104
+ values:{
105
+ value:function() {
106
+ return [].slice.call(_values);
107
+ }
108
+ },
109
+ has:{
110
+ value:function(key) {
111
+ // TODO: check how spec reads about null values
112
+ var index = betterIndexOf.call(_keys, key);
113
+ return index > -1;
114
+ }
115
+ },
116
+ get:{
117
+ value:function(key) {
118
+ var index = betterIndexOf.call(_keys, key);
119
+ return index > -1 ? _values[index] : undefined;
120
+ }
121
+ },
122
+ set:{
123
+ value: _set
124
+ },
125
+ size:{
126
+ get:function() {
127
+ return _items.length;
128
+ }
129
+ },
130
+ clear:{
131
+ value:function() {
132
+ _keys.length = _values.length = _items.length = 0;
133
+ }
134
+ },
135
+ 'delete':{
136
+ value:function(key) {
137
+ var index = betterIndexOf.call(_keys, key);
138
+ if (index > -1) {
139
+ _keys.splice(index, 1);
140
+ _values.splice(index, 1);
141
+ _items.splice(index, 1);
142
+ return true;
143
+ }
144
+ return false;
145
+ }
146
+ },
147
+ forEach:{
148
+ value:function(callbackfn /*, thisArg*/) {
149
+ if (typeof callbackfn != 'function') {
150
+ throw new TypeError('Invalid callback function given to forEach');
151
+ }
152
+
153
+ function tryNext() {
154
+ try {
155
+ return iter.next();
156
+ } catch(e) {
157
+ return undefined;
158
+ }
159
+ }
160
+
161
+ var iter = this.iterator();
162
+ var current = tryNext();
163
+ var next = tryNext();
164
+ while(current !== undefined) {
165
+ callbackfn.apply(arguments[1], [current[1], current[0], this]);
166
+ current = next;
167
+ next = tryNext();
168
+ }
169
+ }
170
+ },
171
+ iterator:{
172
+ value: function() {
173
+ return new MapIterator(this, 'keys+values');
174
+ }
175
+ },
176
+ toString:{
177
+ value: function() {
178
+ return '[Object Map]';
179
+ }
180
+ }
181
+ });
182
+ }
183
+
184
+ var notInNode = module == 'undefined';
185
+ var window = notInNode ? this : global;
186
+ var module = notInNode ? {} : exports;
187
+ var MapPrototype = Map.prototype;
188
+
189
+ Map.prototype = MapPrototype = Map();
190
+
191
+ window.Map = module.Map = window.Map || Map;
192
+ }.call(this, typeof exports));
193
+ //! Copyright 2012 Eric Wendelin - MIT License
194
+ (function() {
195
+ 'use strict';
196
+
197
+ /**
198
+ * Given a filtering function, return a new Map of items matching that
199
+ * function.
200
+ *
201
+ * @param filterFn {Function} that takes up to 3 arguments and returns a Boolean.
202
+ * @return {Map} a new Map that is the subset of this map's items
203
+ * that match the given filter function.
204
+ */
205
+ Map.prototype.filter = function(filterFn) {
206
+ if (typeof filterFn != 'function') {
207
+ throw new TypeError('Expected a function argument');
208
+ }
209
+ var _map = new Map();
210
+ this.forEach(function(value, key, map) {
211
+ if(filterFn(key, value, map)) {
212
+ _map.set(key, value);
213
+ }
214
+ });
215
+ return _map;
216
+ };
217
+
218
+ /**
219
+ * Return a new Map that is the union of this Map and the given other Map.
220
+ * If there are conflicting keys, the item in the Map argument overrides.
221
+ *
222
+ * @param otherMap {Map}
223
+ * @return {Map} with all non-conflicting items
224
+ */
225
+ Map.prototype.merge = function(otherMap) {
226
+ if (!(otherMap instanceof Map)) {
227
+ throw new TypeError('Cannot merge with objects that are not Maps');
228
+ }
229
+
230
+ function setAll(value, key) {
231
+ _map.set(key, value);
232
+ }
233
+ var _map = new Map();
234
+
235
+ this.forEach(setAll);
236
+ otherMap.forEach(setAll);
237
+ return _map;
238
+ };
239
+
240
+ /**
241
+ * Get entry for given key, or if it doesn't exist the default value.
242
+ *
243
+ * @param key {Object} anything, including primitives
244
+ * @param defaultValue {Object}
245
+ * @return item at key or default
246
+ */
247
+ Map.prototype.fetch = function(key, defaultValue) {
248
+ if (this.has(key)) {
249
+ return this.get(key);
250
+ }
251
+ return defaultValue;
252
+ };
253
+
254
+ /**
255
+ * Return a new Map whose keys are the values of this Map, and values are keys.
256
+ *
257
+ * @return a new Map, this map inverted
258
+ */
259
+ Map.prototype.invert = function() {
260
+ var _map = new Map();
261
+ this.forEach(_map.set);
262
+ return _map;
263
+ };
264
+
265
+ /**
266
+ * Remove items from this Map as designated by a filtering function.
267
+ *
268
+ * @param filterFn {Function} using key, value and/or index and returning a Boolean
269
+ */
270
+ Map.prototype.reject = function(filterFn) {
271
+ if (typeof filterFn != 'function') {
272
+ throw new TypeError('Expected a function argument');
273
+ }
274
+ this.forEach(function(value, key, map) {
275
+ if(filterFn(key, value, map)) {
276
+ map['delete'](key);
277
+ }
278
+ }.bind(this));
279
+ };
280
+
281
+ /**
282
+ * @return true if there are no entries in this Map.
283
+ */
284
+ Map.prototype.isEmpty = function() {
285
+ return this.keys().length === 0;
286
+ };
287
+ })();
data/lib/smap_rails.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "smap_rails/version"
2
+ require "smap_rails/engine"
3
+
4
+ module SmapRails
5
+ end
@@ -0,0 +1,5 @@
1
+ module SmapRails
2
+ class Engine < Rails::Engine
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module SmapRails
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'smap_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "smap_rails"
8
+ spec.version = SmapRails::VERSION
9
+ spec.authors = ["Robert Greene"]
10
+ spec.email = ["rgreene@avvo.com"]
11
+
12
+ spec.summary = %q{SmapRails Javascript packaged for Rails asset pipeline}
13
+ spec.description = %q{SmapRails a forward polyfill for ES6 Maps packaged for the Rails asset pipeline}
14
+ spec.homepage = "http://www.github.com/rardoz"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = ["lib"]
18
+ spec.license = "MIT"
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.11"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "minitest", "~> 5.0"
23
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smap_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Robert Greene
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-29 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: SmapRails a forward polyfill for ES6 Maps packaged for the Rails asset
56
+ pipeline
57
+ email:
58
+ - rgreene@avvo.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - app/assets/javascripts/smap.js
68
+ - lib/smap_rails.rb
69
+ - lib/smap_rails/engine.rb
70
+ - lib/smap_rails/version.rb
71
+ - smap_rails.gemspec
72
+ homepage: http://www.github.com/rardoz
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.4.8
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: SmapRails Javascript packaged for Rails asset pipeline
96
+ test_files: []
97
+ has_rdoc: