c80_shared 0.1.90 → 0.1.91
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/app/validators/boats/is_for_rent.rb +22 -0
- data/app/validators/boats/is_for_sell.rb +19 -0
- data/app/validators/currency_presence_validator.rb +17 -0
- data/app/validators/dimension_presence_validator.rb +17 -0
- data/app/validators/sale_inquiry_assign_validator.rb +8 -0
- data/app/validators/sale_inquiry_comment_validator.rb +9 -0
- data/app/validators/user_permission_validator.rb +7 -0
- data/lib/c80_shared/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a2219673943c0915b6c4af2234ab8b13086367662c5bf3234c5b8b979a2e9fa
|
4
|
+
data.tar.gz: 8131f51241e8efca07679e0f4f0f5959f4f5635222944afe47c958c4331f8b78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e9796bbf0124b75a66b560065a925c814c85dbb98b56841ebaafc9561f098cf3d2a01eada05bcce451f7356b900c1620298ba8edc676bbbfcf397e9e6f4de49
|
7
|
+
data.tar.gz: 62b40f6dc28d0cdc21628b2c4d31fb1b743abe723b5cab830d36dd854aac6e4b9beda8230fd86c9f2151edd46b23d5d397f4d50df4d8570a5085a99c3257170f
|
data/Gemfile.lock
CHANGED
@@ -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
|
data/lib/c80_shared/version.rb
CHANGED
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.
|
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-
|
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
|