gera 0.3.4
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/LICENSE +674 -0
- data/README.md +67 -0
- data/Rakefile +43 -0
- data/app/assets/config/gera_manifest.js +2 -0
- data/app/assets/javascripts/gera/application.js +14 -0
- data/app/assets/stylesheets/gera/application.css +15 -0
- data/app/authorizers/gera/application_authorizer.rb +6 -0
- data/app/authorizers/gera/currency_rate_authorizer.rb +9 -0
- data/app/authorizers/gera/currency_rate_mode_authorizer.rb +7 -0
- data/app/authorizers/gera/direction_rate_authorizer.rb +8 -0
- data/app/authorizers/gera/exchange_rate_authorizer.rb +8 -0
- data/app/authorizers/gera/payment_system_authorizer.rb +13 -0
- data/app/authorizers/gera/rate_source_authorizer.rb +7 -0
- data/app/controllers/gera/application_controller.rb +30 -0
- data/app/controllers/gera/currencies_controller.rb +8 -0
- data/app/controllers/gera/currency_rate_history_intervals_controller.rb +53 -0
- data/app/controllers/gera/currency_rate_mode_snapshots_controller.rb +83 -0
- data/app/controllers/gera/currency_rate_modes_controller.rb +60 -0
- data/app/controllers/gera/currency_rates_controller.rb +70 -0
- data/app/controllers/gera/direction_rate_history_intervals_controller.rb +62 -0
- data/app/controllers/gera/direction_rates_controller.rb +28 -0
- data/app/controllers/gera/exchange_rates_controller.rb +25 -0
- data/app/controllers/gera/external_rate_snapshots_controller.rb +35 -0
- data/app/controllers/gera/external_rates_controller.rb +28 -0
- data/app/controllers/gera/payment_systems_controller.rb +78 -0
- data/app/controllers/gera/rate_sources_controller.rb +8 -0
- data/app/decorators/gera/currency_rate_decorator.rb +148 -0
- data/app/decorators/gera/direction_rate_decorator.rb +47 -0
- data/app/decorators/gera/payment_system_decorator.rb +19 -0
- data/app/helpers/gera/application_helper.rb +110 -0
- data/app/helpers/gera/currency_rate_helper.rb +19 -0
- data/app/helpers/gera/currency_rate_modes_helper.rb +73 -0
- data/app/helpers/gera/direction_rate_helper.rb +36 -0
- data/app/helpers/gera/exchange_rates_helper.rb +21 -0
- data/app/jobs/gera/application_job.rb +6 -0
- data/app/models/concerns/gera/currency_pair_generator.rb +14 -0
- data/app/models/concerns/gera/currency_pair_support.rb +42 -0
- data/app/models/concerns/gera/currency_rate_mode_builder_support.rb +35 -0
- data/app/models/concerns/gera/direction_support.rb +14 -0
- data/app/models/concerns/gera/history_interval_concern.rb +46 -0
- data/app/models/gera/application_record.rb +8 -0
- data/app/models/gera/cbr_external_rate.rb +13 -0
- data/app/models/gera/cross_rate_mode.rb +13 -0
- data/app/models/gera/currency_rate.rb +78 -0
- data/app/models/gera/currency_rate_history_interval.rb +25 -0
- data/app/models/gera/currency_rate_history_interval_filter.rb +30 -0
- data/app/models/gera/currency_rate_mode.rb +20 -0
- data/app/models/gera/currency_rate_mode_snapshot.rb +26 -0
- data/app/models/gera/currency_rate_snapshot.rb +12 -0
- data/app/models/gera/direction.rb +44 -0
- data/app/models/gera/direction_rate.rb +136 -0
- data/app/models/gera/direction_rate_history_interval.rb +33 -0
- data/app/models/gera/direction_rate_history_interval_filter.rb +30 -0
- data/app/models/gera/direction_rate_snapshot.rb +7 -0
- data/app/models/gera/exchange_rate.rb +130 -0
- data/app/models/gera/external_rate.rb +38 -0
- data/app/models/gera/external_rate_snapshot.rb +20 -0
- data/app/models/gera/payment_system.rb +98 -0
- data/app/models/gera/rate_source.rb +77 -0
- data/app/models/gera/rate_source_auto.rb +25 -0
- data/app/models/gera/rate_source_bitfinex.rb +9 -0
- data/app/models/gera/rate_source_cbr.rb +13 -0
- data/app/models/gera/rate_source_cbr_avg.rb +6 -0
- data/app/models/gera/rate_source_exmo.rb +9 -0
- data/app/models/gera/rate_source_manual.rb +13 -0
- data/app/views/application/_exchange_rate_monitor.slim +1 -0
- data/app/views/gera/application/_attributes_table.slim +5 -0
- data/app/views/gera/application/_currencies_table.slim +18 -0
- data/app/views/gera/application/_currency_rate_mode_snapshots.slim +6 -0
- data/app/views/gera/application/_direction_rate.slim +6 -0
- data/app/views/gera/application/_directions_submenu.slim +11 -0
- data/app/views/gera/application/_directions_table.slim +15 -0
- data/app/views/gera/application/_exchange_rate.slim +6 -0
- data/app/views/gera/application/_external_rate.slim +6 -0
- data/app/views/gera/application/_header.slim +12 -0
- data/app/views/gera/application/_table.slim +28 -0
- data/app/views/gera/application/_topnav.slim +21 -0
- data/app/views/gera/application/direction_details.slim +75 -0
- data/app/views/gera/application/page.html.slim +1 -0
- data/app/views/gera/currencies/index.html.slim +20 -0
- data/app/views/gera/currency_rate_history_intervals/_filter.slim +11 -0
- data/app/views/gera/currency_rate_history_intervals/index.slim +39 -0
- data/app/views/gera/currency_rate_mode_snapshots/_snapshot.slim +20 -0
- data/app/views/gera/currency_rate_mode_snapshots/edit.html.slim +30 -0
- data/app/views/gera/currency_rate_modes/_cross_rate_mode_fields.slim +21 -0
- data/app/views/gera/currency_rate_modes/_currency_rate_mode.slim +7 -0
- data/app/views/gera/currency_rate_modes/_form.slim +29 -0
- data/app/views/gera/currency_rate_modes/edit.slim +11 -0
- data/app/views/gera/currency_rate_modes/index.html.slim +12 -0
- data/app/views/gera/currency_rates/_currency_rate.slim +22 -0
- data/app/views/gera/currency_rates/_currency_rate_humanized.slim +35 -0
- data/app/views/gera/currency_rates/diff.slim +12 -0
- data/app/views/gera/currency_rates/index.slim +27 -0
- data/app/views/gera/currency_rates/modes.slim +14 -0
- data/app/views/gera/currency_rates/show.slim +4 -0
- data/app/views/gera/direction_rate_history_intervals/_filter.slim +11 -0
- data/app/views/gera/direction_rate_history_intervals/index.slim +41 -0
- data/app/views/gera/direction_rates/_direction_rate_example_calculator.slim +28 -0
- data/app/views/gera/direction_rates/diff.slim +19 -0
- data/app/views/gera/direction_rates/index.slim +26 -0
- data/app/views/gera/direction_rates/legacy.html.slim +5 -0
- data/app/views/gera/direction_rates/minimals.slim +5 -0
- data/app/views/gera/direction_rates/show.slim +14 -0
- data/app/views/gera/external_rate_snapshots/index.slim +25 -0
- data/app/views/gera/external_rate_snapshots/show.slim +22 -0
- data/app/views/gera/external_rates/_flat_list.slim +22 -0
- data/app/views/gera/external_rates/index.html.slim +28 -0
- data/app/views/gera/external_rates/show.slim +1 -0
- data/app/views/gera/payment_systems/_fields.slim +4 -0
- data/app/views/gera/payment_systems/_fields_table.slim +18 -0
- data/app/views/gera/payment_systems/_form.slim +9 -0
- data/app/views/gera/payment_systems/edit.slim +7 -0
- data/app/views/gera/payment_systems/index.slim +3 -0
- data/app/views/gera/payment_systems/new.slim +9 -0
- data/app/views/gera/payment_systems/show.slim +1 -0
- data/app/views/gera/rate_sources/_list.slim +13 -0
- data/app/views/gera/rate_sources/_rate_source.slim +23 -0
- data/app/views/gera/rate_sources/index.html.slim +6 -0
- data/app/views/layouts/application.html.slim +15 -0
- data/app/views/layouts/gera/blank.html.slim +10 -0
- data/app/workers/concerns/gera/rates_worker.rb +87 -0
- data/app/workers/gera/bitfinex_rates_worker.rb +65 -0
- data/app/workers/gera/cbr_avg_rates_worker.rb +42 -0
- data/app/workers/gera/cbr_rates_worker.rb +192 -0
- data/app/workers/gera/create_history_intervals_worker.rb +38 -0
- data/app/workers/gera/currency_rates_worker.rb +64 -0
- data/app/workers/gera/directions_rates_worker.rb +51 -0
- data/app/workers/gera/exmo_rates_worker.rb +62 -0
- data/app/workers/gera/purge_currency_rates_worker.rb +21 -0
- data/app/workers/gera/purge_direction_rates_worker.rb +30 -0
- data/config/currencies.yml +559 -0
- data/config/routes.rb +30 -0
- data/db/migrate/20180912130000_setup.rb +228 -0
- data/db/migrate/20190314114844_add_is_available_to_payment_systems.rb +7 -0
- data/db/migrate/20190315113046_add_icon_url_to_payment_systems.rb +7 -0
- data/db/migrate/20190315132137_add_commission_to_payment_systems.rb +7 -0
- data/lib/banks/currency_exchange.rb +12 -0
- data/lib/builders/currency_rate_auto_builder.rb +38 -0
- data/lib/builders/currency_rate_builder.rb +60 -0
- data/lib/builders/currency_rate_cross_builder.rb +70 -0
- data/lib/builders/currency_rate_direct_builder.rb +26 -0
- data/lib/gera.rb +32 -0
- data/lib/gera/bitfinex_fetcher.rb +36 -0
- data/lib/gera/configuration.rb +47 -0
- data/lib/gera/currencies_purger.rb +28 -0
- data/lib/gera/currency_pair.rb +93 -0
- data/lib/gera/engine.rb +14 -0
- data/lib/gera/mathematic.rb +156 -0
- data/lib/gera/money_support.rb +89 -0
- data/lib/gera/numeric.rb +25 -0
- data/lib/gera/railtie.rb +8 -0
- data/lib/gera/rate.rb +22 -0
- data/lib/gera/rate_from_multiplicator.rb +54 -0
- data/lib/gera/repositories/currency_rate_modes_repository.rb +37 -0
- data/lib/gera/repositories/currency_rates_repository.rb +25 -0
- data/lib/gera/repositories/direction_rates_repository.rb +46 -0
- data/lib/gera/repositories/exchange_rates_repository.rb +23 -0
- data/lib/gera/repositories/payment_systems_repository.rb +21 -0
- data/lib/gera/repositories/universe.rb +47 -0
- data/lib/gera/version.rb +3 -0
- data/lib/tasks/auto_generate_diagram.rake +6 -0
- data/lib/tasks/gera_tasks.rake +4 -0
- metadata +765 -0
data/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Gera
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/finfex/gera)
|
|
4
|
+
|
|
5
|
+
Multiple rates generator for crypto changers and markets.
|
|
6
|
+
|
|
7
|
+
## Осуществляет
|
|
8
|
+
|
|
9
|
+
* Регулярный (ежесекундный) сбор и хранение курсов (`ExternalRate`) из внешних источников (`RateSource`)
|
|
10
|
+
* Построение и хранение матрицы базовых курсов (`CurrencyRate`) для поддерживаемых валют из курсов внешних истичников (`ExternalRate`) на основе установленного метода расчета (`CurrencyRateMode`) автоматически или через кросс-курсы.
|
|
11
|
+
* Построение и хранение матрицы конечных курсов (`DirectionRate`) для поддерживаемых платежных сервисов (`PaymentSystem`) с установленной комиссией (`ExchangeRate`)
|
|
12
|
+
* Регулярная группировка базовых и конечных курсов в N-минутные отрезки со свечками для истории (`CurrencyRateHistoryInterval` и `DirectionRateHistoryInterval`)
|
|
13
|
+
* Регулярная очистка матриц ежесекундных курсов (за сутки накапливается несколько гигабайт)
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Add this line to your application's Gemfile:
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
gem 'gera'
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
And then execute:
|
|
24
|
+
```bash
|
|
25
|
+
$ bundle
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or install it yourself as:
|
|
29
|
+
```bash
|
|
30
|
+
$ gem install gera
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Configuration
|
|
34
|
+
|
|
35
|
+
Add `./config/initializers/gera.rb` with this content:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
Gera.configure do |config|
|
|
39
|
+
config.cross_pairs = { kzt: :rub, eur: :rub }
|
|
40
|
+
end
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Supported external sources of basic rates
|
|
44
|
+
|
|
45
|
+
* EXMO, Russian Central Bank, Bitfinex, Manual
|
|
46
|
+
|
|
47
|
+
## Supported currencies
|
|
48
|
+
|
|
49
|
+
* RUB, USD, BTC, LTC, ETH, DSH, KZT, XRP, ETC, XMR, BCH, EUR, NEO, ZEC
|
|
50
|
+
|
|
51
|
+
## Database
|
|
52
|
+
|
|
53
|
+
SQL tables diagram - https://github.com/finfex/gera/blob/master/doc/erd.pdf
|
|
54
|
+
|
|
55
|
+
## TODO
|
|
56
|
+
|
|
57
|
+
* move Authority to application level
|
|
58
|
+
* Remove STI from RateSource
|
|
59
|
+
|
|
60
|
+
## Contributing
|
|
61
|
+
|
|
62
|
+
* Fork
|
|
63
|
+
* Create Pull Request
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
The gem is available as open source under the terms of the [GPLv3](https://opensource.org/licenses/GPL-3.0).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'rdoc/task'
|
|
8
|
+
|
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
11
|
+
rdoc.title = 'Gera'
|
|
12
|
+
rdoc.options << '--line-numbers'
|
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
|
|
18
|
+
load 'rails/tasks/engine.rake'
|
|
19
|
+
|
|
20
|
+
load 'rails/tasks/statistics.rake'
|
|
21
|
+
|
|
22
|
+
require 'bundler/gem_tasks'
|
|
23
|
+
|
|
24
|
+
begin
|
|
25
|
+
require 'rspec/core/rake_task'
|
|
26
|
+
|
|
27
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
28
|
+
|
|
29
|
+
task :default => :spec
|
|
30
|
+
rescue LoadError
|
|
31
|
+
puts 'no rspec available'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
load 'lib/tasks/auto_generate_diagram.rake'
|
|
35
|
+
|
|
36
|
+
require "yard"
|
|
37
|
+
if defined? YARD
|
|
38
|
+
YARD::Rake::YardocTask.new do |t|
|
|
39
|
+
t.files = ['lib/**/*.rb', 'app/**/*.rb'] # optional
|
|
40
|
+
t.options = ['--any', '--extra', '--opts'] # optional
|
|
41
|
+
t.stats_options = ['--list-undoc'] # optional
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
|
9
|
+
//
|
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
|
11
|
+
// about supported directives.
|
|
12
|
+
//
|
|
13
|
+
//= require rails-ujs
|
|
14
|
+
//= require_tree .
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
|
11
|
+
* It is generally better to create a new file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'application_authorizer'
|
|
4
|
+
module Gera
|
|
5
|
+
class PaymentSystemAuthorizer < ApplicationAuthorizer
|
|
6
|
+
# Для изменения не админами запрещено менять все кроме разрешенных
|
|
7
|
+
WHITE_LIST = %w[income_enabled outcome_enabled referal_output_enabled].freeze
|
|
8
|
+
|
|
9
|
+
def self.restricted_attributes
|
|
10
|
+
(Gera::PaymentSystem.attribute_names - WHITE_LIST).freeze
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Gera
|
|
4
|
+
class ApplicationController < ::ApplicationController
|
|
5
|
+
helper Gera::ApplicationHelper
|
|
6
|
+
helper Gera::CurrencyRateModesHelper
|
|
7
|
+
helper Gera::DirectionRateHelper
|
|
8
|
+
|
|
9
|
+
protect_from_forgery with: :exception
|
|
10
|
+
|
|
11
|
+
ensure_authorization_performed
|
|
12
|
+
|
|
13
|
+
helper_method :payment_systems
|
|
14
|
+
helper_method :query_params
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def query_params
|
|
19
|
+
params.fetch(:q, {}).permit!
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def app_title
|
|
23
|
+
"GERA #{VERSION}"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def payment_systems
|
|
27
|
+
@payment_systems ||= Universe.payment_systems.available
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'application_controller'
|
|
4
|
+
module Gera
|
|
5
|
+
class CurrencyRateHistoryIntervalsController < ApplicationController
|
|
6
|
+
authorize_actions_for CurrencyRate
|
|
7
|
+
helper_method :filter
|
|
8
|
+
|
|
9
|
+
def index
|
|
10
|
+
respond_to do |format|
|
|
11
|
+
format.html { render locals: { title: title, value_decimals: value_decimals } }
|
|
12
|
+
format.json { render json: intervals }
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def value_decimals
|
|
19
|
+
4
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def title
|
|
23
|
+
"График базового курса для направление #{filter.cur_from}->#{filter.cur_to}"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def filter
|
|
27
|
+
@filter ||= CurrencyRateHistoryIntervalFilter.new params.fetch(:currency_rate_history_interval_filter, {}).permit!
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def prepare_rate_value(value)
|
|
31
|
+
inverse? ? 1.0 / value : value
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def inverse?
|
|
35
|
+
false
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def intervals
|
|
39
|
+
scope = Gera::CurrencyRateHistoryInterval
|
|
40
|
+
.where(cur_to_id: filter.currency_to.local_id, cur_from_id: filter.currency_from.local_id)
|
|
41
|
+
.order(:interval_from)
|
|
42
|
+
|
|
43
|
+
case filter.value_type
|
|
44
|
+
when 'rate'
|
|
45
|
+
scope
|
|
46
|
+
.pluck(:interval_from, :min_rate, :max_rate)
|
|
47
|
+
.map { |time, min, max| [time.to_f * 1000, prepare_rate_value(min), prepare_rate_value(max), prepare_rate_value(min), prepare_rate_value(max)] }
|
|
48
|
+
else
|
|
49
|
+
raise "Unknown value_type #{filter.value_type}"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'application_controller'
|
|
4
|
+
module Gera
|
|
5
|
+
class CurrencyRateModeSnapshotsController < ApplicationController
|
|
6
|
+
authorize_actions_for CurrencyRateMode
|
|
7
|
+
authority_actions activate: :create
|
|
8
|
+
|
|
9
|
+
helper_method :view_mode
|
|
10
|
+
|
|
11
|
+
def index
|
|
12
|
+
redirect_to edit_currency_rate_mode_snapshot_path Universe.currency_rate_modes_repository.snapshot
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def edit
|
|
16
|
+
if snapshot.status_draft?
|
|
17
|
+
render :edit, locals: {
|
|
18
|
+
snapshot: snapshot
|
|
19
|
+
}
|
|
20
|
+
else
|
|
21
|
+
redirect_to currency_rate_mode_snapshot_path snapshot
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def show
|
|
26
|
+
if snapshot.status_draft?
|
|
27
|
+
redirect_to edit_currency_rate_mode_snapshot_path snapshot
|
|
28
|
+
else
|
|
29
|
+
render :edit, locals: {
|
|
30
|
+
snapshot: snapshot
|
|
31
|
+
}
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def activate
|
|
36
|
+
snapshot.transaction do
|
|
37
|
+
CurrencyRateModeSnapshot.status_active.update_all status: :deactive
|
|
38
|
+
snapshot.update status: :active
|
|
39
|
+
end
|
|
40
|
+
CurrencyRatesWorker.perform_async if Rails.env.production?
|
|
41
|
+
flash[:success] = 'Режимы активированы'
|
|
42
|
+
redirect_to currency_rate_mode_snapshot_path snapshot
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def update
|
|
46
|
+
snapshot.update permitted_params
|
|
47
|
+
respond_to do |format|
|
|
48
|
+
format.json { respond_with_bip(snapshot) }
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def create
|
|
53
|
+
flash[:success] = 'Создана новая матрица методов расчета'
|
|
54
|
+
redirect_to edit_currency_rate_mode_snapshot_path(create_draft_snapshot)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def view_mode
|
|
60
|
+
if params[:view_mode] == 'calculations'
|
|
61
|
+
:calculations
|
|
62
|
+
else
|
|
63
|
+
:methods
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def snapshot
|
|
68
|
+
CurrencyRateModeSnapshot.find params[:id]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def find_last_draft_snapshot
|
|
72
|
+
CurrencyRateModeSnapshot.status_draft.last
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def create_draft_snapshot
|
|
76
|
+
CurrencyRateModeSnapshot.create!
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def permitted_params
|
|
80
|
+
params.require(:currency_rate_mode_snapshot).permit!
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'application_controller'
|
|
4
|
+
module Gera
|
|
5
|
+
class CurrencyRateModesController < ApplicationController
|
|
6
|
+
authorize_actions_for CurrencyRateMode
|
|
7
|
+
|
|
8
|
+
helper_method :success_url
|
|
9
|
+
|
|
10
|
+
def new
|
|
11
|
+
render :edit, locals: {
|
|
12
|
+
currency_rate_mode: snapshot.currency_rate_modes.build(permitted_params)
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def create
|
|
17
|
+
CurrencyRateMode.create! permitted_params
|
|
18
|
+
|
|
19
|
+
flash[:success] = 'Метод создан'
|
|
20
|
+
redirect_to success_url
|
|
21
|
+
rescue ActiveRecord::RecordInvalid => e
|
|
22
|
+
render :edit, locals: { currency_rate_mode: e.record }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def edit
|
|
26
|
+
render :edit, locals: { currency_rate_mode: currency_rate_mode }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def update
|
|
30
|
+
currency_rate_mode.update! permitted_params
|
|
31
|
+
|
|
32
|
+
flash[:success] = 'Метод изменен'
|
|
33
|
+
redirect_to success_url
|
|
34
|
+
rescue ActiveRecord::RecordInvalid => e
|
|
35
|
+
render :edit, locals: { currency_rate_mode: e.record }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def snapshot
|
|
41
|
+
@snapshot ||= CurrencyRateModeSnapshot.find permitted_params[:currency_rate_mode_snapshot_id]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def success_url
|
|
45
|
+
params[:back] || edit_currency_rate_mode_snapshot_path(currency_rate_mode.snapshot)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def currency_rate_mode
|
|
49
|
+
CurrencyRateMode.find params[:id]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def current_snapshot
|
|
53
|
+
Universe.currency_rate_modes_repository.snapshot
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def permitted_params
|
|
57
|
+
params.require(:currency_rate_mode).permit!
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|