rdux 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +37 -0
- data/Rakefile +29 -0
- data/app/models/rdux/action.rb +33 -0
- data/db/migrate/20200823045609_create_rdux_actions.rb +13 -0
- data/lib/rdux.rb +23 -0
- data/lib/rdux/engine.rb +7 -0
- data/lib/rdux/version.rb +5 -0
- data/lib/tasks/rdux_tasks.rake +6 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cfb7f010e3ba48e4a37ff7b1b257b02edb36bd76081dd840b8e04176ed34bc6a
|
4
|
+
data.tar.gz: 4c6b974f39958cf2c312781f2284690e29e2095daa767c4ac6821b2cd788ec49
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9325ef0b570cefce69e3852d8890671ac112df162dd68d1cc953fe4692def7a9747040cddda41ab1700e7adf918b1cd9f124e9d1c596f1aa57c60bdf49ad6755
|
7
|
+
data.tar.gz: 7ab94f4d3a692b126cfaa940c9f8eaec84bf901c8cdcf50a2b9b1786c80ceb12a17c4235dcafc211607049dc1f39d2480ce1c850f1d05754ecdd4a29434659ba
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2020 himn1
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Rdux
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
|
6
|
+
```bash
|
7
|
+
$ bin/rails rdux:install:migrations
|
8
|
+
```
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'rdux'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
```bash
|
19
|
+
$ bundle
|
20
|
+
```
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
```bash
|
24
|
+
$ gem install rdux
|
25
|
+
```
|
26
|
+
|
27
|
+
## Test
|
28
|
+
|
29
|
+
```bash
|
30
|
+
$ bin/test
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
Contribution directions go here.
|
35
|
+
|
36
|
+
## License
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rdoc/task'
|
10
|
+
|
11
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
12
|
+
rdoc.rdoc_dir = 'rdoc'
|
13
|
+
rdoc.title = 'Rdux'
|
14
|
+
rdoc.options << '--line-numbers'
|
15
|
+
rdoc.rdoc_files.include('README.md')
|
16
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'bundler/gem_tasks'
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
|
23
|
+
Rake::TestTask.new(:test) do |t|
|
24
|
+
t.libs << 'test'
|
25
|
+
t.pattern = 'test/**/*_test.rb'
|
26
|
+
t.verbose = false
|
27
|
+
end
|
28
|
+
|
29
|
+
task default: :test
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rdux
|
4
|
+
class Action < ApplicationRecord
|
5
|
+
def self.table_name_prefix
|
6
|
+
'rdux_'
|
7
|
+
end
|
8
|
+
|
9
|
+
serialize :up_payload, JSON
|
10
|
+
serialize :down_payload, JSON
|
11
|
+
|
12
|
+
validates :name, presence: true
|
13
|
+
validates :up_payload, presence: true
|
14
|
+
|
15
|
+
def up(opts)
|
16
|
+
if opts.any?
|
17
|
+
action_creator.up(up_payload, opts)
|
18
|
+
else
|
19
|
+
action_creator.up(up_payload)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def down
|
24
|
+
action_creator.down(down_payload)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def action_creator
|
30
|
+
name.to_s.classify.constantize.new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/rdux.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rdux/engine'
|
4
|
+
|
5
|
+
module Rdux
|
6
|
+
Result = Struct.new(:ok, :down_payload, :resp, :action) do
|
7
|
+
def payload
|
8
|
+
resp || down_payload
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module_function
|
13
|
+
|
14
|
+
def dispatch(action_name, payload, opts = {})
|
15
|
+
action = Action.new(name: action_name, up_payload: payload)
|
16
|
+
res = action.up(opts)
|
17
|
+
action.down_payload = res.down_payload
|
18
|
+
res.down_payload = action.down_payload
|
19
|
+
action.save! if res.ok
|
20
|
+
res.action = action
|
21
|
+
res
|
22
|
+
end
|
23
|
+
end
|
data/lib/rdux/engine.rb
ADDED
data/lib/rdux/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rdux
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zbigniew Humeniuk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rubocop
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rubocop-rails
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: sqlite3
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
description: |
|
76
|
+
Write apps that are easy to test.
|
77
|
+
Rdux gives you a possibility to centralize your app's state modification logic (DB changes).
|
78
|
+
It does it via introducing a new architectural layer - actions.
|
79
|
+
Rdux enables powerful capabilities like undo/redo.
|
80
|
+
It makes it easy to trace when, where, why, and how your application's state changed.
|
81
|
+
email:
|
82
|
+
- hello@artofcode.co
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files: []
|
86
|
+
files:
|
87
|
+
- MIT-LICENSE
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- app/models/rdux/action.rb
|
91
|
+
- db/migrate/20200823045609_create_rdux_actions.rb
|
92
|
+
- lib/rdux.rb
|
93
|
+
- lib/rdux/engine.rb
|
94
|
+
- lib/rdux/version.rb
|
95
|
+
- lib/tasks/rdux_tasks.rake
|
96
|
+
homepage: https://artofcode.co
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 2.6.0
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubygems_version: 3.1.2
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Rdux adds a new layer to Rails apps - actions.
|
119
|
+
test_files: []
|