smpl_prflr 0.0.6 → 0.0.7

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: 667cbd9f7ea72347173b01eeb2befb0c8ef6f5e6f33087807406c88b1af6cfb3
4
- data.tar.gz: f44f7825d46fd9311ce277e276094c151021b034b05ef767d353c422a37726de
3
+ metadata.gz: 631e5d59f68f03080bd721b15ba9bf66df3f17cc14a4856c4a3c59a5aa912a87
4
+ data.tar.gz: b334d58ebefc14665778ead61a91ca43794555a9510cfe0a6f7dba60c0582282
5
5
  SHA512:
6
- metadata.gz: 5922c1415b82aebab63fc3ca3587164714a9c519cf04b6436cc3dd654ee567b4ea4286ef35e20f096d98b109910a78454326d6b6dd04767d1a1e1ede76d06faa
7
- data.tar.gz: 2cce6ba1e2796b1beca8377837675398a7d849367fb136b209f7437186ef539fd837aee038637060fc30f9f37a3a333b5b659e70c133558db6b743bc6ff874e1
6
+ metadata.gz: 39ea8978dc78d2df0627d632c0e68e230893910df70cc29a339d4442f759087d6fd7ef674f683817f9cb44cd7bda6f5fa67d4f73135ec9c493e70a5739ee2721
7
+ data.tar.gz: fc7e47f6beb95bf206b30a1b061e3a7abdcf3c7daa941755fb5002a594eb0552da74bdfc75aa614ddd32fb121ed2381875ea3fb9d510ab00df40c4987b83800c
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  .idea/
2
2
  Gemfile.lock
