c80_shared 0.0.1 → 0.1.0

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
- SHA1:
3
- metadata.gz: f5c4e9ba0cf5b537e7e36a3f6944b202ac3ceeeb
4
- data.tar.gz: 9cf30c41a5a13351d090c0df8ec53d631bfab0cb
2
+ SHA256:
3
+ metadata.gz: 07d6a6f13128993e4fd9f9cfa5b8b67c00f6bd1848ef7aac889e9770869f044a
4
+ data.tar.gz: 649bc6d41b1f052d3e728678a07883022376cbdf2592d40000572e6cc878a2f3
5
5
  SHA512:
6
- metadata.gz: f4aeef460e0c2f724faabadde587b7f48a6d5008c2de7a52e1c8f1fab8926c3e21b816cba8d55ba876818a71782631fe4e3ce6e243b422641770d3e7ec742c44
7
- data.tar.gz: d9789f0c2e923780361cbddacf6c02d8f41b2db55b29cf0a205ce797da9c997ccf99d280e1de54c472ba8ed1ff16b46c596ef61330c50c166c726344646ea640
6
+ metadata.gz: 39c32316674c3f9536666fe30a4e85a61f1e7a5ceeec8d99ba24ea5eabc6c8f762fb1548e80205baf17f87f5f6c9b32bac4db36d3ad2861568df9e9062a4d1a4
7
+ data.tar.gz: 755b7afc763fc23ac8470887f08fa07021cd86d8e9db7f954a6f2ecd836f458b4dda9a4ffe4a8bc139c728c5c268ae087a411b637cf5c638b2939b18a00186a2
@@ -0,0 +1,9 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,52 @@
1
+ Style/AsciiComments:
2
+ Description: 'Use only ascii symbols in comments.'
3
+ StyleGuide: '#english-comments'
4
+ Enabled: false
5
+ Style/FrozenStringLiteralComment:
6
+ Enabled: false
7
+ Style/CommentedKeyword:
8
+ Enabled: false
9
+ Style/SymbolArray:
10
+ Enabled: false
11
+ Metrics/LineLength:
12
+ Max: 120
13
+ Enabled: false
14
+ Metrics/MethodLength:
15
+ CountComments: false # count full line comments?
16
+ Max: 20
17
+ Enabled: false
18
+ Metrics/ModuleLength:
19
+ CountComments: false # count full line comments?
20
+ Max: 150
21
+ Metrics/ClassLength:
22
+ CountComments: false # count full line comments?
23
+ Max: 150
24
+ Metrics/ParameterLists:
25
+ Max: 3
26
+ CountKeywordArgs: true
27
+ Layout/LeadingCommentSpace:
28
+ Enabled: false
29
+ Layout/SpaceBeforeComment:
30
+ Enabled: false
31
+ Layout/ExtraSpacing:
32
+ Enabled: false
33
+ Layout/CaseIndentation:
34
+ Enabled: false
35
+ Layout/TrailingWhitespase:
36
+ Enabled: false
37
+ Layout/SpaceAroundOperators:
38
+ Enabled: false
39
+ Style/FormatString:
40
+ Enabled: false
41
+ Style/FormatStringToken:
42
+ Enabled: false
43
+ Layout/AlignParameters:
44
+ Enabled: false
45
+ Metrics/BlockNesting:
46
+ Enabled: false
47
+ Layout/TrailingWhitespace:
48
+ Enabled: false
49
+ Metrics/AbcSize:
50
+ Enabled: false
51
+ Style/Documentation:
52
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in c80_shared.gemspec
6
+ gemspec
@@ -0,0 +1,35 @@
1
+ # C80Shared
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/c80_shared`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'c80_shared'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install c80_shared
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/c80_shared.
@@ -1,7 +1,8 @@
1
1
  module Dicts
2
2
  class EmailTokenSubj < ::Dict
3
- TO_AGENT_NEW_ORDER = new(1, 'to_agent_new_order')
4
- TO_AGENT_ACCEPTED_BID = new(2, 'to_agent_accepted_bid')
5
- TO_CLIENT_NEW_BID = new(3, 'to_client_new_bid')
3
+ TO_CLIENT_NEW_INQUIRY = new(1, 'to_client_new_inquiry')
4
+ TO_AGENT_NEW_INQUIRY = new(2, 'to_agent_new_inquiry')
5
+ TO_CLIENT_NEW_BID = new(3, 'to_client_new_bid')
6
+ TO_AGENT_ACCEPTED_BID = new(4, 'to_agent_accepted_bid')
6
7
  end
7
8
  end
@@ -0,0 +1,33 @@
1
+ module Site
2
+ module TimeHelper
3
+
4
+ def next_hour(value)
5
+ value == 23 ? 0 : value + 1
6
+ end
7
+
8
+ # Вернёт отформатированную строку с датой ~ от локали.
9
+ # @param with_time [Boolean] Если true - вернёт и время
10
+ #
11
+ def format_date(date, locale, with_time = false)
12
+ date.strftime locale_date_format(locale, with_time)
13
+ end
14
+
15
+ # В зависимости от локали выдаст соответствующий формат для отображения дат.
16
+ # https://en.wikipedia.org/wiki/Date_format_by_country
17
+ # @param with_time [Boolean] Если true - вернёт и время
18
+ #
19
+ def locale_date_format(locale, with_time = false)
20
+ res = case locale.to_s
21
+ when 'en'
22
+ '%Y/%m/%d'
23
+ when 'ru'
24
+ '%d.%m.%Y'
25
+ else
26
+ '%Y/%m/%d'
27
+ end
28
+
29
+ res += ' %H:%M' if with_time
30
+ res
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,162 @@
1
+ module Lease
2
+ class InquirySerializer < ::AbstractSerializer
3
+
4
+ extend ::Site::TimeHelper
5
+
6
+ class << self
7
+
8
+ def available_attributes
9
+ [
10
+ :id,
11
+ :token,
12
+ :account_id,
13
+ :state,
14
+ :is_skippered,
15
+ :is_my_price,
16
+ :my_price,
17
+ :my_price_currency,
18
+ :address,
19
+ :latitude,
20
+ :longitude,
21
+ :period,
22
+ :duration,
23
+ :from,
24
+ :to,
25
+ :guests,
26
+ :kids,
27
+ :watersports,
28
+ :need_transfer,
29
+ :email,
30
+ :name,
31
+ :phone_number,
32
+ :comments,
33
+ :created_at,
34
+ :created_at_full,
35
+ :boat_types
36
+ ].freeze
37
+ end
38
+
39
+ def id(inquiry)
40
+ { id: inquiry.id }
41
+ end
42
+
43
+ def account_id(inquiry)
44
+ { account_id: inquiry.account_id }
45
+ end
46
+
47
+ def state(inquiry)
48
+ { state: inquiry.state }
49
+ end
50
+
51
+ def token(inquiry)
52
+ { token: inquiry.token }
53
+ end
54
+
55
+ def is_skippered(inquiry)
56
+ { is_skippered: inquiry.is_skippered }
57
+ end
58
+
59
+ def guests(inquiry)
60
+ { guests: inquiry.guests }
61
+ end
62
+
63
+ def kids(inquiry)
64
+ { kids: inquiry.kids }
65
+ end
66
+
67
+ def watersports(inquiry)
68
+ { watersports: inquiry.watersports }
69
+ end
70
+
71
+ def need_transfer(inquiry)
72
+ { need_transfer: inquiry.need_transfer }
73
+ end
74
+
75
+ def comments(inquiry)
76
+ { comments: inquiry.comments }
77
+ end
78
+
79
+ def created_at(inquiry)
80
+ { created_at: format_date(inquiry.created_at, @opts[:locale]) }
81
+ end
82
+
83
+ def created_at_full(inquiry)
84
+ { created_at_full: format_date(inquiry.created_at, @opts[:locale], true) }
85
+ end
86
+
87
+ def address(inquiry)
88
+ { address: inquiry.address }
89
+ end
90
+
91
+ def latitude(inquiry)
92
+ { latitude: inquiry.latitude.to_f }
93
+ end
94
+
95
+ def longitude(inquiry)
96
+ { longitude: inquiry.longitude.to_f }
97
+ end
98
+
99
+ def email(inquiry)
100
+ { email: inquiry.client_account.account.user.email }
101
+ end
102
+
103
+ def name(inquiry)
104
+ { name: inquiry.name }
105
+ end
106
+
107
+ def phone_number(inquiry)
108
+ { phone_number: inquiry.phone_number }
109
+ end
110
+
111
+ def period(inquiry)
112
+ { period: '%s - %s' % [from(inquiry)[:from], to(inquiry)[:to]] }
113
+ end
114
+
115
+ def duration(inquiry)
116
+ distance = (inquiry.to - inquiry.from).to_i / 24 / 60 / 60
117
+ distance = distance.zero? ? 1 : distance
118
+ uom = I18n.t('activerecord.labels.lease/bid.day', count: distance)
119
+ {
120
+ duration: {
121
+ distance: distance,
122
+ uom: uom
123
+ }
124
+ }
125
+ end
126
+
127
+ def from(inquiry)
128
+ { from: format_date(inquiry.from, @opts[:locale]) }
129
+ end
130
+
131
+ def to(inquiry)
132
+ { to: format_date(inquiry.to, @opts[:locale]) }
133
+ end
134
+
135
+ def is_my_price(inquiry)
136
+ { is_my_price: inquiry.is_my_price }
137
+ end
138
+
139
+ def my_price(inquiry)
140
+ { my_price: inquiry.my_price }
141
+ end
142
+
143
+ def my_price_currency(inquiry)
144
+ { my_price_currency: inquiry.my_price_currency }
145
+ end
146
+
147
+ def boat_types(inquiry)
148
+ boat_types = BoatType.where(id: inquiry.boat_type_ids).includes(:translations)
149
+ {
150
+ boat_types: boat_types.map do |bt|
151
+ {
152
+ id: bt.id,
153
+ name: bt.name,
154
+ icon: bt.icon.url
155
+ }
156
+ end
157
+ }
158
+ end
159
+
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "c80_shared"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "c80_shared/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "c80_shared"
7
+ spec.version = C80Shared::VERSION
8
+ spec.authors = ["C80609A"]
9
+ spec.email = ["c080609a@gmail.com"]
10
+
11
+ spec.summary = %q{Write a short summary, because RubyGems requires one.}
12
+ spec.description = %q{Write a longer description or delete this line.}
13
+ spec.homepage = "http://google.com"
14
+ spec.license = 'MIT'
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
@@ -0,0 +1,21 @@
1
+ # загружаем библиотечные классы
2
+ lambda do
3
+ lib_path = '%s/**/*.rb' % File.expand_path('../c80_shared', __FILE__)
4
+ # noinspection RubyResolve
5
+ Dir[lib_path].each { |f| require_relative f }
6
+ end.call
7
+
8
+ # загружаем все классы из директории app
9
+ lambda do
10
+ lib_path = File.expand_path('../../app', __FILE__)
11
+ dir_names = %w[dicts helpers serializers] # order matters!
12
+
13
+ dir_names.each do |dir|
14
+ dir_path = '%s/%s/**/*.rb' % [lib_path, dir]
15
+ # noinspection RubyResolve
16
+ Dir[dir_path].each { |f| require_relative f }
17
+ end
18
+ end.call
19
+
20
+ module C80Shared
21
+ end
@@ -0,0 +1,28 @@
1
+ class AbstractSerializer
2
+
3
+ # extend ActionView::Helpers::NumberHelper
4
+ # extend ApplicationHelper
5
+
6
+ class << self
7
+
8
+ def serialize(model, attributes: available_attributes, opts: {})
9
+ @opts = opts
10
+ unknown_attributes = attributes - available_attributes
11
+
12
+ if unknown_attributes.present?
13
+ raise StandardError, sprintf('Unknown attributes: %s', unknown_attributes.join(', '))
14
+ end
15
+
16
+ attributes.each_with_object({}) { |attribute, result| result.merge!(send(attribute, model)) }
17
+ end
18
+
19
+ def available_attributes
20
+ []
21
+ end
22
+
23
+ def opts
24
+ @opts
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ # Базовый класс для словарей из Dicts.
2
+ #
3
+ class Dict
4
+ attr_reader :id, :index
5
+
6
+ def initialize(id, index)
7
+ @id = id
8
+ @index = index
9
+ end
10
+
11
+ def self.all
12
+ constants.map { |const| const_get const }
13
+ end
14
+
15
+ def self.find(id)
16
+ all.select { |const| const.id == id.to_i }.first
17
+ end
18
+
19
+ def self.where(ids)
20
+ all.select { |const| ids.include?(const.id) }
21
+ end
22
+ end
@@ -0,0 +1,46 @@
1
+ # Когда база с боевого используется процессе разработки,
2
+ # вместо того, чтобы искать изображения локально,
3
+ # отправляем запрос на боевой сервер.
4
+ #
5
+ # ::usage::
6
+ #
7
+ # Rails.application.configure do
8
+ # config.middleware.use ImagesProxy
9
+ # end
10
+ #
11
+ # ::dependency::
12
+ #
13
+ # gem 'rack-proxy'
14
+ #
15
+ #
16
+ class ImagesProxy < Rack::Proxy
17
+
18
+ NEED_FAKE = /(system|ckeditor)/i # в урле должно содержаться это, чтобы запрос ушёл на боевой
19
+ HOST = 'getboat.com:80'.freeze # боевой адрес + порт
20
+
21
+ def initialize(app)
22
+ @app = app
23
+ end
24
+
25
+ def call(env)
26
+ original_host = env['HTTP_HOST']
27
+ rewrite_env(env)
28
+ if env['HTTP_HOST'] != original_host
29
+ perform_request(env)
30
+ else
31
+ # just regular
32
+ @app.call(env)
33
+ end
34
+ end
35
+
36
+ def rewrite_env(env)
37
+ path = Rack::Request.new(env).path
38
+ if path =~ NEED_FAKE && !File.exists?(path)
39
+ env['HTTP_HOST'] = HOST
40
+ env['SERVER_PORT'] = 80
41
+ else
42
+ # do nothing
43
+ end
44
+ env
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module C80Shared
2
+ VERSION = "0.1.0"
3
+ end
metadata CHANGED
@@ -1,28 +1,65 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: c80_shared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - C80609A
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-04 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Description of Shared.
11
+ date: 2018-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Write a longer description or delete this line.
14
42
  email:
15
43
  - c080609a@gmail.com
16
44
  executables: []
17
45
  extensions: []
18
46
  extra_rdoc_files: []
19
47
  files:
20
- - MIT-LICENSE
21
- - README.rdoc
48
+ - ".gitignore"
49
+ - ".rubocop.yml"
50
+ - Gemfile
51
+ - README.md
22
52
  - app/dicts/email_token_subj.rb
23
- - lib/shared.rb
24
- - lib/shared/engine.rb
25
- - lib/shared/version.rb
53
+ - app/helpers/site/time_helper.rb
54
+ - app/serializers/lease/inquiry_serializer.rb
55
+ - bin/console
56
+ - bin/setup
57
+ - c80_shared.gemspec
58
+ - lib/c80_shared.rb
59
+ - lib/c80_shared/abstract_serializer.rb
60
+ - lib/c80_shared/dict.rb
61
+ - lib/c80_shared/middleware/images_proxy.rb
62
+ - lib/c80_shared/version.rb
26
63
  homepage: http://google.com
27
64
  licenses:
28
65
  - MIT
@@ -43,8 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
80
  version: '0'
44
81
  requirements: []
45
82
  rubyforge_project:
46
- rubygems_version: 2.5.2.3
83
+ rubygems_version: 2.7.3
47
84
  signing_key:
48
85
  specification_version: 4
49
- summary: Summary of Shared.
86
+ summary: Write a short summary, because RubyGems requires one.
50
87
  test_files: []
@@ -1,20 +0,0 @@
1
- Copyright 2018 C80609A
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.
@@ -1,3 +0,0 @@
1
- = Shared
2
-
3
- This project rocks and uses MIT-LICENSE.
@@ -1,4 +0,0 @@
1
- require "shared/engine"
2
-
3
- module Shared
4
- end
@@ -1,5 +0,0 @@
1
- module Shared
2
- class Engine < ::Rails::Engine
3
- isolate_namespace Shared
4
- end
5
- end
@@ -1,3 +0,0 @@
1
- module Shared
2
- VERSION = "0.0.1"
3
- end