smpl_prflr 0.0.9 → 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
2
  SHA256:
3
- metadata.gz: 4512a90321b13ef139c866db48da2d2d470db633f1a61338ef429d0d0d12bb0b
4
- data.tar.gz: 68ba88dc28766ccdd6d5f901e705dc27df67918e1da35fd208e41e14aa364a36
3
+ metadata.gz: 3f10e567765ca0ed3ef844f4ff52441884183d3e4a6cf4bc6dde5464be58c256
4
+ data.tar.gz: b37c061d5f817171a1a08e925bf87ed07234986ae5cb992ff51559621981a3ed
5
5
  SHA512:
6
- metadata.gz: d3e79a2500b151477282f1098af5df11cf584f66f4de11db81bb0faaf6b48076578e73e89a47c0df52f8cf3103f7b70cd2acb4df58800f92752b0cf4cbee1512
7
- data.tar.gz: 58ace1f5a79d7d6a6cc83cac4abe7fe6aaac89cd141f91dad5a770bb0d672bc0d80644c76cdf2c1d00741d9c03c3bb48245b4009656c7fa406f6d4e03f4ffcd5
6
+ metadata.gz: 727f102810b6f6152909571b1c529c9041eac6ea739b051b4089355c25330c8c3688d4537dcd8c22c0eb6e96452f20cbcf871a684a859e40a2dd50d509ea332b
7
+ data.tar.gz: e13236737185a7cf704b445b4062e85647768fd214e316030cefe9ec4c3aa1d1aed2f0afafee2fb7cbebfd88bf9406e98a9364756e878f4d745da3959f4dbc28
@@ -24,12 +24,6 @@
24
24
 
25
25
  module SmplPrflr
26
26
  module Constants
27
- MODES = {
28
- production: "config/production.yml",
29
- development: "config/development.yml",
30
- test: "config/test.yml"
31
- }.freeze
32
-
33
27
  HOST = "127.0.0.1".freeze
34
28
  PORT = "6379"
35
29
  DB = "15"
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The MIT License (MIT)
4
+ #
5
+ # Copyright (c) 2019-2022 Kondratev Ilya
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included
15
+ # in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ module SmplPrflr
26
+ # main error
27
+ class Error < StandardError; end
28
+
29
+ # raise when profiler error
30
+ class ProfilerError < Error; end
31
+
32
+ # raise when load resources error
33
+ class LoadResourcesError < Error; end
34
+
35
+ # raise in main class
36
+ class ClassProfilerError < Error; end
37
+ end
@@ -0,0 +1,17 @@
1
+ require 'redis'
2
+
3
+ module SmplPrflr
4
+ module Initializers
5
+ module Base
6
+ def initialize_base!
7
+ host = ENV['HOST'] || SmplPrflr::Constants::HOST
8
+ port = ENV['PORT'] || SmplPrflr::Constants::PORT
9
+ db = ENV['DB'] || SmplPrflr::Constants::DB
10
+
11
+ @redis = Redis.new(host: host, port: port, db: db)
12
+ rescue StandardError => e
13
+ raise SmplPrflr::LoadResourcesError.new, e.message
14
+ end
15
+ end
16
+ end
17
+ end
@@ -23,5 +23,5 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  module SmplPrflr
26
- VERSION = "0.0.9".freeze
26
+ VERSION = "0.1.0".freeze
27
27
  end
data/lib/smpl_prflr.rb CHANGED
@@ -22,54 +22,33 @@
22
22
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
23
  # SOFTWARE.
24
24
 
25
- require 'logger'
26
- require "figaro"
27
25
  require 'ruby-prof'
28
- require 'redis'
26
+ require 'smpl_prflr/initializers/base'
29
27
  require 'smpl_prflr/constants'
28
+ require 'smpl_prflr/errors'
30
29
 
31
30
  module SmplPrflr
32
- class ProfilerError < StandardError; end
31
+ include SmplPrflr::Initializers::Base
33
32
 
34
- # @author KILYA
35
- # Init logger
36
- #
37
33
  # Init Profiler
38
34
  #
39
- # Load env
40
- #
41
35
  # Init Redis
42
36
  # @raise [ProfilerError]
43
- def initialize_profiler!(mod = :development)
44
- path = File.expand_path(
45
- Constants::MODES[mod.to_sym]
46
- )
47
- Figaro.application = Figaro::Application.new(
48
- environment: mod.to_sym,
49
- path: path
50
- )
51
- Figaro.load
52
-
53
- @logger = Logger.new($stdout)
54
- @redis = Redis.new(
55
- host: Figaro.env.host || SmplPrflr::Constants::HOST,
56
- port: Figaro.env.port || SmplPrflr::Constants::PORT,
57
- db: Figaro.env.db || SmplPrflr::Constants::DB
58
- )
59
- rescue StandardError => e
60
- raise ProfilerError.new e.message
37
+ def initialize_profiler!
38
+ initialize_base!
39
+ rescue SmplPrflr::Error => e
40
+ raise SmplPrflr::ClassProfilerErrore, e.message
61
41
  end
62
42
 
63
- # @author KILYA
64
43
  # @example PONG
65
44
  # @return [String] PONG
66
45
  def ping
67
46
  "PONG"
68
47
  end
69
48
 
70
- # @author KILYA
71
49
  # Profile block of your code
72
50
  # @return [nil]
51
+ # @raise ProfilerError
73
52
  def p
74
53
  result = RubyProf.profile do
75
54
  yield
@@ -81,7 +60,7 @@ module SmplPrflr
81
60
  @redis.set(:profile, output)
82
61
 
83
62
  nil
84
- rescue StandardError => e
85
- @logger.error e.message.to_s
63
+ rescue SmplPrflr::Error => e
64
+ raise SmplPrflr::ClassProfilerErrore.new, e.message
86
65
  end
87
66
  end
data/test/test_ping.rb CHANGED
@@ -10,6 +10,6 @@ class TestPing < Minitest::Test
10
10
  end
11
11
 
12
12
  def test_version
13
- assert_equal("0.0.8", SmplPrflr::VERSION)
13
+ assert_equal("0.1.0", SmplPrflr::VERSION)
14
14
  end
15
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smpl_prflr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Kondratev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-05 00:00:00.000000000 Z
11
+ date: 2022-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -117,6 +117,8 @@ files:
117
117
  - bin/smpl_prflr
118
118
  - lib/smpl_prflr.rb
119
119
  - lib/smpl_prflr/constants.rb
120
+ - lib/smpl_prflr/errors.rb
121
+ - lib/smpl_prflr/initializers/base.rb
120
122
  - lib/smpl_prflr/version.rb
121
123
  - smpl_prflr.gemspec
122
124
  - test/test_ping.rb