3
- *.gem
3
+ *.gem
4
+ /config/*
data/README.md CHANGED
@@ -23,7 +23,7 @@ requre 'smpl_prflr'
23
23
 
24
24
  include SmplPrflr
25
25
 
26
- orinitialize_profiler!
26
+ initialize_profiler!(mod: "production")
27
27
 
28
28
  p { block_of_your_own_code }
29
29
  ```
@@ -0,0 +1,7 @@
1
+ module Profiler
2
+ module Constants
3
+ DEFAULT_HOST = "127.0.0.1".freeze
4
+ DEFAULT_PORT = 6379
5
+ DEFAULT_DB = 15
6
+ end
7
+ end
data/lib/smpl_prflr.rb CHANGED
@@ -23,17 +23,35 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  require 'logger'
26
- require 'profiler/profile'
27
- require 'env/loading'
26
+ require "config"
27
+ require 'ruby-prof'
28
+ require 'redis'
29
+ require 'profiler/constants'
30
+ require 'active_support/all'
28
31
 
29
32
  module SmplPrflr
30
33
  # @author KILYA
31
34
  # Init logger
32
35
  # Init Profiler
33
- def initialize_profiler!(mod: :development)
34
- env = Env::Loading.new(app_mode: mod)
36
+ # Load env
37
+ # Init Redis
38
+ def initialize_profiler!(mod: "development")
39
+ Config.setup do |config|
40
+ config.const_name = "Settings"
41
+ config.use_env = false
42
+ end
43
+
44
+ env = ::ActiveSupport::StringInquirer.new(mod)
45
+ path = Dir.pwd << ("/config")
46
+ Config.load_and_set_settings(Config.setting_files(path, env))
47
+ Settings.env = env
48
+
35
49
  @logger = Logger.new($stdout)
36
- @profiler = Profiler::Profile.new(env)
50
+ @redis = Redis.new(
51
+ host: Settings.HOST || Profiler::Constants::DEFAULT_HOST,
52
+ port: Settings.PORT || Profiler::Constants::DEFAULT_PORT,
53
+ db: Settings.DB || Profiler::Constants::DEFAULT_DB
54
+ )
37
55
  end
38
56
 
39
57
  # @author KILYA
@@ -47,10 +65,17 @@ module SmplPrflr
47
65
  # Profile block of your code
48
66
  # @return [nil]
49
67
  def p
50
- @profiler.start do
68
+ output = String.new
69
+ result = RubyProf.profile do
51
70
  yield
52
71
  end
53
- rescue Profiler::ProfilerError => e
54
- @logger.error(e.message.to_s)
72
+
73
+ printer = RubyProf::FlatPrinter.new(result)
74
+ printer.print(output, min_percent: 0)
75
+ @redis.set(:profile, output)
76
+
77
+ nil
78
+ rescue StandardError => e
79
+ @logger.error e.message.to_s
55
80
  end
56
81
  end
data/smpl_prflr.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.rubygems_version = '2.7'
8
8
  s.required_ruby_version = '>=2.2'
9
9
  s.name = 'smpl_prflr'
10
- s.version = '0.0.6'
10
+ s.version = '0.0.7'
11
11
  s.executables << 'smpl_prflr'
12
12
  s.license = 'MIT'
13
13
  s.summary = 'Profiler'
@@ -21,5 +21,6 @@ Gem::Specification.new do |s|
21
21
  s.add_dependency 'ruby-prof', '~> 1.4', '>= 1.4.3'
22
22
  s.add_dependency 'redis', '~> 4.6'
23
23
  s.add_dependency 'rack', '~> 2.2'
24
- s.add_dependency 'figaro'
24
+ s.add_dependency 'config', '~> 4.0'
25
+ s.add_dependency 'activesupport', '~> 6.1.1'
25
26
  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.6
4
+ version: 0.0.7
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-04-06 00:00:00.000000000 Z
11
+ date: 2022-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -87,19 +87,33 @@ dependencies:
87
87
  - !ruby/object:Gem::Version
88
88
  version: '2.2'
89
89
  - !ruby/object:Gem::Dependency
90
- name: figaro
90
+ name: config
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - ">="
93
+ - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '0'
95
+ version: '4.0'
96
96
  type: :runtime
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - ">="
100
+ - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '0'
102
+ version: '4.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: activesupport
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 6.1.1
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 6.1.1
103
117
  description: SmplPrflr for profiler own code.
104
118
  email: ilyafulleveline@gmail.com
105
119
  executables:
@@ -115,9 +129,7 @@ files:
115
129
  - README.md
116
130
  - Rakefile
117
131
  - bin/smpl_prflr
118
- - lib/env/constants.rb
119
- - lib/env/loading.rb
120
- - lib/profiler/profile.rb
132
+ - lib/profiler/constants.rb
121
133
  - lib/smpl_prflr.rb
122
134
  - smpl_prflr.gemspec
123
135
  - test/test_ping.rb
data/lib/env/constants.rb DELETED
@@ -1,8 +0,0 @@
1
- module Env
2
- module Constants
3
- MODES = {
4
- production: "./config/production.yml",
5
- development: "./config/development.yml"
6
- }.freeze
7
- end
8
- end
data/lib/env/loading.rb DELETED
@@ -1,16 +0,0 @@
1
- require 'figaro'
2
- require 'env/constants'
3
-
4
- module Env
5
- class Loading
6
- def initialize(app_mode: :development)
7
- path = Env::Constants::MODES[app_mode]
8
- Figaro.application = Figaro::Application.new(environment: app_mode, path: path)
9
- Figaro.load
10
- end
11
-
12
- def store(value:)
13
- Figaro.env.send(value)
14
- end
15
- end
16
- end
@@ -1,59 +0,0 @@
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
- require 'ruby-prof'
26
- require 'redis'
27
-
28
- module Profiler
29
- class Profile
30
- class ProfilerError < StandardError; end
31
-
32
- # @author KILYA
33
- # Initialise redis
34
- def initialize(env)
35
- @redis = Redis.new(
36
- host: env.store(value: "host") || "127.0.0.1",
37
- port: env.store(value: "port") || 6379,
38
- db: env.store(value: "db") || 15
39
- )
40
- end
41
-
42
- # @author KILYA
43
- # main point
44
- def start
45
- output = String.new
46
- result = RubyProf.profile do
47
- yield
48
- end
49
-
50
- printer = RubyProf::FlatPrinter.new(result)
51
- printer.print(output, min_percent: 0)
52
- @redis.set(:profile, output)
53
-
54
- nil
55
- rescue StandardError => e
56
- raise ProfilerError.new e.message.to_s
57
- end
58
- end
59
- end