rudux 0.0.3 → 1.0.0
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 +4 -4
- data/lib/rudux/combined.rb +6 -1
- data/lib/rudux/hash_reducer.rb +27 -0
- data/lib/rudux/reducer.rb +10 -10
- data/lib/rudux/store.rb +4 -2
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0bd0da2f6bdee5b50087c9fb153070a7efe215f2
|
|
4
|
+
data.tar.gz: 9893179d6e8f8b1ee181f8aa08649b7fe0dc0640
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e4b85e5a0763b78acbef2213ae4968661b2f20aac47d51fa259e0037e1bb7b02aa01137d08abe866502908af17ceb38e5c80b29a3e8a8aa6eb498ec3fe0c616a
|
|
7
|
+
data.tar.gz: b878c03943d88797f13435a5c2496e6b321d0de47e61eadebee022c6e8d8612f694c72e3b24d1d3e0c657661b071163b5ee060a91dfdf3d5f542cd52ce4757b8
|
data/lib/rudux/combined.rb
CHANGED
|
@@ -7,7 +7,12 @@ module Rudux
|
|
|
7
7
|
def reduce state, action
|
|
8
8
|
@hash.keys.map do |key|
|
|
9
9
|
reducer = @hash[key]
|
|
10
|
-
|
|
10
|
+
if state.is_a? Hash
|
|
11
|
+
substate = state[key]
|
|
12
|
+
else
|
|
13
|
+
substate = state.send(key)
|
|
14
|
+
end
|
|
15
|
+
reduced = reducer.reduce(substate, action)
|
|
11
16
|
Hash[key, reduced]
|
|
12
17
|
end.reduce({}, &:merge!)
|
|
13
18
|
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'rudux/combined'
|
|
2
|
+
|
|
3
|
+
module Rudux
|
|
4
|
+
class HashReducer
|
|
5
|
+
|
|
6
|
+
def initialize reducer
|
|
7
|
+
@subreducer = reducer
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def reduce state, action
|
|
11
|
+
unless state.is_a? Hash
|
|
12
|
+
raise 'HashReducer not given hash'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
state.keys.map do |key|
|
|
16
|
+
result = @subreducer.reduce(state[key], action)
|
|
17
|
+
|
|
18
|
+
if result.respond_to? :[]
|
|
19
|
+
Hash[result[:id], result]
|
|
20
|
+
else
|
|
21
|
+
Hash[result.id, result]
|
|
22
|
+
end
|
|
23
|
+
end.reduce(&:merge!)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/rudux/reducer.rb
CHANGED
|
@@ -6,8 +6,6 @@ module Rudux
|
|
|
6
6
|
def self.reduce states, action
|
|
7
7
|
if states.is_a? Array
|
|
8
8
|
reduce_array_of_states(states, action)
|
|
9
|
-
elsif states.is_a? Hash
|
|
10
|
-
reduce_hash_of_states(states, action)
|
|
11
9
|
else
|
|
12
10
|
reduce_single_state(states, action)
|
|
13
11
|
end
|
|
@@ -19,15 +17,11 @@ module Rudux
|
|
|
19
17
|
end
|
|
20
18
|
end
|
|
21
19
|
|
|
22
|
-
def self.reduce_hash_of_states hash, action
|
|
23
|
-
hash.map do |state|
|
|
24
|
-
result = reduce_single_state(state[1], action)
|
|
25
|
-
Hash[result.id, result]
|
|
26
|
-
end.reduce(&:merge!)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
20
|
def self.reduce_single_state state, action
|
|
30
21
|
base = self.base.reduce(state, action)
|
|
22
|
+
unless action.respond_to? :to_sym
|
|
23
|
+
puts "Action #{action.inspect} received to_sym"
|
|
24
|
+
end
|
|
31
25
|
if self.respond_to? action.to_sym
|
|
32
26
|
this = self.send(action.to_sym, state, action)
|
|
33
27
|
else
|
|
@@ -37,7 +31,13 @@ module Rudux
|
|
|
37
31
|
if merged.empty?
|
|
38
32
|
state
|
|
39
33
|
else
|
|
40
|
-
state.copy
|
|
34
|
+
if state.respond_to? :copy
|
|
35
|
+
# oop style
|
|
36
|
+
state.copy(merged)
|
|
37
|
+
else
|
|
38
|
+
# hash style
|
|
39
|
+
merged
|
|
40
|
+
end
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
|
data/lib/rudux/store.rb
CHANGED
metadata
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rudux
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Christopher Okhravi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-01-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
|
-
description:
|
|
13
|
+
description:
|
|
14
14
|
email:
|
|
15
15
|
executables: []
|
|
16
16
|
extensions: []
|
|
@@ -19,6 +19,7 @@ files:
|
|
|
19
19
|
- lib/rudux/action.rb
|
|
20
20
|
- lib/rudux/combined.rb
|
|
21
21
|
- lib/rudux/entity.rb
|
|
22
|
+
- lib/rudux/hash_reducer.rb
|
|
22
23
|
- lib/rudux/mutating_reducer.rb
|
|
23
24
|
- lib/rudux/reducer.rb
|
|
24
25
|
- lib/rudux/store.rb
|