c80_shared 0.1.90 → 0.1.91

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b74798e7fa2ba84239918bc247e89ceca53912539ae784d14ba6556c0ba13a1
4
- data.tar.gz: b6123aae96bf2611736b5005b2459da881e906e8a9476d067229e975cd00fa1c
3
+ metadata.gz: 8a2219673943c0915b6c4af2234ab8b13086367662c5bf3234c5b8b979a2e9fa
4
+ data.tar.gz: 8131f51241e8efca07679e0f4f0f5959f4f5635222944afe47c958c4331f8b78
5
5
  SHA512:
6
- metadata.gz: e6ccb76fbbd4df0cf0297c821711e79dd9e3059cb61fad4b20d379244e4937eef719acd1f1c59908f5a0fff595821def85b0b8f18422bce1c011034c8cd5cee1
7
- data.tar.gz: 9fb4506fab81c11b4ccd8b4fa96a19251c5f39767f187c19b177ff9277fb8ccc97cb289b4566dda9e916ffa894640fd2473140e5c6e03cb3e295f30a248794f8
6
+ metadata.gz: 7e9796bbf0124b75a66b560065a925c814c85dbb98b56841ebaafc9561f098cf3d2a01eada05bcce451f7356b900c1620298ba8edc676bbbfcf397e9e6f4de49
7
+ data.tar.gz: 62b40f6dc28d0cdc21628b2c4d31fb1b743abe723b5cab830d36dd854aac6e4b9beda8230fd86c9f2151edd46b23d5d397f4d50df4d8570a5085a99c3257170f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- c80_shared (0.1.89)
4
+ c80_shared (0.1.90)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -0,0 +1,22 @@
1
+ module Boats
2
+ # определяем, указана ли хоть какая-нибудь цена аренды?
3
+ #
4
+ module IsForRent
5
+ module_function
6
+
7
+ # @param [Boat || Form] record
8
+ # @return [TrueClass || FalseClass]
9
+ #
10
+ def check?(record)
11
+ ::Dictionaries::BoatCharterAttribute::ALL.map do |attr|
12
+ ::Dicts::Currency::ALL.map do |currency|
13
+ field = Currency.attribute_name currency.index, attr
14
+ value = record.try field
15
+ # puts '%s = %s' % [field, value]
16
+ # noinspection RubySimplifyBooleanInspection
17
+ !!(value&.>0)
18
+ end
19
+ end.flatten.any?
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module Boats
2
+ # определяем, указана ли хоть какая-нибудь цена продажи?
3
+ #
4
+ module IsForSell
5
+ module_function
6
+
7
+ # @param [Boat] record
8
+ # @return [TrueClass || FalseClass]
9
+ #
10
+ def check?(record)
11
+ ::Dicts::Currency::ALL.map do |currency|
12
+ field = Currency.attribute_name currency.index, 'sale_price'
13
+ value = record.send field
14
+ # noinspection RubySimplifyBooleanInspection
15
+ !!(value&.>0)
16
+ end.any?
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ class CurrencyPresenceValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ unless record.currency
4
+ raise ArgumentError, 'record.currency does not exist'
5
+ end
6
+ available_currencies = I18n::t('static.currencies').map{|currency| currency[:id]}
7
+ record_currency = record.currency.upcase
8
+ if available_currencies.include? record_currency
9
+ attribute_currency = attribute.to_s.split('_')[-1].upcase
10
+ if record_currency == attribute_currency && record.attributes[attribute.to_s].nil?
11
+ record.errors[attribute] << "can't be blank!"
12
+ end
13
+ else
14
+ raise ArgumentError, 'Model record.currency does not exist in I18n::t(\'static.currencies\')'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ class DimensionPresenceValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ unless record.dimension
4
+ raise ArgumentError, 'record.dimension does not exist'
5
+ end
6
+ available_dimensions = I18n::t('static.dimensions').map{|dimension| dimension[:id]}
7
+ record_dimension = record.dimension.downcase
8
+ if available_dimensions.include? record_dimension
9
+ attribute_dimension = attribute.to_s.split('_')[-1].downcase
10
+ if record_dimension == attribute_dimension && record.attributes[attribute.to_s].nil?
11
+ record.errors[attribute] << "can't be blank!"
12
+ end
13
+ else
14
+ raise ArgumentError, 'Model record.dimension does not exist in I18n::(\'static.dimensions\')'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ class SaleInquiryAssignValidator < ActiveModel::Validator
2
+ def validate(record)
3
+ record.errors.add(:sale_inquiry, :blank) and return false if record.sale_inquiry.nil?
4
+ record.errors.add(:assignee, :blank) and return false if record.assignee.nil?
5
+ record.errors.add(:author, :blank) and return false if record.author.nil?
6
+ true
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ class SaleInquiryCommentValidator < ActiveModel::Validator
2
+ def validate(record)
3
+ record.errors.add(:sale_inquiry, :blank) and return false if record.sale_inquiry.nil?
4
+ record.errors.add(:author, :blank) and return false if record.author.nil?
5
+ record.errors.add(:text, :blank) and return false unless record.text.present?
6
+ record.errors.add(:text, :less_than_or_equal_to, count: 1024) and return false if record.text.size > 1024
7
+ true
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ class UserPermissionValidator < ActiveModel::Validator
2
+ def validate(record)
3
+ record.errors.add(:can, :blank) and return false if record.can.nil?
4
+ record.errors.add(:action, :blank) and return false if record.action.nil?
5
+ true
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module C80Shared
2
- VERSION = "0.1.90"
2
+ VERSION = "0.1.91"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: c80_shared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.90
4
+ version: 0.1.91
5
5
  platform: ruby
6
6
  authors:
7
7
  - C80609A
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-07 00:00:00.000000000 Z
11
+ date: 2020-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -120,6 +120,13 @@ files:
120
120
  - app/services/sale/inquiry_asked_prices_save_service.rb
121
121
  - app/services/users/find_or_generate_email_token_service.rb
122
122
  - app/services/users/generate_email_token_service.rb
123
+ - app/validators/boats/is_for_rent.rb
124
+ - app/validators/boats/is_for_sell.rb
125
+ - app/validators/currency_presence_validator.rb
126
+ - app/validators/dimension_presence_validator.rb
127
+ - app/validators/sale_inquiry_assign_validator.rb
128
+ - app/validators/sale_inquiry_comment_validator.rb
129
+ - app/validators/user_permission_validator.rb
123
130
  - bin/console
124
131
  - bin/rails
125
132
  - bin/setup