active_orm 4.0.3 → 5.0.0

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
  SHA1:
3
- metadata.gz: 87cf8156abefa39eaab7be881aa46cbedfac81fa
4
- data.tar.gz: 68c8f4303731297a32a3e6caa4f12f6147524262
3
+ metadata.gz: e54ca0d570dbde6643e8920cc5dbbbfe7e07615e
4
+ data.tar.gz: 07f7455f9ee50e95bf214b74088acc770b74cf4d
5
5
  SHA512:
6
- metadata.gz: e36bc75f882c676b415e82aefa1c73af1674a78e66659b1cd53b5d76c61dcb651f03a3f1da3522bf8ac48d3caafd9a8a50028740e64aafd7c72b6ffd2153cdf4
7
- data.tar.gz: c88479768d5f79f0c82f2b40cb6e8cb09045f263bc5d9753b0779f514711aa930d1a3f7c3c123a57cf019087b86de5b628718a4444ad058db854eddc7f70b533
6
+ metadata.gz: 18926c723a16a6317b20db4eaa970ebe4100e6e7520107b3a208ed35916ad9a2b641e63b25a51314360f40104c77e1ee8aa3bb597eb711cc4d011c729f9141f6
7
+ data.tar.gz: be0525d9c1494541c8762c0e6e168b129ac8b1f0fcfd90401db93e828f472c462bfe254b7fad2ec495732c0bc6ddec7d019ac82120f207a92ea21732363762b3
data/.reek CHANGED
@@ -7,6 +7,8 @@ ClassVariable:
7
7
  enabled: false
8
8
  ControlParameter:
9
9
  enabled: false
10
+ DataClump:
11
+ enabled: false
10
12
  DuplicateMethodCall:
11
13
  exclude:
12
14
  - 'Base#metamorph'
@@ -16,19 +18,11 @@ IrresponsibleModule:
16
18
  enabled: false
17
19
  LongParameterList:
18
20
  enabled: false
19
- ManualDispatch:
20
- enabled: false
21
- NestedIterators:
22
- max_allowed_nesting: 2
23
21
  NilCheck:
24
22
  enabled: false
25
- PrimaDonnaMethod:
26
- enabled: false
27
23
  RepeatedConditional:
28
24
  enabled: false
25
+ TooManyMethods:
26
+ enabled: false
29
27
  TooManyStatements:
30
28
  max_statements: 10
31
- exclude:
32
- - 'Base#metamorph'
33
- UtilityFunction:
34
- enabled: false
@@ -4,41 +4,21 @@ AllCops:
4
4
  TargetRubyVersion: 2.4
5
5
  Exclude:
6
6
  - 'spec/**/**/*'
7
- Layout/ClosingParenthesisIndentation:
8
- Enabled: false
9
7
  Layout/EmptyLinesAroundBlockBody:
10
8
  Enabled: false
11
9
  Layout/EmptyLinesAroundClassBody:
12
10
  Enabled: false
13
11
  Layout/EmptyLinesAroundModuleBody:
14
12
  Enabled: false
15
- Layout/FirstParameterIndentation:
16
- Enabled: false
17
- Layout/MultilineMethodCallIndentation:
18
- EnforcedStyle: aligned
19
13
  LineLength:
20
14
  Max: 100
21
15
  Lint/ScriptPermission:
22
16
  Enabled: false
23
17
  Metrics/ClassLength:
24
18
  Enabled: false
25
- Metrics/ModuleLength:
26
- Enabled: false
27
- Style/Alias:
28
- EnforcedStyle: prefer_alias_method
29
- Style/BracesAroundHashParameters:
30
- Enabled: false
31
19
  Style/ClassAndModuleChildren:
32
20
  EnforcedStyle: compact
33
21
  Style/ClassVars:
34
22
  Enabled: false
35
23
  Style/Documentation:
36
24
  Enabled: false
