distribot-ui 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/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +12 -0
- data/Dockerfile +9 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +270 -0
- data/LICENSE +201 -0
- data/README.md +25 -0
- data/Rakefile +21 -0
- data/app/assets/images/.keep +0 -0
- data/app/assets/images/distribot-70x70.png +0 -0
- data/app/assets/javascripts/application.js +28 -0
- data/app/assets/javascripts/jquery.sparkline.min.js +5 -0
- data/app/assets/javascripts/signin/signin.js +30 -0
- data/app/assets/stylesheets/application.css.scss +17 -0
- data/app/controllers/admin_controller.rb +15 -0
- data/app/controllers/application_controller.rb +22 -0
- data/app/controllers/concerns/.keep +0 -0
- data/app/controllers/flow_controller.rb +64 -0
- data/app/controllers/handler_controller.rb +17 -0
- data/app/controllers/signin_controller.rb +22 -0
- data/app/controllers/worker_controller.rb +17 -0
- data/app/helpers/application_helper.rb +16 -0
- data/app/mailers/.keep +0 -0
- data/app/models/.keep +0 -0
- data/app/models/concerns/.keep +0 -0
- data/app/models/user.rb +83 -0
- data/app/views/admin/home.html.erb +14 -0
- data/app/views/flow/create.html.erb +22 -0
- data/app/views/flow/empty_list.html.erb +21 -0
- data/app/views/flow/list.html.erb +54 -0
- data/app/views/flow/show.html.erb +1 -0
- data/app/views/handler/list.html.erb +35 -0
- data/app/views/handler/show.html.erb +1 -0
- data/app/views/layouts/application.html.erb +72 -0
- data/app/views/signin/signin.html.erb +32 -0
- data/app/views/worker/list.html.erb +31 -0
- data/app/views/worker/show.html.erb +1 -0
- data/bin/bundle +3 -0
- data/bin/distribot-ui +13 -0
- data/bin/distribot-ui-restart +12 -0
- data/bin/rails +4 -0
- data/bin/rake +4 -0
- data/bin/setup +29 -0
- data/config.ru +4 -0
- data/config/application.rb +33 -0
- data/config/boot.rb +3 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +39 -0
- data/config/environments/production.rb +76 -0
- data/config/environments/test.rb +42 -0
- data/config/initializers/assets.rb +17 -0
- data/config/initializers/backtrace_silencers.rb +7 -0
- data/config/initializers/cookies_serializer.rb +3 -0
- data/config/initializers/filter_parameter_logging.rb +4 -0
- data/config/initializers/inflections.rb +16 -0
- data/config/initializers/mime_types.rb +4 -0
- data/config/initializers/session_store.rb +3 -0
- data/config/initializers/wrap_parameters.rb +9 -0
- data/config/locales/en.yml +23 -0
- data/config/routes.rb +36 -0
- data/config/secrets.yml +22 -0
- data/db/seeds.rb +9 -0
- data/distribot-ui.gemspec +45 -0
- data/docker-compose.yml +32 -0
- data/docs/distribot-ui-screenshot.png +0 -0
- data/lib/assets/.keep +0 -0
- data/lib/distribot-ui.rb +3 -0
- data/lib/distribot-ui/command.rb +62 -0
- data/lib/distribot-ui/version.rb +4 -0
- data/lib/redis_model.rb +109 -0
- data/lib/tasks/.keep +0 -0
- data/provision/distribot-ui.sh +52 -0
- data/public/404.html +67 -0
- data/public/422.html +67 -0
- data/public/500.html +66 -0
- data/public/favicon.ico +0 -0
- data/public/robots.txt +5 -0
- data/spec/controllers/admin_controller_spec.rb +27 -0
- data/spec/controllers/flow_controller_spec.rb +87 -0
- data/spec/controllers/handler_controller_spec.rb +12 -0
- data/spec/controllers/signin_controller_spec.rb +88 -0
- data/spec/controllers/worker_controller_spec.rb +12 -0
- data/spec/factories/users.rb +7 -0
- data/spec/helpers/application_helper_spec.rb +24 -0
- data/spec/models/user_spec.rb +32 -0
- data/spec/spec_helper.rb +80 -0
- metadata +351 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Do not eager load code on boot. This avoids loading your whole application
|
11
|
+
# just for the purpose of running a single test. If you are using a tool that
|
12
|
+
# preloads Rails for running tests, you may have to set it to true.
|
13
|
+
config.eager_load = false
|
14
|
+
|
15
|
+
# Configure static file server for tests with Cache-Control for performance.
|
16
|
+
config.serve_static_files = true
|
17
|
+
config.static_cache_control = 'public, max-age=3600'
|
18
|
+
|
19
|
+
# Show full error reports and disable caching.
|
20
|
+
config.consider_all_requests_local = true
|
21
|
+
config.action_controller.perform_caching = false
|
22
|
+
|
23
|
+
# Raise exceptions instead of rendering exception templates.
|
24
|
+
config.action_dispatch.show_exceptions = false
|
25
|
+
|
26
|
+
# Disable request forgery protection in test environment.
|
27
|
+
config.action_controller.allow_forgery_protection = false
|
28
|
+
|
29
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
30
|
+
# The :test delivery method accumulates sent emails in the
|
31
|
+
# ActionMailer::Base.deliveries array.
|
32
|
+
config.action_mailer.delivery_method = :test
|
33
|
+
|
34
|
+
# Randomize the order test cases are executed.
|
35
|
+
config.active_support.test_order = :random
|
36
|
+
|
37
|
+
# Print deprecation notices to the stderr.
|
38
|
+
config.active_support.deprecation = :stderr
|
39
|
+
|
40
|
+
# Raises error for missing translations
|
41
|
+
# config.action_view.raise_on_missing_translations = true
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Version of your assets, change this if you want to expire all your assets.
|
4
|
+
Rails.application.config.assets.version = '1.0'
|
5
|
+
|
6
|
+
# Add additional assets to the asset load path
|
7
|
+
# Rails.application.config.assets.paths << Emoji.images_path
|
8
|
+
|
9
|
+
# Precompile additional assets.
|
10
|
+
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
|
11
|
+
# Rails.application.config.assets.precompile += %w( search.js )
|
12
|
+
Rails.application.config.assets.precompile += Dir['app/assets/javascripts/**/*'].map do |item|
|
13
|
+
item.gsub(%r{^app/assets/javascripts/},'')
|
14
|
+
end
|
15
|
+
Rails.application.config.assets.precompile += Dir['app/assets/stylesheets/**/*'].map do |item|
|
16
|
+
item.gsub(%r{^app/assets/stylesheets/},'').gsub(/\.css\.scss$/, '.css')
|
17
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format. Inflections
|
4
|
+
# are locale specific, and you may define rules for as many different
|
5
|
+
# locales as you wish. All of these examples are active by default:
|
6
|
+
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
7
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
8
|
+
# inflect.singular /^(ox)en/i, '\1'
|
9
|
+
# inflect.irregular 'person', 'people'
|
10
|
+
# inflect.uncountable %w( fish sheep )
|
11
|
+
# end
|
12
|
+
|
13
|
+
# These inflection rules are supported but not enabled by default:
|
14
|
+
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
15
|
+
# inflect.acronym 'RESTful'
|
16
|
+
# end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
|
9
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Files in the config/locales directory are used for internationalization
|
2
|
+
# and are automatically loaded by Rails. If you want to use locales other
|
3
|
+
# than English, add the necessary files in this directory.
|
4
|
+
#
|
5
|
+
# To use the locales, use `I18n.t`:
|
6
|
+
#
|
7
|
+
# I18n.t 'hello'
|
8
|
+
#
|
9
|
+
# In views, this is aliased to just `t`:
|
10
|
+
#
|
11
|
+
# <%= t('hello') %>
|
12
|
+
#
|
13
|
+
# To use a different locale, set it with `I18n.locale`:
|
14
|
+
#
|
15
|
+
# I18n.locale = :es
|
16
|
+
#
|
17
|
+
# This would use the information in config/locales/es.yml.
|
18
|
+
#
|
19
|
+
# To learn more, please read the Rails Internationalization guide
|
20
|
+
# available at http://guides.rubyonrails.org/i18n.html.
|
21
|
+
|
22
|
+
en:
|
23
|
+
hello: "Hello world"
|
data/config/routes.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
|
3
|
+
root 'signin#signin', as: :signin, constraints: lambda { |req| req.session[:user_id].nil? }
|
4
|
+
root 'admin#home', as: :admin_home, constraints: lambda { |req| ! req.session[:user_id].nil? }
|
5
|
+
|
6
|
+
post '/' => 'signin#submit_signin'
|
7
|
+
get '/signout' => 'signin#signout'
|
8
|
+
|
9
|
+
scope 'flows' do
|
10
|
+
get '' => 'flow#list'
|
11
|
+
scope 'new' do
|
12
|
+
get '' => 'flow#create', as: :create_flow
|
13
|
+
post '' => 'flow#create'
|
14
|
+
end
|
15
|
+
scope ':flow_id' do
|
16
|
+
get '' => 'flow#show', as: :show_flow
|
17
|
+
post 'cancel' => 'flow#cancel', as: :cancel_flow
|
18
|
+
post 'pause' => 'flow#pause', as: :pause_flow
|
19
|
+
post 'resume' => 'flow#resume', as: :resume_flow
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
scope 'handlers' do
|
24
|
+
get '' => 'handler#list'
|
25
|
+
scope ':name' do
|
26
|
+
get '' => 'handler#show', as: :show_handler
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
scope 'workers' do
|
31
|
+
get '' => 'worker#list'
|
32
|
+
scope ':worker_id' do
|
33
|
+
get '' => 'worker#show', as: :show_worker
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/config/secrets.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
|
6
|
+
# Make sure the secret is at least 30 characters and all random,
|
7
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
+
# You can use `rake secret` to generate a secure secret key.
|
9
|
+
|
10
|
+
# Make sure the secrets in this file are kept private
|
11
|
+
# if you're sharing your code publicly.
|
12
|
+
|
13
|
+
development:
|
14
|
+
secret_key_base: dde7f940256696d2804eb4498a3f101f3e8611c8b9ee978ee9b587621daa60cc019ed3e5e0e0bf4ea874eb01e4dd321d64df0e8dd88ac03347a283b7e53d2976
|
15
|
+
|
16
|
+
test:
|
17
|
+
secret_key_base: e08cd2dc81b993959853ae685d73f08f78a978dffb1063c65b9d8cd4201ce79d5f87fe642dd7d9c3b28a577891e22bb2953cfddb98e95356aa7289106ba863a9
|
18
|
+
|
19
|
+
# Do not keep production secrets in the repository,
|
20
|
+
# instead read values from the environment.
|
21
|
+
production:
|
22
|
+
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
data/db/seeds.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
|
7
|
+
# Mayor.create(name: 'Emanuel', city: cities.first)
|
8
|
+
|
9
|
+
User.new(email: 'user@example.com', password: 'password').save
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'distribot-ui/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "distribot-ui"
|
8
|
+
spec.version = DistribotUI::VERSION
|
9
|
+
spec.authors = ["John Drago"]
|
10
|
+
spec.email = ["jdrago.999@gmail.com"]
|
11
|
+
spec.summary = %q{Web UI for Distribot}
|
12
|
+
spec.description = %q{Web UI for Distribot}
|
13
|
+
spec.homepage = "https://github.com/jdrago999/distribot-ui"
|
14
|
+
spec.license = "Apache"
|
15
|
+
|
16
|
+
unless (ARGV & %w(rake build)).length.zero?
|
17
|
+
# NOTE: `distribot-ui start` will run `bundle exec ...`. so this gemspec file evaluated by bundler then exec `git ls-files`
|
18
|
+
# but `git ls-files` would be warn if $PWD is not git dir, and unnecessary this step for to do it.
|
19
|
+
# And spec.files required for building a .gem only.
|
20
|
+
# Thus git ls-files only invoked with `rake build` command
|
21
|
+
spec.files = `git ls-files`.split($/)
|
22
|
+
end
|
23
|
+
spec.executables = ["distribot-ui"]
|
24
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency 'byebug'
|
28
|
+
spec.add_development_dependency 'rspec-rails'
|
29
|
+
spec.add_development_dependency 'shoulda-matchers'
|
30
|
+
# spec.add_development_dependency 'factory_girl_rails'
|
31
|
+
spec.add_development_dependency 'webmock'
|
32
|
+
spec.add_development_dependency 'simplecov'
|
33
|
+
spec.add_development_dependency 'web-console', '~> 2.0'
|
34
|
+
|
35
|
+
spec.add_dependency 'rails', '4.2.5'
|
36
|
+
spec.add_dependency 'font-awesome-rails'
|
37
|
+
spec.add_dependency 'sass-rails', '~> 5.0'
|
38
|
+
spec.add_dependency 'sprockets'
|
39
|
+
spec.add_dependency 'tubesock'
|
40
|
+
spec.add_dependency 'bcrypt', '~> 3.1'
|
41
|
+
|
42
|
+
spec.add_dependency 'bundler'
|
43
|
+
spec.add_dependency 'puma'
|
44
|
+
spec.add_dependency 'thor'
|
45
|
+
end
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
infra:
|
3
|
+
image: distribot/infra:latest
|
4
|
+
environment:
|
5
|
+
- TERM=xterm
|
6
|
+
- RABBITMQ_USERNAME=distribot
|
7
|
+
- RABBITMQ_PASSWORD=distribot
|
8
|
+
working_dir: /var/www/distribot
|
9
|
+
command: bash -c "./provision/infra.sh && tail -f /dev/null"
|
10
|
+
ports:
|
11
|
+
- 5672
|
12
|
+
- 15672
|
13
|
+
- 6379
|
14
|
+
- 443
|
15
|
+
|
16
|
+
code:
|
17
|
+
build: .
|
18
|
+
dockerfile: ./Dockerfile
|
19
|
+
volumes:
|
20
|
+
- ./:/var/www/distribot-ui
|
21
|
+
environment:
|
22
|
+
- TERM=xterm
|
23
|
+
- INFRA_HOST=infra_1
|
24
|
+
- RABBITMQ_USERNAME=distribot
|
25
|
+
- RABBITMQ_PASSWORD=distribot
|
26
|
+
working_dir: /var/www/distribot-ui
|
27
|
+
links:
|
28
|
+
- infra
|
29
|
+
ports:
|
30
|
+
- 3000
|
31
|
+
- 9292
|
32
|
+
command: bash -c "./provision/distribot-ui.sh && tail -f /dev/null"
|
Binary file
|
data/lib/assets/.keep
ADDED
File without changes
|
data/lib/distribot-ui.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/core_ext"
|
3
|
+
|
4
|
+
module DistribotUI
|
5
|
+
class Command < Thor
|
6
|
+
ROOT = File.expand_path('../../../', __FILE__)
|
7
|
+
|
8
|
+
|
9
|
+
desc "start", "start distribot-ui server"
|
10
|
+
option :port, type: :numeric, default: 9292
|
11
|
+
option :pidfile, type: :string, default: File.expand_path('tmp/distribot-ui.pid', ROOT)
|
12
|
+
option :daemonize, type: :boolean, default: false
|
13
|
+
option :host, type: :string, default: '0.0.0.0'
|
14
|
+
def start
|
15
|
+
trap(:INT) { puts "\nStopping..." }
|
16
|
+
# NOTE: on Debian based distributions, td-agent uses start-stop-daemon with --exec option for stopping process
|
17
|
+
# then distribot-ui will be killed by them because given --exec option matches.
|
18
|
+
# DISTRIBOT_UI_EXEC_COMMAND is used for workaround it.
|
19
|
+
cmd = ENV['DISTRIBOT_UI_EXEC_COMMAND'].presence || "rackup"
|
20
|
+
system(* %w(bundle exec) + cmd.split(" ") + %W(#{options[:daemonize] ? "-D" : ""} --pid #{options[:pidfile]} -p #{options[:port]} --host #{options[:host]} -E production #{ROOT}/config.ru))
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
desc "stop", "stop distribot-ui server"
|
25
|
+
option :pidfile, type: :string, default: File.expand_path('tmp/distribot-ui.pid', ROOT)
|
26
|
+
def stop
|
27
|
+
Process.kill(:TERM, pid) if pid
|
28
|
+
rescue Errno::ESRCH
|
29
|
+
ensure
|
30
|
+
puts "stopped"
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
desc "status", "status of distribot-ui server"
|
35
|
+
option :pidfile, type: :string, default: File.expand_path('tmp/distribot-ui.pid', ROOT)
|
36
|
+
def status
|
37
|
+
if pid && Process.kill(0, pid)
|
38
|
+
puts "distribot-ui is running"
|
39
|
+
else
|
40
|
+
puts "distribot-ui is stopped"
|
41
|
+
end
|
42
|
+
rescue Errno::ESRCH
|
43
|
+
puts "distribot-ui is stopped"
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
desc "setup", "setup distribot-ui server"
|
48
|
+
long_desc <<-DESC
|
49
|
+
install dependency gems
|
50
|
+
DESC
|
51
|
+
def setup
|
52
|
+
trap(:INT) { puts "\nStopping..." }
|
53
|
+
system(*%W(bundle install))
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def pid
|
59
|
+
File.read(options[:pidfile]).to_i rescue nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/redis_model.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
|
2
|
+
class RedisModel
|
3
|
+
|
4
|
+
include ActiveModel::Validations
|
5
|
+
include ActiveModel::Callbacks
|
6
|
+
define_model_callbacks :create, :update
|
7
|
+
|
8
|
+
def initialize(attributes = {})
|
9
|
+
@attributes = attributes
|
10
|
+
attributes.each do |key,val|
|
11
|
+
send "#{key}=", val
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def read_attribute_for_validation(key)
|
16
|
+
@attributes[key]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.first
|
20
|
+
all.first
|
21
|
+
end
|
22
|
+
|
23
|
+
def save!
|
24
|
+
false unless self.save
|
25
|
+
end
|
26
|
+
|
27
|
+
def save(*args)
|
28
|
+
unless self.valid?
|
29
|
+
return false
|
30
|
+
end
|
31
|
+
|
32
|
+
if self.id
|
33
|
+
run_callbacks :update do
|
34
|
+
self.update
|
35
|
+
end
|
36
|
+
else
|
37
|
+
run_callbacks :create do
|
38
|
+
self.create
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def update
|
44
|
+
raise NotImplementedError.new
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.find(id)
|
48
|
+
find_by_id(id)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.find_by_id(id)
|
52
|
+
raw_json = redis.get("distribot.#{table}.by.id:#{id}")
|
53
|
+
if raw_json
|
54
|
+
self.new JSON.parse(raw_json).merge(id: id)
|
55
|
+
else
|
56
|
+
return nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.find_by_email(email)
|
61
|
+
if id = redis.get("distribot.#{table}.by.email:#{email}")
|
62
|
+
return self.find_by_id(id)
|
63
|
+
else
|
64
|
+
return nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.find_by(args={})
|
69
|
+
send("find_by_#{args.keys.first}", args.values.first)
|
70
|
+
end
|
71
|
+
|
72
|
+
def delete
|
73
|
+
# Delete the email->id and the id->data values:
|
74
|
+
redis.multi do
|
75
|
+
redis.del("distribot.#{table}.by.id:#{self.id}")
|
76
|
+
redis.del("distribot.#{table}.by.email:#{self.email}")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.all
|
81
|
+
redis.scan_each(match: "distribot.#{table}.by.id:*").map do |key|
|
82
|
+
id = key.gsub(/^distribot\.#{table}\.by\.id\:/,'')
|
83
|
+
find_by_id(id)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.table
|
88
|
+
self.class.to_s.downcase.pluralize
|
89
|
+
end
|
90
|
+
|
91
|
+
def table
|
92
|
+
self.class.table
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.delete_all
|
96
|
+
self.all.map(&:delete)
|
97
|
+
end
|
98
|
+
|
99
|
+
protected
|
100
|
+
|
101
|
+
def self.redis
|
102
|
+
Distribot.redis
|
103
|
+
end
|
104
|
+
|
105
|
+
def redis
|
106
|
+
self.class.redis
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|