smpl_prflr 0.0.6 → 0.0.9

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: 4512a90321b13ef139c866db48da2d2d470db633f1a61338ef429d0d0d12bb0b
4
+ data.tar.gz: 68ba88dc28766ccdd6d5f901e705dc27df67918e1da35fd208e41e14aa364a36
5
5
  SHA512:
6
- metadata.gz: 5922c1415b82aebab63fc3ca3587164714a9c519cf04b6436cc3dd654ee567b4ea4286ef35e20f096d98b109910a78454326d6b6dd04767d1a1e1ede76d06faa
7
- data.tar.gz: 2cce6ba1e2796b1beca8377837675398a7d849367fb136b209f7437186ef539fd837aee038637060fc30f9f37a3a333b5b659e70c133558db6b743bc6ff874e1
6
+ metadata.gz: d3e79a2500b151477282f1098af5df11cf584f66f4de11db81bb0faaf6b48076578e73e89a47c0df52f8cf3103f7b70cd2acb4df58800f92752b0cf4cbee1512
7
+ data.tar.gz: 58ace1f5a79d7d6a6cc83cac4abe7fe6aaac89cd141f91dad5a770bb0d672bc0d80644c76cdf2c1d00741d9c03c3bb48245b4009656c7fa406f6d4e03f4ffcd5
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  .idea/
2
2
  Gemfile.lock
3
- *.gem
3
+ *.gem
4
+ /config/*
data/.rubocop.yml CHANGED
@@ -61,4 +61,7 @@ Style/IdenticalConditionalBranches:
61
61
  Enabled: false
62
62
 
63
63
  Style/ExplicitBlockArgument:
64
+ Enabled: false
65
+
66
+ Style/RedundantFreeze:
64
67
  Enabled: false
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! :production
27
27
 
28
28
  p { block_of_your_own_code }
29
29
  ```
data/bin/smpl_prflr CHANGED
@@ -9,7 +9,11 @@ require 'redis'
9
9
  # url: 127.0.0.1
10
10
  # method GET
11
11
  def my_method env
12
- redis = Redis.new host: "127.0.0.1", port: 6379, db: 15
12
+ redis = Redis.new(
13
+ host: "127.0.0.1" || env[:HOST],
14
+ port: 6379 || env[:PORT],
15
+ db: 15 || env[:DB]
16
+ )
13
17
  result = redis.get(:profile) || "Nothing to profile"
14
18
  [200, {}, [result]]
15
19
  rescue StandardError
@@ -22,38 +22,16 @@
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'
25
+ module SmplPrflr
26
+ module Constants
27
+ MODES = {
28
+ production: "config/production.yml",
29
+ development: "config/development.yml",
30
+ test: "config/test.yml"
31
+ }.freeze
27
32
 
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
33
+ HOST = "127.0.0.1".freeze
34
+ PORT = "6379"
35
+ DB = "15"
58
36
  end
59
37
  end
@@ -0,0 +1,27 @@
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
+ VERSION = "0.0.9".freeze
27
+ end
data/lib/smpl_prflr.rb CHANGED
@@ -23,17 +23,41 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  require 'logger'
26
- require 'profiler/profile'
27
- require 'env/loading'
26
+ require "figaro"
27
+ require 'ruby-prof'
28
+ require 'redis'
29
+ require 'smpl_prflr/constants'
28
30
 
29
31
  module SmplPrflr
32
+ class ProfilerError < StandardError; end
33
+
30
34
  # @author KILYA
31
35
  # Init logger
36
+ #
32
37
  # Init Profiler
33
- def initialize_profiler!(mod: :development)
34
- env = Env::Loading.new(app_mode: mod)
38
+ #
39
+ # Load env
40
+ #
41
+ # Init Redis
42
+ # @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
+
35
53
  @logger = Logger.new($stdout)
36
- @profiler = Profiler::Profile.new(env)
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
61
  end
38
62
 
39
63
  # @author KILYA
@@ -47,10 +71,17 @@ module SmplPrflr
47
71
  # Profile block of your code
48
72
  # @return [nil]
49
73
  def p
50
- @profiler.start do
74
+ result = RubyProf.profile do
51
75
  yield
52
76
  end
53
- rescue Profiler::ProfilerError => e
54
- @logger.error(e.message.to_s)
77
+
78
+ output = String.new
79
+ printer = RubyProf::FlatPrinter.new(result)
80
+ printer.print(output, min_percent: 0)
81
+ @redis.set(:profile, output)
82
+
83
+ nil
84
+ rescue StandardError => e
85
+ @logger.error e.message.to_s
55
86
  end
56
87
  end
data/smpl_prflr.gemspec CHANGED
@@ -1,4 +1,9 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
1
4
  require 'English'
5
+ require 'smpl_prflr/version'
6
+
2
7
  Gem::Specification.new do |s|
3
8
  s.specification_version = 2 if s.respond_to? :specification_version=
4
9
  if s.respond_to? :required_rubygems_version=
@@ -7,7 +12,7 @@ Gem::Specification.new do |s|
7
12
  s.rubygems_version = '2.7'
8
13
  s.required_ruby_version = '>=2.2'
9
14
  s.name = 'smpl_prflr'
10
- s.version = '0.0.6'
15
+ s.version = SmplPrflr::VERSION
11
16
  s.executables << 'smpl_prflr'
12
17
  s.license = 'MIT'
13
18
  s.summary = 'Profiler'
@@ -21,5 +26,5 @@ Gem::Specification.new do |s|
21
26
  s.add_dependency 'ruby-prof', '~> 1.4', '>= 1.4.3'
22
27
  s.add_dependency 'redis', '~> 4.6'
23
28
  s.add_dependency 'rack', '~> 2.2'
24
- s.add_dependency 'figaro'
29
+ s.add_dependency 'figaro', '~> 1.2'
25
30
  end
data/test/test_ping.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'minitest/autorun'
2
2
  require 'smpl_prflr'
3
+ require 'smpl_prflr/version'
3
4
 
4
5
  class TestPing < Minitest::Test
5
6
  include SmplPrflr
@@ -7,4 +8,8 @@ class TestPing < Minitest::Test
7
8
  def test_reverse_string
8
9
  assert_equal("PONG", ping)
9
10
  end
11
+
12
+ def test_version
13
+ assert_equal("0.0.8", SmplPrflr::VERSION)
14
+ end
10
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.6
4
+ version: 0.0.9
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-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -90,16 +90,16 @@ dependencies:
90
90
  name: figaro
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - ">="
93
+ - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '0'
95
+ version: '1.2'
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: '1.2'
103
103
  description: SmplPrflr for profiler own code.
104
104
  email: ilyafulleveline@gmail.com
105
105
  executables:
@@ -115,10 +115,9 @@ files:
115
115
  - README.md
116
116
  - Rakefile
117
117
  - bin/smpl_prflr
118
- - lib/env/constants.rb
119
- - lib/env/loading.rb
120
- - lib/profiler/profile.rb
121
118
  - lib/smpl_prflr.rb
119
+ - lib/smpl_prflr/constants.rb
120
+ - lib/smpl_prflr/version.rb
122
121
  - smpl_prflr.gemspec
123
122
  - test/test_ping.rb
124
123
  homepage: https://github.com/ikondratev/smpl_prflr
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