active_orm 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6402a41fe830352f983fdd97911a64b778798e0c
4
+ data.tar.gz: f17b468669665f7e5c2d7ab190ffee73bc90738b
5
+ SHA512:
6
+ metadata.gz: fc1f5179861cd2e8fc31292d7b5bdf306b09b295c0cccf8606c6dc24b5ce5316ba8c373f930bb9e43632aaa6b5264569c380c8f569319e811dcda5cd972d210f
7
+ data.tar.gz: 408e73240083dbe63bd83a265c7624a70668b0d0d842303dbb8b05bfe35cdf7c8a3965cc14b98cf93f1fdc778b41de2f61f8325a51a25f4517137e9245c57698
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --backtrace
2
+ --color
3
+ --format progress
4
+ --order random
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ before_install:
2
+ - sudo apt-get install libxml2-dev
3
+ cache: bundler
4
+ language: ruby
5
+ notifications:
6
+ email:
7
+ recipients:
8
+ - j.gomez@drexed.com
9
+ on_failure: change
10
+ on_success: never
11
+ rvm:
12
+ - ruby-head
13
+ script: 'bundle exec rake'
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_orm.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # ActiveOrm
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/active_orm.svg)](http://badge.fury.io/rb/active_orm)
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/drexed/active_orm/badge.png)](https://coveralls.io/r/drexed/active_orm)
6
+
7
+ ActiveOrm is a library for object ruby mapping of different databases.
8
+
9
+ **Supported:**
10
+ * Redis
11
+
12
+ **Roadmap:**
13
+ * Cassandra
14
+ * InfluxDB
15
+
16
+ Note: Library will be rewritten to be even more flexible for connection switching.
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'active_orm'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install active_orm
33
+
34
+ ## Table of Contents
35
+
36
+ * [Redis](#redis)
37
+
38
+ ## Redis
39
+
40
+ **Configuration:**
41
+
42
+ **Options:**
43
+ * client: add a custom Redis client
44
+
45
+ ```ruby
46
+ ActiveOrm::Redis.configure do |config|
47
+ config.client = Redis.new(:host => "10.0.1.1", :port => 6380, :db => 15)
48
+ end
49
+ ```
50
+
51
+ **Usage:**
52
+
53
+ **Commands:**
54
+ * Geo
55
+ * Hash
56
+ * HyperLogLog
57
+ * Key
58
+ * List
59
+ * PubSub
60
+ * Script
61
+ * Set
62
+ * Sorted Set
63
+ * String
64
+ * Transaction
65
+
66
+ ```ruby
67
+ ActiveOrm::Redis::String.create(:month, "01")
68
+ ActiveOrm::Redis::String.find(:month) #=> "01"
69
+ ActiveOrm::Redis::String.evaluate.find(:month) #=> 1
70
+
71
+ ActiveOrm::Redis::List.create(:user_1, { id: 32123, name: "James Dean", username: "alpha123" })
72
+ ActiveOrm::Redis::List.find(:user_1) #=> { id: "32123", name: "James Dean", username: "alpha123" }
73
+ ActiveOrm::Redis::List.evaluate.find(:user_1) #=> { id: 32123, name: "James Dean", username: "alpha123" }
74
+ ```
75
+
76
+ ## Contributing
77
+
78
+ 1. Fork it ( https://github.com/[my-github-username]/active_orm/fork )
79
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
80
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
81
+ 4. Push to the branch (`git push origin my-new-feature`)
82
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task default: :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_orm/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_orm"
8
+ spec.version = ActiveOrm::VERSION
9
+ spec.authors = ["Juan Gomez"]
10
+ spec.email = ["j.gomez@drexed.com"]
11
+
12
+ spec.summary = %q{Commonly used database ORM.}
13
+ spec.description = %q{ORM for non-supported databases.}
14
+ spec.homepage = "https://github.com/drexed/active_orm"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "coveralls"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_orm"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/active_orm.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "active_orm/version"
2
+ require "active_orm/base"
3
+
4
+ require "active_orm/redis"
5
+ require "active_orm/redis/connection"
6
+ require "active_orm/redis/geo"
7
+ require "active_orm/redis/hash"
8
+ require "active_orm/redis/hyper_log_log"
9
+ require "active_orm/redis/key"
10
+ require "active_orm/redis/list"
11
+ require "active_orm/redis/pub_sub"
12
+ require "active_orm/redis/script"
13
+ require "active_orm/redis/set"
14
+ require "active_orm/redis/sorted_set"
15
+ require "active_orm/redis/string"
16
+ require "active_orm/redis/transaction"
@@ -0,0 +1,17 @@
1
+ class ActiveOrm::Base
2
+
3
+ attr_accessor :configuration
4
+
5
+ def self.configuration
6
+ @configuration ||= Configuration.new
7
+ end
8
+
9
+ def self.configuration=(config)
10
+ @configuration = config
11
+ end
12
+
13
+ def self.configure
14
+ yield(configuration)
15
+ end
16
+
17
+ end
@@ -0,0 +1,19 @@
1
+ require "redis"
2
+
3
+ require "active_orm/redis/base"
4
+ require "active_orm/redis/configuration"
5
+ class ActiveOrm::Redis < ActiveOrm::Base
6
+
7
+ extend Base
8
+
9
+ attr_accessor :client
10
+
11
+ def initialize(client=nil)
12
+ @client ||= (client.nil? ? ActiveOrm::Redis.configuration.client : client)
13
+ end
14
+
15
+ def self.client(client=nil)
16
+ client.nil? ? new.client : new(client).client
17
+ end
18
+
19
+ end
@@ -0,0 +1,61 @@
1
+ module Base
2
+
3
+ @@evaluate = false
4
+
5
+ def evaluate(value=true)
6
+ @@evaluate = value
7
+ return(self)
8
+ end
9
+
10
+ def evaluate?
11
+ value = @@evaluate
12
+ @@evaluate = false
13
+ return(value)
14
+ end
15
+
16
+ private
17
+
18
+ def metaform(value)
19
+ value.nil? ? value : (eval(value) rescue value)
20
+ end
21
+
22
+ def metamorph(args)
23
+ case args.class.name
24
+ when "Array"
25
+ args.first.is_a?(Array) ? args.map { |h| h.map { |v| metaform(v) } } : args.map { |v| metaform(v) }
26
+ when "Hash"
27
+ args.each { |k, v| args[k] = metaform(v) }
28
+ else
29
+ metaform(args)
30
+ end
31
+ end
32
+
33
+ def metatransform(value)
34
+ value.empty? ? nil : (evaluate? ? metamorph(value) : value)
35
+ end
36
+
37
+ def normalize_key(key)
38
+ key.to_s
39
+ end
40
+
41
+ def stringify_keys(value)
42
+ value.map { |k, v| k.to_s }
43
+ end
44
+
45
+ def append?(order)
46
+ "append" == order.to_s
47
+ end
48
+
49
+ def prepend?(order)
50
+ "prepend" == order.to_s
51
+ end
52
+
53
+ def milliseconds?(format)
54
+ "milliseconds" == format.to_s
55
+ end
56
+
57
+ def seconds?(format)
58
+ "seconds" == format.to_s
59
+ end
60
+
61
+ end
@@ -0,0 +1,9 @@
1
+ class Configuration
2
+
3
+ attr_accessor :client
4
+
5
+ def initialize
6
+ @client ||= Redis.new
7
+ end
8
+
9
+ end
@@ -0,0 +1,103 @@
1
+ class ActiveOrm::Redis::Connection < ActiveOrm::Redis
2
+
3
+ def self.authenticate(password)
4
+ client.auth(password)
5
+ end
6
+
7
+ def self.connected?
8
+ client.connected?
9
+ end
10
+
11
+ def self.database(index)
12
+ client.select(index)
13
+ end
14
+
15
+ def self.database_id
16
+ client.database_id
17
+ end
18
+
19
+ def self.database_size
20
+ client.dbsize
21
+ end
22
+
23
+ def self.debug(*args)
24
+ client.debug(args)
25
+ end
26
+
27
+ def self.disconnect
28
+ client.disconnect
29
+ end
30
+
31
+ def self.echo(message)
32
+ client.echo(message)
33
+ end
34
+
35
+ def self.flush
36
+ client.flushdb
37
+ end
38
+
39
+ def self.flush_all
40
+ client.flushall
41
+ end
42
+
43
+ def self.info
44
+ client.info
45
+ end
46
+
47
+ def self.ping
48
+ client.ping
49
+ end
50
+
51
+ def self.quit
52
+ client.quit
53
+ end
54
+
55
+ def self.reconnect
56
+ client.reconnect
57
+ end
58
+
59
+ def self.rewrite_aof
60
+ client.bgrewriteaof
61
+ end
62
+
63
+ def self.save
64
+ client.bgsave
65
+ end
66
+
67
+ def self.saved_at
68
+ client.lastsave
69
+ end
70
+
71
+ def self.shutdown
72
+ client.shutdown
73
+ end
74
+
75
+ def self.shutdown
76
+ client.shutdown
77
+ end
78
+
79
+ def self.slave_of(host, port)
80
+ client.slaveof(host, port)
81
+ end
82
+
83
+ def self.slowlog(command, length=nil)
84
+ client.slowlog(command, length)
85
+ end
86
+
87
+ def self.synchronize
88
+ client.synchronize
89
+ end
90
+
91
+ def self.time
92
+ client.time
93
+ end
94
+
95
+ def self.with_reconnect(val=true, &block)
96
+ client.with_reconnect(val, &block)
97
+ end
98
+
99
+ def self.without_reconnect(&block)
100
+ client.with_reconnect(false, &block)
101
+ end
102
+
103
+ end
@@ -0,0 +1,27 @@
1
+ class ActiveOrm::Redis::Geo < ActiveOrm::Redis
2
+
3
+ def self.create
4
+ # TODO
5
+ end
6
+
7
+ def self.hash
8
+ # TODO
9
+ end
10
+
11
+ def self.position
12
+ # TODO
13
+ end
14
+
15
+ def self.distance
16
+ # TODO
17
+ end
18
+
19
+ def self.radius
20
+ # TODO
21
+ end
22
+
23
+ def self.radius_member
24
+ # TODO
25
+ end
26
+
27
+ end
@@ -0,0 +1,69 @@
1
+ class ActiveOrm::Redis::Hash < ActiveOrm::Redis
2
+
3
+ def self.find(key, field)
4
+ value = client.hget(normalize_key(key), field)
5
+ value = metamorph(value) if evaluate?
6
+ return(value)
7
+ end
8
+
9
+ def self.find_each(key, *args)
10
+ value = client.hmget(normalize_key(key), args)
11
+ value = metamorph(value) if evaluate?
12
+ return(value)
13
+ end
14
+
15
+ def self.all(key)
16
+ value = client.hgetall(normalize_key(key))
17
+ value = metamorph(value) if evaluate?
18
+ return(value)
19
+ end
20
+
21
+ def self.keys(key)
22
+ value = client.hkeys(normalize_key(key))
23
+ value = metamorph(value) if evaluate?
24
+ return(value)
25
+ end
26
+
27
+ def self.values(key)
28
+ value = client.hvals(normalize_key(key))
29
+ value = metamorph(value) if evaluate?
30
+ return(value)
31
+ end
32
+
33
+ def self.value_length(key, field)
34
+ client.hstrlen(normalize_key(key), field)
35
+ end
36
+
37
+ def self.count(key)
38
+ client.hlen(normalize_key(key))
39
+ end
40
+
41
+ def self.exists?(key, field)
42
+ client.hexists(normalize_key(key), field)
43
+ end
44
+
45
+ def self.create(key, field, value)
46
+ client.hset(normalize_key(key), field, value)
47
+ end
48
+
49
+ def self.create!(key, field, value)
50
+ client.hsetnx(normalize_key(key), field, value)
51
+ end
52
+
53
+ def self.create_each(key, *args)
54
+ client.hmset(normalize_key(key), *args)
55
+ end
56
+
57
+ def self.increment(key, field, value)
58
+ value.is_a?(Float) ? client.hincrbyfloat(normalize_key(key), field, value) : client.hincrby(normalize_key(key), field, value)
59
+ end
60
+
61
+ def self.destroy(key, *args)
62
+ client.hdel(normalize_key(key), *args)
63
+ end
64
+
65
+ def self.scan(key, cursor, opts={})
66
+ client.hdel(normalize_key(key), cursor, opts)
67
+ end
68
+
69
+ end
@@ -0,0 +1,15 @@
1
+ class ActiveOrm::Redis::HyperLogLog < ActiveOrm::Redis
2
+
3
+ def self.create(key, member)
4
+ client.pfadd(normalize_key(key), member)
5
+ end
6
+
7
+ def self.count(*args)
8
+ client.pfcount(args)
9
+ end
10
+
11
+ def self.merge(key, *keys)
12
+ client.pfmerge(normalize_key(key), keys)
13
+ end
14
+
15
+ end
@@ -0,0 +1,81 @@
1
+ class ActiveOrm::Redis::Key < ActiveOrm::Redis
2
+
3
+ def self.exists?(key)
4
+ client.exists(normalize_key(key))
5
+ end
6
+
7
+ def self.type?(key)
8
+ client.type(normalize_key(key))
9
+ end
10
+
11
+ def self.ttl?(key, format=:seconds)
12
+ seconds?(format) ? client.ttl(normalize_key(key)) : client.pttl(normalize_key(key))
13
+ end
14
+
15
+ def self.sort(key, opts={})
16
+ client.sort(normalize_key(key), opts)
17
+ end
18
+
19
+ def self.sample
20
+ client.randomkey
21
+ end
22
+
23
+ def self.rename(key, value)
24
+ client.rename(normalize_key(key), value.to_s)
25
+ end
26
+
27
+ def self.rename!(key, value)
28
+ client.renamenx(normalize_key(key), value.to_s)
29
+ end
30
+
31
+ def self.destroy(key)
32
+ client.del(normalize_key(key))
33
+ end
34
+
35
+ def self.persist(key)
36
+ client.persist(normalize_key(key))
37
+ end
38
+
39
+ def self.expire(key, seconds, format=:seconds)
40
+ seconds?(format) ? client.expire(normalize_key(key), seconds) : client.pexpire(normalize_key(key), seconds)
41
+ end
42
+
43
+ def self.expire_at(key, seconds, format=:seconds)
44
+ seconds?(format) ? client.expireat(normalize_key(key), seconds) : client.pexpireat(normalize_key(key), seconds)
45
+ end
46
+
47
+ def self.dump(key)
48
+ client.dump(normalize_key(key))
49
+ end
50
+
51
+ def self.match(pattern="*")
52
+ value = client.keys(normalize_key(pattern))
53
+ value = nil if value.empty?
54
+ return(value)
55
+ end
56
+
57
+ def self.migrate(key, options)
58
+ client.migrate(normalize_key(key), options)
59
+ end
60
+
61
+ def self.move(key, destination)
62
+ client.move(normalize_key(key), destination)
63
+ end
64
+
65
+ def self.object(*args)
66
+ client.object(args)
67
+ end
68
+
69
+ def self.restore(key, milliseconds, value)
70
+ client.restore(normalize_key(key), milliseconds, value)
71
+ end
72
+
73
+ def self.sort(key, opts={})
74
+ client.sort(normalize_key(key), opts)
75
+ end
76
+
77
+ def self.scan(cursor, opts={})
78
+ client.scan(cursor, opts)
79
+ end
80
+
81
+ end
@@ -0,0 +1,113 @@
1
+ class ActiveOrm::Redis::List < ActiveOrm::Redis
2
+
3
+ def self.find(key, position=1)
4
+ value = client.lindex(normalize_key(key), (position - 1))
5
+ value = metamorph(value) if evaluate?
6
+ return(value)
7
+ end
8
+
9
+ def self.first(key, limit=1)
10
+ value = client.lrange(normalize_key(key), 0, -1)
11
+ value = ((limit == 1) ? value.first : value.first(limit))
12
+ value = metamorph(value) if evaluate?
13
+ return(value)
14
+ end
15
+
16
+ def self.last(key, limit=1)
17
+ value = client.lrange(normalize_key(key), 0, -1)
18
+ value = ((limit == 1) ? value.last : value.last(limit))
19
+ value = metamorph(value) if evaluate?
20
+ return(value)
21
+ end
22
+
23
+ def self.between(key, start=1, finish=0)
24
+ value = client.lrange(normalize_key(key), (start - 1), (finish - 1))
25
+ value = metatransform(value)
26
+ return(value)
27
+ end
28
+
29
+ def self.all(key)
30
+ value = client.lrange(normalize_key(key), 0, -1)
31
+ value = metatransform(value)
32
+ return(value)
33
+ end
34
+
35
+ def self.count(key)
36
+ client.llen(normalize_key(key))
37
+ end
38
+
39
+ def self.create(key, value, order=:prepend)
40
+ append?(order) ? client.rpush(normalize_key(key), value) : client.lpush(normalize_key(key), value)
41
+ end
42
+
43
+ def self.create!(key, value, order=:prepend)
44
+ append?(order) ? client.rpushx(normalize_key(key), value) : client.lpushx(normalize_key(key), value)
45
+ end
46
+
47
+ def self.create_limit(key, value, limit, order=:prepend)
48
+ append?(order) ? client.rpush(normalize_key(key), value) : client.lpush(normalize_key(key), value)
49
+ client.ltrim(normalize_key(key), 0, (limit - 1))
50
+ end
51
+
52
+ def self.create_limit!(key, value, limit, order=:prepend)
53
+ append?(order) ? client.rpushx(normalize_key(key), value) : client.lpushx(normalize_key(key), value)
54
+ client.ltrim(normalize_key(key), 0, (limit - 1))
55
+ end
56
+
57
+ def self.create_before(key, pivot, value)
58
+ client.linsert(normalize_key(key), :before, pivot, value)
59
+ end
60
+
61
+ def self.create_after(key, pivot, value)
62
+ client.linsert(normalize_key(key), :after, pivot, value)
63
+ end
64
+
65
+ def self.update(key, index, value)
66
+ client.lset(normalize_key(key), index, value)
67
+ end
68
+
69
+ def self.move(key, desination)
70
+ value = client.rpoplpush(normalize_key(key), normalize_key(desination))
71
+ value = metamorph(value) if evaluate?
72
+ return(value)
73
+ end
74
+
75
+ def self.move_blocking(key, desination, opts={})
76
+ value = brpoplpush(normalize_key(key), normalize_key(desination))
77
+ value = metamorph(value) if evaluate?
78
+ return(value)
79
+ end
80
+
81
+ def self.destroy(key, count, value)
82
+ client.lrem(normalize_key(key), count, value)
83
+ end
84
+
85
+ def self.destroy_first(key, limit=1)
86
+ client.ltrim(normalize_key(key), limit, -1)
87
+ end
88
+
89
+ def self.destroy_last(key, limit=1)
90
+ client.ltrim(normalize_key(key), 0, -(limit + 1))
91
+ end
92
+
93
+ def self.destroy_except(key, start, finish)
94
+ client.ltrim(normalize_key(key), (start - 1), (finish - 1))
95
+ end
96
+
97
+ def self.destroy_all(key)
98
+ client.ltrim(normalize_key(key), -1, 0)
99
+ end
100
+
101
+ def self.pop(key, order=:prepend)
102
+ value = append?(order) ? client.rpop(key) : client.lpop(key)
103
+ value = metamorph(value) if evaluate?
104
+ return(value)
105
+ end
106
+
107
+ def self.pop_blocking(keys, opts={})
108
+ value = append?(opts.fetch(:order, :prepend)) ? client.brpop(keys, opts.fetch(:timeout, 0)) : client.blpop(keys, opts.fetch(:timeout, 0))
109
+ value = metamorph(value) if evaluate?
110
+ return(value)
111
+ end
112
+
113
+ end
@@ -0,0 +1,31 @@
1
+ class ActiveOrm::Redis::PubSub < ActiveOrm::Redis
2
+
3
+ def self.publish(channel, message)
4
+ client.publish(channel, message)
5
+ end
6
+
7
+ def self.subscribed?
8
+ client.subscribed?
9
+ end
10
+
11
+ def self.subscribe(*channels, &block)
12
+ client.subscribe(channels, &block)
13
+ end
14
+
15
+ def self.unsubscribe(*channels)
16
+ client.unsubscribe(channels)
17
+ end
18
+
19
+ def self.match_subscribe(*channels, &block)
20
+ client.psubscribe(channels, &block)
21
+ end
22
+
23
+ def self.match_unsubscribe(*channels)
24
+ client.punsubscribe(channels)
25
+ end
26
+
27
+ def self.state(command, *args)
28
+ client.pubsub(command, args)
29
+ end
30
+
31
+ end
@@ -0,0 +1,15 @@
1
+ class ActiveOrm::Redis::Script < ActiveOrm::Redis
2
+
3
+ def self.script(command, *args)
4
+ client.script(command, args)
5
+ end
6
+
7
+ def self.eval(*args)
8
+ client.eval(:eval, args)
9
+ end
10
+
11
+ def self.evalsha(*args)
12
+ client.eval(:evalsha, args)
13
+ end
14
+
15
+ end
@@ -0,0 +1,73 @@
1
+ class ActiveOrm::Redis::Set < ActiveOrm::Redis
2
+
3
+ def self.find(key)
4
+ value = client.smembers(normalize_key(key))
5
+ value = metatransform(value)
6
+ return(value)
7
+ end
8
+
9
+ def self.combine(*args)
10
+ value = client.sunion(*args)
11
+ value = metatransform(value)
12
+ return(value)
13
+ end
14
+
15
+ def self.difference(*args)
16
+ value = client.sdiff(*args)
17
+ value = metatransform(value)
18
+ return(value)
19
+ end
20
+
21
+ def self.intersection(key, *args)
22
+ value = client.sinter(normalize_key(key), *args)
23
+ value = metatransform(value)
24
+ return(value)
25
+ end
26
+
27
+ def self.sample(key, value=1)
28
+ value = client.srandmember(normalize_key(key), value)
29
+ value = metatransform(value)
30
+ return(value)
31
+ end
32
+
33
+ def self.value?(key, value)
34
+ client.sismember(normalize_key(key), value)
35
+ end
36
+
37
+ def self.count(key)
38
+ client.scard(normalize_key(key))
39
+ end
40
+
41
+ def self.create(key, *args)
42
+ client.sadd(normalize_key(key), args)
43
+ end
44
+
45
+ def self.create_combination(key, *args)
46
+ client.sunionstore(normalize_key(key), *args)
47
+ end
48
+
49
+ def self.create_difference(key, *args)
50
+ client.sdiffstore(normalize_key(key), *args)
51
+ end
52
+
53
+ def self.create_intersection(key, *args)
54
+ client.sinterstore(normalize_key(key), *args)
55
+ end
56
+
57
+ def self.move(key, destination, value)
58
+ client.smove(normalize_key(key), destination.to_s, value)
59
+ end
60
+
61
+ def self.destroy(key, *args)
62
+ client.srem(normalize_key(key), *args)
63
+ end
64
+
65
+ def self.destroy_random(key)
66
+ client.spop(normalize_key(key))
67
+ end
68
+
69
+ def self.scan(key, cursor, opts={})
70
+ client.sscan(normalize_key(key), cursor, opts)
71
+ end
72
+
73
+ end
@@ -0,0 +1,147 @@
1
+ class ActiveOrm::Redis::SortedSet < ActiveOrm::Redis
2
+
3
+ def self.find(key, position, opts={})
4
+ value = client.zrange(normalize_key(key), (position - 1), (position - 1), opts)
5
+ value = value.first
6
+ value = metamorph(value) if evaluate?
7
+ return(value)
8
+ end
9
+
10
+ def self.find_score(key, position, opts={})
11
+ value = client.zrangebyscore(normalize_key(key), position, position, opts)
12
+ value = value.first
13
+ value = metamorph(value) if evaluate?
14
+ return(value)
15
+ end
16
+
17
+ def self.first(key, opts={})
18
+ value = client.zrange(normalize_key(key), 0, 0, opts)
19
+ value = value.first
20
+ value = metamorph(value) if evaluate?
21
+ return(value)
22
+ end
23
+
24
+ def self.first_score(key, opts={})
25
+ value = client.zrangebyscore(normalize_key(key), 1, 1, opts)
26
+ value = value.first
27
+ value = metamorph(value) if evaluate?
28
+ return(value)
29
+ end
30
+
31
+ def self.last(key, opts={})
32
+ value = client.zrevrange(normalize_key(key), 0, 0, opts)
33
+ value = value.first
34
+ value = metamorph(value) if evaluate?
35
+ return(value)
36
+ end
37
+
38
+ def self.last_score(key, opts={})
39
+ value = client.zrevrangebyscore(normalize_key(key), 1, 1, opts)
40
+ value = value.first
41
+ value = metamorph(value) if evaluate?
42
+ return(value)
43
+ end
44
+
45
+ def self.between(key, start, finish, opts={})
46
+ value = client.zrange(normalize_key(key), (start - 1), (finish - 1), opts)
47
+ value = metatransform(value)
48
+ return(value)
49
+ end
50
+
51
+ def self.between_reverse(key, start, finish, opts={})
52
+ value = client.zrevrange(normalize_key(key), (start - 1), (finish - 1), opts)
53
+ value = metatransform(value)
54
+ return(value)
55
+ end
56
+
57
+ def self.between_scores(key, min, max, opts={})
58
+ value = client.zrangebyscore(normalize_key(key), min, max, opts)
59
+ value = metatransform(value)
60
+ return(value)
61
+ end
62
+
63
+ def self.between_scores_reverse(key, min, max, opts={})
64
+ value = client.zrevrangebyscore(normalize_key(key), min, max, opts)
65
+ value = metatransform(value)
66
+ return(value)
67
+ end
68
+
69
+ def self.between_lex(key, min, max, opts={})
70
+ value = client.zrangebylex(normalize_key(key), min, max, opts)
71
+ value = metatransform(value)
72
+ return(value)
73
+ end
74
+
75
+ def self.between_lex_reverse(key, min, max, opts={})
76
+ value = client.zrevrangebylex(normalize_key(key), min, max, opts)
77
+ value = metatransform(value)
78
+ return(value)
79
+ end
80
+
81
+ def self.all(key, opts={})
82
+ value = client.zrange(normalize_key(key), "-inf", "+inf", opts)
83
+ value = metatransform(value)
84
+ return(value)
85
+ end
86
+
87
+ def self.position(key, value)
88
+ value = client.zrank(normalize_key(key), value)
89
+ value = value + 1 unless value.nil?
90
+ return(value)
91
+ end
92
+
93
+ def self.position_reverse(key, value)
94
+ value = client.zrevrank(normalize_key(key), value)
95
+ value = value + 1 unless value.nil?
96
+ return(value)
97
+ end
98
+
99
+ def self.score(key, value)
100
+ client.zscore(normalize_key(key), value)
101
+ end
102
+
103
+ def self.count(key)
104
+ client.zcard(normalize_key(key))
105
+ end
106
+
107
+ def self.count_between(key, min, max)
108
+ client.zcount(normalize_key(key), min, max)
109
+ end
110
+
111
+ def self.create(key, *args)
112
+ client.zadd(normalize_key(key), args)
113
+ end
114
+
115
+ def self.create_intersection(key, keys, opts={})
116
+ client.zinterstore(normalize_key(key), keys, opts)
117
+ end
118
+
119
+ def self.create_combination(key, keys, opts={})
120
+ client.zunionstore(normalize_key(key), keys, opts)
121
+ end
122
+
123
+ def self.increment(key, value, count)
124
+ client.zincrby(normalize_key(key), count, value)
125
+ end
126
+
127
+ def self.destroy(key, at)
128
+ client.zrem(normalize_key(key), at)
129
+ end
130
+
131
+ def self.destroy_between(key, start, finish)
132
+ client.zremrangebyrank(normalize_key(key), (start - 1), (finish - 1))
133
+ end
134
+
135
+ def self.destroy_scores(key, min, max)
136
+ client.zremrangebyscore(normalize_key(key), min, max)
137
+ end
138
+
139
+ def self.destroy_lex(key, min, max, opts={})
140
+ client.zrevrangebylex(normalize_key(key), max, min, opts)
141
+ end
142
+
143
+ def self.scan(key, cursor, opts={})
144
+ client.zscan(normalize_key(key), cursor, opts)
145
+ end
146
+
147
+ end
@@ -0,0 +1,82 @@
1
+ class ActiveOrm::Redis::String < ActiveOrm::Redis
2
+
3
+ def self.find(key)
4
+ value = client.get(normalize_key(key))
5
+ value = metamorph(value) if evaluate?
6
+ return(value)
7
+ end
8
+
9
+ def self.find_each(*args)
10
+ args = stringify_keys(args)
11
+ value = client.mget(args)
12
+ value = metamorph(value) if evaluate?
13
+ return(value)
14
+ end
15
+
16
+ def self.length(key)
17
+ client.strlen(normalize_key(key))
18
+ end
19
+
20
+ def self.split(key, start, finish)
21
+ client.getrange(normalize_key(key), start, finish)
22
+ end
23
+
24
+ def self.create(key, value, opts={})
25
+ client.set(normalize_key(key), value, opts)
26
+ end
27
+
28
+ def self.create!(key, value)
29
+ client.setnx(normalize_key(key), value)
30
+ end
31
+
32
+ def self.create_each(*args)
33
+ args = stringify_keys(args)
34
+ client.mset(args)
35
+ end
36
+
37
+ def self.create_each!(*args)
38
+ args = stringify_keys(args)
39
+ client.msetnx(args)
40
+ end
41
+
42
+ def self.create_until(key, value, seconds, format=:seconds)
43
+ seconds?(format) ? client.setex(normalize_key(key), seconds, value) : client.psetex(normalize_key(key), seconds, value)
44
+ end
45
+
46
+ def self.append(key, value)
47
+ client.append(normalize_key(key), value)
48
+ end
49
+
50
+ def self.replace(key, value, offset)
51
+ client.setrange(normalize_key(key), offset, value)
52
+ end
53
+
54
+ def self.decrement(key, value=1)
55
+ (value == 1) ? client.decr(normalize_key(key)) : client.decrby(normalize_key(key), value)
56
+ end
57
+
58
+ def self.increment(key, value=1)
59
+ if value.is_a?(Float)
60
+ client.incrbyfloat(normalize_key(key), value)
61
+ else
62
+ (value == 1) ? client.incr(normalize_key(key)) : client.incrby(normalize_key(key), value)
63
+ end
64
+ end
65
+
66
+ def self.reset(key, value=0)
67
+ client.getset(normalize_key(key), value)
68
+ end
69
+
70
+ def self.bit_count(key, start=0, finish=-1)
71
+ client.bitcount(normalize_key(key), start, finish)
72
+ end
73
+
74
+ def self.get_bit(key, offset)
75
+ client.getbit(normalize_key(key), offset)
76
+ end
77
+
78
+ def self.set_bit(key, offset, bit)
79
+ client.setbit(normalize_key(key), offset, bit)
80
+ end
81
+
82
+ end
@@ -0,0 +1,23 @@
1
+ class ActiveOrm::Redis::Transaction < ActiveOrm::Redis
2
+
3
+ def self.discard
4
+ client.discard
5
+ end
6
+
7
+ def self.exec
8
+ client.exec
9
+ end
10
+
11
+ def self.multi(&block)
12
+ client.multi(&block)
13
+ end
14
+
15
+ def self.watch(*args)
16
+ client.watch(args)
17
+ end
18
+
19
+ def self.unwatch
20
+ client.unwatch
21
+ end
22
+
23
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveOrm
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_orm
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Juan Gomez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ORM for non-supported databases.
70
+ email:
71
+ - j.gomez@drexed.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".coveralls.yml"
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - README.md
83
+ - Rakefile
84
+ - active_orm.gemspec
85
+ - bin/console
86
+ - bin/rake
87
+ - bin/setup
88
+ - lib/active_orm.rb
89
+ - lib/active_orm/base.rb
90
+ - lib/active_orm/redis.rb
91
+ - lib/active_orm/redis/base.rb
92
+ - lib/active_orm/redis/configuration.rb
93
+ - lib/active_orm/redis/connection.rb
94
+ - lib/active_orm/redis/geo.rb
95
+ - lib/active_orm/redis/hash.rb
96
+ - lib/active_orm/redis/hyper_log_log.rb
97
+ - lib/active_orm/redis/key.rb
98
+ - lib/active_orm/redis/list.rb
99
+ - lib/active_orm/redis/pub_sub.rb
100
+ - lib/active_orm/redis/script.rb
101
+ - lib/active_orm/redis/set.rb
102
+ - lib/active_orm/redis/sorted_set.rb
103
+ - lib/active_orm/redis/string.rb
104
+ - lib/active_orm/redis/transaction.rb
105
+ - lib/active_orm/version.rb
106
+ homepage: https://github.com/drexed/active_orm
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.8
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Commonly used database ORM.
130
+ test_files: []