smpl_prflr 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18ed8c169f4c2ffd164823d3e225608710e9ab8edc5d0786b308bdcca7b4eeeb
4
- data.tar.gz: fae15566f5558dd29727557f0ad831b11178ae0766c3ebd18a9afd01bb5addd6
3
+ metadata.gz: a849c934abcb8d5c5aff39c0afa470b08ce5bdd55d567e0d30a107448cb72d0d
4
+ data.tar.gz: 89014767287aca0f12a948eb397a886072f14944a1256b46b6da7a0e616bc995
5
5
  SHA512:
6
- metadata.gz: '025598f88748306974a29be60ac8dadd0b3edf11bfb58b384cb308bbd98f38e96d8b9bae88ef59b5fc8da3b8f4e3e964c5b295e96ab75ff9abd189af0defdf85'
7
- data.tar.gz: 35f74d523d0dc957887a59632116a454ec084623eeb421b4276f21762cc2b68904d134b3a719df1faed2e8c31cfbbf7f28a210ffc68c683267271528ccb880b0
6
+ metadata.gz: 1a45fba0d3cd6abe515783e94380e972f496e0c2f22fc3f72c0475c3712c1b7dfc3aa8968c32a5616161bbac9e9bacf532626fa683fa80bbb7a7fda749c77340
7
+ data.tar.gz: a7d9c830ca1adf59737f1646ba60664530a9828b5f8f2c96a7ed9b289b98c5ec30ffc40ebd02cd60ca330b8518374e6b329ee025d848e1d326114df839ac6ffb
data/.rubocop.yml CHANGED
@@ -5,7 +5,6 @@ AllCops:
5
5
  - Rakefile
6
6
  - smpl_prflr.gemspec