37
- Style/HashSyntax:
38
- Enabled: false
39
- Style/FrozenStringLiteralComment:
40
- Enabled: false
41
- Style/NumericLiterals:
42
- Enabled: false
43
- Style/RescueModifier:
44
- Enabled: false
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in active_orm.gemspec
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/active_orm.svg)](http://badge.fury.io/rb/active_orm)
4
4
  [![Build Status](https://travis-ci.org/drexed/active_orm.svg?branch=master)](https://travis-ci.org/drexed/active_orm)
5
- [![Coverage Status](https://coveralls.io/repos/github/drexed/active_orm/badge.svg?branch=master)](https://coveralls.io/github/drexed/active_orm?branch=master)
6
5
 
7
6
  ActiveOrm is a library for object ruby mapping of different databases.
8
7
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
 
3
5
  task default: :spec
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # coding: utf-8
2
4
 
3
5
  lib = File.expand_path('../lib', __FILE__)
@@ -21,7 +23,6 @@ Gem::Specification.new do |spec|
21
23
  spec.require_paths = %w[lib]
22
24
 
23
25
  spec.add_runtime_dependency 'rails'
24
- spec.add_runtime_dependency 'dry-configurable'
25
26
 
26
27
  spec.add_development_dependency 'bundler'
27
28
  spec.add_development_dependency 'coveralls'
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'active_orm'
data/bin/rake CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- #
2
+ # frozen_string_literal: true
3
+
3
4
  # This file was generated by Bundler.
4
5
  #
5
6
  # The application 'rake' is installed as part of a gem, and
6
7
  # this file is here to facilitate running it.
7
- #
8
8
 
9
9
  require 'pathname'
10
10
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
@@ -1,12 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/railtie'
2
4
 
3
- %w[version railtie base redis].each do |file_name|
5
+ %w[version railtie].each do |file_name|
4
6
  require "active_orm/#{file_name}"
5
7
  end
6
8
 
7
- %w[connection geo hash hyper_log_log key list pub_sub script set sorted_set string transaction]
8
- .each do |file_name|
9
- require "active_orm/redis/#{file_name}"
10
- end
9
+ %w[
10
+ configuration base connection geo hash hyper_log_log key list pub_sub script set sorted_set
11
+ string transaction
12
+ ].each do |file_name|
13
+ require "active_orm/redis/#{file_name}"
14
+ end
11
15
 
12
16
  require 'generators/active_orm/install_generator'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ActiveOrm::Railtie < Rails::Railtie
2
4
 
3
5
  rake_tasks do
@@ -1,76 +1,87 @@
1
- module Base
1
+ # frozen_string_literal: true
2
2
 
3
- @@evaluate = false
3
+ class ActiveOrm::Redis::Base
4
+ class << self
4
5
 
5
- def evaluate(value = true)
6
- @@evaluate = value
7
- self
8
- end
6
+ @@evaluate = false
9
7
 
10
- private
8
+ def client(new_client = nil)
9
+ new_client || ActiveOrm::Redis.configuration.client
10
+ end
11
11
 
12
- def evaluate?
13
- value = @@evaluate
14
- @@evaluate = false
15
- value
16
- end
12
+ def evaluate(value = true)
13
+ @@evaluate = value
14
+ self
15
+ end
17
16
 
18
- def append?(order)
19
- order.to_s == 'append'
20
- end
17
+ private
21
18
 
22
- # rubocop:disable Lint/RescueException, Security/Eval
23
- def metaform(value)
24
- value.nil? ? value : eval(value)
25
- rescue Exception
26
- value
27
- end
28
- # rubocop:enable Lint/RescueException, Security/Eval
29
-
30
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
31
- def metamorph(datum)
32
- case datum.class.name
33
- when 'Array'
34
- data = datum.first
35
-
36
- if data.is_a?(Array)
37
- datum.map { |arr| arr.map { |val| metaform(val) } }
38
- elsif data.is_a?(Hash)
39
- datum.map { |hsh| hsh.each { |key, val| hash.store(key, metaform(val)) } }
40
- else
41
- datum.map { |val| metaform(val) }
19
+ def evaluate?
20
+ value = @@evaluate
21
+ @@evaluate = false
22
+ value
23
+ end
24
+
25
+ def append?(order)
26
+ order.to_s == 'append'
27
+ end
28
+
29
+ # rubocop:disable Lint/RescueException, Security/Eval
30
+ def metaform(value)
31
+ value.nil? ? value : eval(value)
32
+ rescue Exception
33
+ value
34
+ end
35
+ # rubocop:enable Lint/RescueException, Security/Eval
36
+
37
+ def metaform_array(datum)
38
+ datum.map { |val| metaform(val) }
39
+ end
40
+
41
+ def metaform_hash(datum)
42
+ datum.lazy.each { |key, val| datum[key] = metaform(val) }
43
+ end
44
+
45
+ def metamorph_array(datum)
46
+ case datum.first.class.name
47
+ when 'Array' then datum.map { |arr| metaform_array(arr) }
48
+ when 'Hash' then datum.map { |hsh| metaform_hash(hsh) }
49
+ else metaform_array(datum)
42
50
  end
43
- when 'Hash'
44
- datum.each { |key, val| datum.store(key, metaform(val)) }
45
- else
46
- metaform(datum)
47
51
  end
48
- end
49
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
50
52
 
51
- def metatransform(datum)
52
- return(nil) if datum.empty?
53
- evaluate? ? metamorph(datum) : datum
54
- end
53
+ def metamorph(datum)
54
+ case datum.class.name
55
+ when 'Array' then metamorph_array(datum)
56
+ when 'Hash' then metaform_hash(datum)
57
+ else metaform(datum)
58
+ end
59
+ end
55
60
 
56
- def milliseconds?(format)
57
- format.to_s == 'milliseconds'
58
- end
61
+ def metatransform(datum)
62
+ return if datum.empty?
63
+ evaluate? ? metamorph(datum) : datum
64
+ end
59
65
 
60
- def normalize_key(key)
61
- key.to_s
62
- end
66
+ def milliseconds?(format)
67
+ format.to_s == 'milliseconds'
68
+ end
63
69
 
64
- def prepend?(order)
65
- order.to_s == 'prepend'
66
- end
70
+ def normalize_key(key)
71
+ key.to_s
72
+ end
67
73
 
68
- def seconds?(format)
69
- format.to_s == 'seconds'
70
- end
74
+ def prepend?(order)
75
+ order.to_s == 'prepend'
76
+ end
71
77
 
72
- def stringify_keys(value)
73
- value.map { |key, _| key.to_s }
74
- end
78
+ def seconds?(format)
79
+ format.to_s == 'seconds'
80
+ end
81
+
82
+ def stringify_keys(value)
83
+ value.map { |key, _| key.to_s }
84
+ end
75
85
 
86
+ end
76
87
  end
@@ -1,9 +1,36 @@
1
- class Configuration
1
+ # frozen_string_literal: true
2
2
 
3
- attr_accessor :client
3
+ # rubocop:disable Style/ClassAndModuleChildren
4
4
 
5
- def initialize
6
- @client ||= Redis.new
7
- end
5
+ begin
6
+ require 'fakeredis'
7
+ rescue LoadError
8
+ require 'redis'
9
+ end
10
+
11
+ module ActiveOrm
12
+ module Redis
13
+ class Configuration
14
+
15
+ attr_accessor :client
16
+
17
+ def initialize
18
+ @client = ::Redis.new
19
+ end
8
20
 
21
+ end
22
+
23
+ def self.configuration
24
+ @configuration ||= Configuration.new
25
+ end
26
+
27
+ def self.configuration=(config)
28
+ @configuration = config
29
+ end
30
+
31
+ def self.configure
32
+ yield(configuration)
33
+ end
34
+
35
+ end
9
36
  end
@@ -1,99 +1,103 @@
1
- class ActiveOrm::Redis::Connection < ActiveOrm::Redis
1
+ # frozen_string_literal: true
2
2
 
3
- def self.authenticate(password)
4
- client.auth(password)
5
- end
3
+ class ActiveOrm::Redis::Connection < ActiveOrm::Redis::Base
4
+ class << self
6
5
 
7
- def self.connected?
8
- client.connected?
9
- end
6
+ def authenticate(password)
7
+ client.auth(password)
8
+ end
10
9
 
11
- def self.database(index)
12
- client.select(index)
13
- end
10
+ def connected?
11
+ client.connected?
12
+ end
14
13
 
15
- def self.database_id
16
- client.database_id
17
- end
14
+ def database(index)
15
+ client.select(index)
16
+ end
18
17
 
19
- def self.database_size
20
- client.dbsize
21
- end
18
+ def database_id
19
+ client.database_id
20
+ end
22
21
 
23
- def self.debug(*args)
24
- client.debug(args)
25
- end
22
+ def database_size
23
+ client.dbsize
24
+ end
26
25
 
27
- def self.disconnect
28
- client.disconnect
29
- end
26
+ def debug(*args)
27
+ client.debug(args)
28
+ end
30
29
 
31
- def self.echo(message)
32
- client.echo(message)
33
- end
30
+ def disconnect
31
+ client.disconnect
32
+ end
34
33
 
35
- def self.flush
36
- client.flushdb
37
- end
34
+ def echo(message)
35
+ client.echo(message)
36
+ end
38
37
 
39
- def self.flush_all
40
- client.flushall
41
- end
38
+ def flush
39
+ client.flushdb
40
+ end
42
41
 
43
- def self.info
44
- client.info
45
- end
42
+ def flush_all
43
+ client.flushall
44
+ end
46
45
 
47
- def self.ping
48
- client.ping
49
- end
46
+ def info
47
+ client.info
48
+ end
50
49
 
51
- def self.quit
52
- client.quit
53
- end
50
+ def ping
51
+ client.ping
52
+ end
54
53
 
55
- def self.reconnect
56
- client.reconnect
57
- end
54
+ def quit
55
+ client.quit
56
+ end
58
57
 
59
- def self.rewrite_aof
60
- client.bgrewriteaof
61
- end
58
+ def reconnect
59
+ client.reconnect
60
+ end
62
61
 
63
- def self.save
64
- client.bgsave
65
- end
62
+ def rewrite_aof
63
+ client.bgrewriteaof
64
+ end
66
65
 
67
- def self.saved_at
68
- client.lastsave
69
- end
66
+ def save
67
+ client.bgsave
68
+ end
70
69
 
71
- def self.shutdown
72
- client.shutdown
73
- end
70
+ def saved_at
71
+ client.lastsave
72
+ end
74
73
 
75
- def self.slave_of(host, port)
76
- client.slaveof(host, port)
77
- end
74
+ def shutdown
75
+ client.shutdown
76
+ end
78
77
 
79
- def self.slowlog(command, length = nil)
80
- client.slowlog(command, length)
81
- end
78
+ def slave_of(host, port)
79
+ client.slaveof(host, port)
80
+ end
82
81
 
83
- def self.synchronize
84
- client.synchronize
85
- end
82
+ def slowlog(command, length = nil)
83
+ client.slowlog(command, length)
84
+ end
86
85
 
87
- def self.time
88
- client.time
89
- end
86
+ def synchronize
87
+ client.synchronize
88
+ end
90
89
 
91
- def self.with_reconnect(&block)
92
- client.with_reconnect(true, &block)
93
- end
90
+ def time
91
+ client.time
92
+ end
94
93
 
95
- def self.without_reconnect(&block)
96
- client.with_reconnect(false, &block)
97
- end
94
+ def with_reconnect(&block)
95
+ client.with_reconnect(true, &block)
96
+ end
97
+
98
+ def without_reconnect(&block)
99
+ client.with_reconnect(false, &block)
100
+ end
98
101
 
102
+ end
99
103
  end