reactive_array 1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/reactive_array.rb +40 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 07ada799fbc1549a7173896ad34c88e04a53a045
|
4
|
+
data.tar.gz: b0a75fd217032e57c3016ee9d0d08787855b5aab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2893996dba4f0a6afdf8e0a705cbe7cba68c0e6baf293b1153e8753ecdbbfc29ec9437bc112ef2d59b5fece660632ff4cf2e5396bb763e598449da4824a3aa76
|
7
|
+
data.tar.gz: ea86e90375d7d35a930c37006b91671b4e516cf121195c9e509541c95e5f29b8441ed439d00597e9a0ffb8da9d3fbb7a7a6434e2c26c0719e291418fa770d58f
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# A wrapper around an array that calls #react! on any 'send'. This enables you to react to certain events or changes to the array.
|
2
|
+
class ReactiveArray
|
3
|
+
|
4
|
+
def initialize(*args)
|
5
|
+
@array = Array.new(*args)
|
6
|
+
yield self if block_given?
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
react!(:to_s)
|
11
|
+
@array.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_a
|
15
|
+
react!(:to_a)
|
16
|
+
@array
|
17
|
+
end
|
18
|
+
alias_method :to_ary, :to_a
|
19
|
+
|
20
|
+
OPERATORS = ["&", "+", "-", "|", "<=>", "=="]
|
21
|
+
OPERATORS.each do |operator|
|
22
|
+
class_eval <<-end_eval, __FILE__, __LINE__
|
23
|
+
def #{operator}(other_array)
|
24
|
+
@array #{operator} other_array.to_a
|
25
|
+
end
|
26
|
+
end_eval
|
27
|
+
end
|
28
|
+
|
29
|
+
def method_missing(m, *args, &block)
|
30
|
+
x = @array.send(m, *args, &block)
|
31
|
+
react!(m)
|
32
|
+
# if the @array returned self, we return self too (but we will refer to our wrapper class of course)
|
33
|
+
x.equal?(@array) ? self : x
|
34
|
+
end
|
35
|
+
|
36
|
+
def react!(m)
|
37
|
+
raise NotImplemented, "responsibility of subclass"
|
38
|
+
# puts "reacting on #{m.inspect}"
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reactive_array
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tijn Schuurmans
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Reactive Array is a array that autoserializes itself after each write
|
14
|
+
operation.
|
15
|
+
email: tijn.schuurmans@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/reactive_array.rb
|
21
|
+
homepage: https://github.com/tijn/reactive_array
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements:
|
40
|
+
- none
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.2.2
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Reactive Array.
|
46
|
+
test_files: []
|