7
7
  - bin/*
8
- - config.ru
9
8
 
10
9
  Style/FrozenStringLiteralComment:
11
10
  Enabled: false
data/Gemfile CHANGED
@@ -1,8 +1,3 @@
1
1
  source 'https://rubygems.org/'
2
2
  ruby '2.7.2'
3
- gemspec
4
-
5
- gem 'rack', '~> 2.2'
6
- gem 'require_all', '~> 2.0'
7
- gem 'activesupport', '~> 6.1.1'
8
- gem 'config', '~> 3.1'
3
+ gemspec
data/README.md CHANGED
@@ -6,6 +6,7 @@
6
6
  ruby '2.7.2'
7
7
  gem 'redis' '~> 4.6'
8
8
  gem 'ruby-prof' '~>1.4'
9
+ gem 'rack'
9
10
  ```
10
11
  ## Install:
11
12
  ```sh
@@ -13,6 +14,12 @@ bundle install smpl_prflr
13
14
 
14
15
  requre 'smpl_prflr'
15
16
  ```
17
+ ## As web:
18
+ ```sh
19
+ gem install smpl_prflr
20
+
21
+ smpl_prflr
22
+ ```
16
23
  ## How is it works?:
17
24
  ```sh
18
25
  require 'smpl_prflr'
@@ -20,4 +27,8 @@ requre 'smpl_prflr'
20
27
  SmplPrflr.new.p do
21
28
  'your own code'
22
29
  end
30
+
31
+ after that you should start web server smpl_prflr
32
+ get request: 127.0.0.1:9292/
33
+
23
34
  ```
data/bin/smpl_prflr CHANGED
@@ -1,5 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
- #
3
- Dir.chdir(File.join(File.dirname(__FILE__), ".."))
4
2
 
5
- load ::File.expand_path("../../config.ru", __FILE__)
3
+ require 'rack'
4
+ require 'redis'
5
+
6
+ # @author KILYA
7
+ # View profile by redis
8
+ # port: 9292
9
+ # url: 127.0.0.1
10
+ # method GET
11
+ def my_method env
12
+ redis = Redis.new host: "127.0.0.1", port: 6379, db: 15
13
+ result = redis.get(:profile) || "Nothing to profile"
14
+ [200, {}, [result]]
15
+ rescue StandardError
16
+ [500, {}, ["Redis not available"]]
17
+ end
18
+
19
+ Rack::Handler::WEBrick.run method(:my_method), :Port => 9292
20
+
data/lib/smpl_prflr.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The MIT License (MIT)
2
4
  #
3
5
  # Copyright (c) 2019-2022 Kondratev Ilya
@@ -26,14 +28,13 @@ require 'logger'
26
28
 
27
29
  class SmplPrflr
28
30
  class ProfilerError < StandardError; end
29
- DEFAULT_HOST = "127.0.0.1".freeze
30
31
 
31
32
  # @author KILYA
32
33
  # @param [String] host
33
34
  # @param [Integer] port
34
35
  # @param [Integer] db
35
36
  # @example self.new(host: "http:/your.path", port: 555, db:1)
36
- def initialize(host: DEFAULT_HOST, port: 6379, db: 15)
37
+ def initialize(host: "127.0.0.1", port: 6379, db: 15)
37
38
  @logger = Logger.new($stdout)
38
39
  @redis = Redis.new(
39
40
  host: host,
@@ -53,6 +54,7 @@ class SmplPrflr
53
54
 
54
55
  # @author KILYA
55
56
  # Profile block of your code
57
+ # @return [nil]
56
58
  def p
57
59
  profiled = ""
58
60
  result = RubyProf.profile do
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.2'
10
+ s.version = '0.0.3'
11
11
  s.executables << 'smpl_prflr'
12
12
  s.license = 'MIT'
13
13
  s.summary = 'Profiler'
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
20
20
  s.add_dependency 'rubocop-rake'
21
21
  s.add_dependency 'ruby-prof', '~> 1.4', '>= 1.4.3'
22
22
  s.add_dependency 'redis', '~> 4.6'
23
+ s.add_dependency 'rack', '~> 2.2'
23
24
  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.2
4
+ version: 0.0.3
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-03 00:00:00.000000000 Z
11
+ date: 2022-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -72,6 +72,20 @@ dependencies:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '4.6'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rack
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.2'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '2.2'
75
89
  description: SmplPrflr for profiler own code.
76
90
  email: ilyafulleveline@gmail.com
77
91
  executables:
@@ -86,15 +100,7 @@ files:
86
100
  - LICENSE.txt
87
101
  - README.md
88
102
  - Rakefile
89
- - app/controllers/base_controller.rb
90
- - app/controllers/services_controller.rb
91
- - app/services/profile_service.rb
92
103
  - bin/smpl_prflr
93
- - config.ru
94
- - config/app/app.rb
95
- - config/app/router.rb
96
- - config/application.rb
97
- - config/initializers/001_settings.rb
98
104
  - lib/smpl_prflr.rb
99
105
  - smpl_prflr.gemspec
100
106
  - test/test_ping.rb
@@ -1,38 +0,0 @@
1
- # The MIT License (MIT)
2
- #
3
- # Copyright (c) 2019-2022 Kondratev Ilya
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included
13
- # in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
22
-
23
- class BaseController
24
- def initialize(request)
25
- @request = request
26
- @response = Services::ProfileService.new
27
- end
28
-
29
- def not_found
30
- build_response("not_found", status: 404)
31
- end
32
-
33
- private
34
-
35
- def build_response(body, status: 200)
36
- [status, { "Content-Type" => "text/json" }, [body]]
37
- end
38
- end
@@ -1,33 +0,0 @@
1
- # The MIT License (MIT)
2
- #
3
- # Copyright (c) 2019-2022 Kondratev Ilya
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included
13
- # in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
22
-
23
- class ServicesController < BaseController
24
- def ping
25
- result = "PONG"
26
- build_response(result)
27
- end
28
-
29
- def profile
30
- result = @response.load_profile
31
- build_response(result)
32
- end
33
- end
@@ -1,37 +0,0 @@
1
- # The MIT License (MIT)
2
- #
3
- # Copyright (c) 2019-2022 Kondratev Ilya
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included
13
- # in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
22
-
23
- module Services
24
- class ProfileService
25
- def initialize
26
- @redis = Redis.new(
27
- host: "127.0.0.1",
28
- port: 6379,
29
- db: 15
30
- )
31
- end
32
-
33
- def load_profile
34
- @redis.get(:profile)
35
- end
36
- end
37
- end
data/config/app/app.rb DELETED
@@ -1,32 +0,0 @@
1
- # The MIT License (MIT)
2
- #
3
- # Copyright (c) 2019-2022 Kondratev Ilya
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included
13
- # in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
22
-
23
- class App
24
- def call(env)
25
- request = Rack::Request.new(env)
26
- serve_request(request)
27
- end
28
-
29
- def serve_request(request)
30
- Router.new(request).route!
31
- end
32
- end
data/config/app/router.rb DELETED
@@ -1,50 +0,0 @@
1
- # The MIT License (MIT)
2
- #
3
- # Copyright (c) 2019-2022 Kondratev Ilya
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included
13
- # in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
22
-
23
- class Router
24
- def initialize(request)
25
- @request = request
26
- end
27
-
28
- def route!
29
- return controller.not_found unless @request.get?
30
-
31
- case @request.path
32
- when "/ping"
33
- controller.ping
34
- when "/profile"
35
- controller.profile
36
- else
37
- controller.not_found
38
- end
39
- end
40
-
41
- private
42
-
43
- def controller
44
- @controller ||= ServicesController.new(@request)
45
- end
46
-
47
- def params
48
- JSON.parse(@request.body.read)
49
- end
50
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # require gems
4
- require 'bundler'
5
-
6
- Bundler.require(:default, ENV["RACK_ENV"] || "development")
7
-
8
- # require additional gem files
9
- require "active_support/all"
10
-
11
- # initialize application, logger, gems, etc.
12
- require_all "config/initializers"
13
-
14
- # require application
15
- require_all "app"
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "config"
4
-
5
- Config.setup do |config|
6
- config.const_name = "Settings"
7
- config.use_env = false
8
- end
9
-
10
- env = ::ActiveSupport::StringInquirer.new(ENV["RACK_ENV"] || "development")
11
- path = Dir.pwd << ("/config")
12
- Config.load_and_set_settings(Config.setting_files(path, env))
13
-
14
- Settings.env = env
data/config.ru DELETED
@@ -1,4 +0,0 @@
1
- require_relative "config/application"
2
- require_all "./config/app"
3
-
4
- run Rack::URLMap.new('/' => Rack::Builder.new { run App.new })