smpl_prflr 0.0.3 → 0.0.6

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: a849c934abcb8d5c5aff39c0afa470b08ce5bdd55d567e0d30a107448cb72d0d
4
- data.tar.gz: 89014767287aca0f12a948eb397a886072f14944a1256b46b6da7a0e616bc995
3
+ metadata.gz: 667cbd9f7ea72347173b01eeb2befb0c8ef6f5e6f33087807406c88b1af6cfb3
4
+ data.tar.gz: f44f7825d46fd9311ce277e276094c151021b034b05ef767d353c422a37726de
5
5
  SHA512:
6
- metadata.gz: 1a45fba0d3cd6abe515783e94380e972f496e0c2f22fc3f72c0475c3712c1b7dfc3aa8968c32a5616161bbac9e9bacf532626fa683fa80bbb7a7fda749c77340
7
- data.tar.gz: a7d9c830ca1adf59737f1646ba60664530a9828b5f8f2c96a7ed9b289b98c5ec30ffc40ebd02cd60ca330b8518374e6b329ee025d848e1d326114df839ac6ffb
6
+ metadata.gz: 5922c1415b82aebab63fc3ca3587164714a9c519cf04b6436cc3dd654ee567b4ea4286ef35e20f096d98b109910a78454326d6b6dd04767d1a1e1ede76d06faa
7
+ data.tar.gz: 2cce6ba1e2796b1beca8377837675398a7d849367fb136b209f7437186ef539fd837aee038637060fc30f9f37a3a333b5b659e70c133558db6b743bc6ff874e1
data/README.md CHANGED
@@ -4,31 +4,35 @@
4
4
  ## Dependencies:
5
5
  ```sh
6
6
  ruby '2.7.2'
7
- gem 'redis' '~> 4.6'
8
- gem 'ruby-prof' '~>1.4'
9
- gem 'rack'
7
+ ...
8
+ gem 'redis' '4.6'
9
+ gem 'ruby-prof' '1.4'
10
+ gem 'rubocop' '1.26'
11
+ gem 'rack' '2.2'
10
12
  ```
11
13
  ## Install:
12
14
  ```sh
13
15
  bundle install smpl_prflr
14
16
 
15
17
  requre 'smpl_prflr'
16
- ```
17
- ## As web:
18
- ```sh
19
- gem install smpl_prflr
20
18
 
21
- smpl_prflr
22
19
  ```
23
20
  ## How is it works?:
24
21
  ```sh
25
22
  require 'smpl_prflr'
23
+
24
+ include SmplPrflr
25
+
26
+ orinitialize_profiler!
26
27
 
27
- SmplPrflr.new.p do
28
- 'your own code'
29
- end
30
-
31
- after that you should start web server smpl_prflr
28
+ p { block_of_your_own_code }
29
+ ```
30
+
31
+ ## As web:
32
+ ```sh
33
+ user@mac$ gem install smpl_prflr
34
+ ...
35
+ user@mac$ smpl_prflr
36
+ ...
32
37
  get request: 127.0.0.1:9292/
33
-
34
38
  ```
@@ -0,0 +1,8 @@
1
+ module Env
2
+ module Constants
3
+ MODES = {
4
+ production: "./config/production.yml",
5
+ development: "./config/development.yml"
6
+ }.freeze
7
+ end
8
+ end
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,59 @@
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
data/lib/smpl_prflr.rb CHANGED
@@ -22,33 +22,24 @@
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 'ruby-prof'
26
- require 'redis'
27
25
  require 'logger'
26
+ require 'profiler/profile'
27
+ require 'env/loading'
28
28
 
29
- class SmplPrflr
30
- class ProfilerError < StandardError; end
31
-
29
+ module SmplPrflr
32
30
  # @author KILYA
33
- # @param [String] host
34
- # @param [Integer] port
35
- # @param [Integer] db
36
- # @example self.new(host: "http:/your.path", port: 555, db:1)
37
- def initialize(host: "127.0.0.1", port: 6379, db: 15)
31
+ # Init logger
32
+ # Init Profiler
33
+ def initialize_profiler!(mod: :development)
34
+ env = Env::Loading.new(app_mode: mod)
38
35
  @logger = Logger.new($stdout)
39
- @redis = Redis.new(
40
- host: host,
41
- port: port,
42
- db: db
43
- )
36
+ @profiler = Profiler::Profile.new(env)
44
37
  end
45
38
 
46
39
  # @author KILYA
47
- # @param nil
48
- #
49
40
  # @example PONG
50
41
  # @return [String] PONG
51
- def self.ping
42
+ def ping
52
43
  "PONG"
53
44
  end
54
45
 
@@ -56,17 +47,10 @@ class SmplPrflr
56
47
  # Profile block of your code
57
48
  # @return [nil]
58
49
  def p
59
- profiled = ""
60
- result = RubyProf.profile do
50
+ @profiler.start do
61
51
  yield
62
52
  end
63
-
64
- printer = RubyProf::FlatPrinter.new(result)
65
- printer.print(profiled, min_percent: 0)
66
- @redis.set(:profile, profiled)
67
-
68
- nil
69
- rescue StandardError => e
53
+ rescue Profiler::ProfilerError => e
70
54
  @logger.error(e.message.to_s)
71
55
  end
72
56
  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.3'
10
+ s.version = '0.0.6'
11
11
  s.executables << 'smpl_prflr'
12
12
  s.license = 'MIT'
13
13
  s.summary = 'Profiler'
@@ -21,4 +21,5 @@ 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
25
  end
data/test/test_ping.rb CHANGED
@@ -2,8 +2,9 @@ require 'minitest/autorun'
2
2
  require 'smpl_prflr'
3
3
 
4
4
  class TestPing < Minitest::Test
5
+ include SmplPrflr
6
+
5
7
  def test_reverse_string
6
- ping = SmplPrflr.ping
7
8
  assert_equal("PONG", ping)
8
9
  end
9
10
  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.3
4
+ version: 0.0.6
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-04 00:00:00.000000000 Z
11
+ date: 2022-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -86,6 +86,20 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: '2.2'
89
+ - !ruby/object:Gem::Dependency
90
+ name: figaro
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
89
103
  description: SmplPrflr for profiler own code.
90
104
  email: ilyafulleveline@gmail.com
91
105
  executables:
@@ -101,6 +115,9 @@ files:
101
115
  - README.md
102
116
  - Rakefile
103
117
  - bin/smpl_prflr
118
+ - lib/env/constants.rb
119
+ - lib/env/loading.rb
120
+ - lib/profiler/profile.rb
104
121
  - lib/smpl_prflr.rb
105
122
  - smpl_prflr.gemspec
106
123
  - test/test_ping.rb