collectionadapters 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/collectionadapters.gemspec +31 -0
- data/lib/collectionadapters/hash_sequel.rb +42 -0
- data/lib/collectionadapters/hash_sequel.rb~ +39 -0
- data/lib/collectionadapters/version.rb +3 -0
- data/lib/collectionadapters.rb +7 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0e6b15127d37e2c2fb9dc0519eaf3bf93f59b8a617fb2113dfd9bc3a5be1656c
|
4
|
+
data.tar.gz: 537506e2dfd758415109a38609ecf7dc30a62d3c55bb596576b36a89f89ceaa6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a00302535344debb22140ff4bfdfcd54e2122ad06b29ed8589b0f09760100e0c6ff1676f1f1d3079b8735a5ca01d9920f28a95d4da938d96e6adb55cbf734d57
|
7
|
+
data.tar.gz: d63d6e4e9c0ca29bb7e1b0594089366f7c059be25bc42e8bdff35b4998afdd0a963e45c306e1816d238223cbd55f0b1a8ece1c4db75f64cb702f9e77d41d8303
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Vidar Hokstad
|
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 in
|
13
|
+
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 NONINFRINGEMENT. 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Collectionadapters
|
2
|
+
|
3
|
+
A small set of adapters to allow you to drop in different alternative
|
4
|
+
behaviors in cases where limited interfaces of the Ruby collection classes
|
5
|
+
(Hash, Set, Array etc.) are expected.
|
6
|
+
|
7
|
+
Contributions welcome.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'collectionadapters'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install collectionadapters
|
24
|
+
|
25
|
+
To avoid pulling in unnecessary numbers of additional gems, please
|
26
|
+
consult the documentation for each adapter for additional dependencies.
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
TODO: Write usage instructions here
|
31
|
+
|
32
|
+
## Development
|
33
|
+
|
34
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
35
|
+
|
36
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/vidarh/collectionadapters.
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "collectionadapters"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "collectionadapters/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "collectionadapters"
|
8
|
+
spec.version = Collectionadapters::VERSION
|
9
|
+
spec.authors = ["Vidar Hokstad"]
|
10
|
+
spec.email = ["vidar@hokstad.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A set of small adapaters to provide narrow subsets of Ruby collection interfaces to various data stores.}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "http://github.com/vidarh/collectionadapters"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_development_dependency "sequel"
|
30
|
+
spec.add_development_dependency "sqlite3"
|
31
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
module CollectionAdapters
|
3
|
+
# Takes a Sequel model
|
4
|
+
# and provides +#[]+ and +#[]=+
|
5
|
+
# using Sequels API.
|
6
|
+
#
|
7
|
+
# Values are converted silently to String's
|
8
|
+
#
|
9
|
+
# NOTE: You need to require 'sequel'
|
10
|
+
# yourself; this is to allow you to
|
11
|
+
# optionally also use this adapter
|
12
|
+
# with other classes that provide the
|
13
|
+
# same API.
|
14
|
+
#
|
15
|
+
class HashSequel
|
16
|
+
def initialize(model:, keycolumn:, valuecolumn:)
|
17
|
+
@model = model
|
18
|
+
@k = keycolumn.to_sym
|
19
|
+
@v = valuecolumn.to_sym
|
20
|
+
end
|
21
|
+
|
22
|
+
def []= (key, value)
|
23
|
+
key = key.to_s
|
24
|
+
(@model.first(@k => key) || @model.new).set(@k => key, @v => value).save
|
25
|
+
value
|
26
|
+
end
|
27
|
+
|
28
|
+
def [] (key)
|
29
|
+
r = @model[@k => key.to_s]
|
30
|
+
r ? r.values[@v] : nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete(key)
|
34
|
+
if ob = @model.first(@k => key.to_s)
|
35
|
+
ob.delete
|
36
|
+
ob.values[@v]
|
37
|
+
else
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
module CollectionAdapters
|
3
|
+
# Takes a Sequel model
|
4
|
+
# and provides +#[]+ and +#[]=+
|
5
|
+
# using Sequels API.
|
6
|
+
#
|
7
|
+
# Values are converted silently to String's
|
8
|
+
#
|
9
|
+
# NOTE: You need to require 'sequel'
|
10
|
+
# yourself; this is to allow you to
|
11
|
+
# optionally also use this adapter
|
12
|
+
# with other classes that provide the
|
13
|
+
# same API.
|
14
|
+
#
|
15
|
+
class HashSequel
|
16
|
+
def initialize(model:, keycolumn:, valuecolumn:)
|
17
|
+
@model = model
|
18
|
+
@k = keycolumn.to_sym
|
19
|
+
@v = valuecolumn.to_sym
|
20
|
+
end
|
21
|
+
|
22
|
+
def []= (key, value)
|
23
|
+
key = key.to_s
|
24
|
+
(@model.first(@k => key) || @model.new).set(@k => key, @v => value).save
|
25
|
+
value
|
26
|
+
end
|
27
|
+
|
28
|
+
def [] (key)
|
29
|
+
r = @model[@k => key.to_s]
|
30
|
+
r ? r.values[@v] : nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete(key)
|
34
|
+
ob = @model.first(@k => key.to_s)
|
35
|
+
ob.delete
|
36
|
+
ob.values[@v]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: collectionadapters
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vidar Hokstad
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-06 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: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sequel
|
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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: A set of small adapaters to provide narrow subsets of Ruby collection
|
84
|
+
interfaces to various data stores.
|
85
|
+
email:
|
86
|
+
- vidar@hokstad.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- collectionadapters.gemspec
|
101
|
+
- lib/collectionadapters.rb
|
102
|
+
- lib/collectionadapters/hash_sequel.rb
|
103
|
+
- lib/collectionadapters/hash_sequel.rb~
|
104
|
+
- lib/collectionadapters/version.rb
|
105
|
+
homepage: http://github.com/vidarh/collectionadapters
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.7.6
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: A set of small adapaters to provide narrow subsets of Ruby collection interfaces
|
129
|
+
to various data stores.
|
130
|
+
test_files: []
|