karma 0.1.1 → 0.1.3

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: 4af951689fc254cd405b232d6fbe9360082f3c0077693ae4cfffaf8f924d5481
4
- data.tar.gz: f9f57749c98ecc5da401f495da4a2ae821a5920497a7d6f459322bece5bc4e45
3
+ metadata.gz: 96ca4d676420829dd458cf282017325e3ee545f66a0318e9b457f66bceda011a
4
+ data.tar.gz: 95c31c4476a2e85fd152d9cecc964136b3ea12c6e1a45f38c63cc97b4f2abc84
5
5
  SHA512:
6
- metadata.gz: 7eee8a4bfe16836ec04faafec7fa27611fee311f77b176d550cc088c664fa3acd7fe0a2c8692c67ddb59f9ae669988559d7bd48453e02292afa169999284aa37
7
- data.tar.gz: 5be03eefbc39350ae4e639fa3455f89c36abb03a20e7a87c2b1f26e921370921d592ed9d8fb7bf65fc4cdf1a2e0e9bb7dcee04c8638662663009a5b37be8bc0b
6
+ metadata.gz: 78cd74834edb96a785780c74f521639b6476f7842294ff198166fdd0333239b94cf3adfc293a7a17883e3ba632157237ec010f9a7ee5e492cd963dc3312fb865
7
+ data.tar.gz: deefe72e812e5538b2e576a3e13e7f70e7b1bcdfca99c74964b86f077da12ff5e314ba32d30ca60a87e7945f43f1174146bbe396671977b17bef371a1bd7e06a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karma (0.1.1)
4
+ karma (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/karma/config.rb CHANGED
@@ -1,18 +1,22 @@
1
1
  module Karma
2
- Config = Struct.new(:host, :port) do
2
+ class << self
3
+ attr_accessor :configuration
4
+ end
5
+
6
+ class Configuration
7
+ attr_accessor :port, :host
8
+
3
9
  def initialize
4
- self.port = 8080
5
- self.host = 'localhost'
10
+ @host = 'localhost'
11
+ @port = 8080
6
12
  end
7
13
  end
8
14
 
9
15
  def self.configure
10
- @config = Config.new
11
- yield(@config) if block_given?
12
- @config
16
+ yield(configuration)
13
17
  end
14
18
 
15
- def self.config
16
- @config || configure
19
+ def self.configuration
20
+ @@configuration ||= Configuration.new
17
21
  end
18
22
  end
@@ -1,14 +1,13 @@
1
1
  module Karma
2
2
  class Connection
3
3
  def initialize
4
- @port = Karma.config.port
5
- @host = Karma.config.host
6
4
  @maxlen = 4096
7
-
8
- establish_connection!
9
5
  end
10
6
 
11
7
  def send_and_read(request)
8
+ unless defined?(@socket)
9
+ establish_connection!
10
+ end
12
11
  send(request)
13
12
  read
14
13
  end
@@ -48,8 +47,8 @@ module Karma
48
47
 
49
48
  def establish_connection!
50
49
  @socket = TCPSocket.new(
51
- @host,
52
- @port,
50
+ Karma.configuration.host,
51
+ Karma.configuration.port,
53
52
  connect_timeout: 0.5
54
53
  )
55
54
  end
data/lib/karma/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Karma
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/karma.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'json'
2
2
  require 'socket'
3
- require 'ostruct'
4
3
 
5
4
  require 'karma/version'
6
5
  require 'karma/config'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Fedorov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-04 00:00:00.000000000 Z
11
+ date: 2023-07-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby client for the Karma key-counter database
14
14
  email: