gdatastore_cache_store 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 41dc3d10d34e182bdda727e6306b343fb3c6dce2
4
+ data.tar.gz: 3248b7d6243f8fd891c34b04513513db11cfb8a2
5
+ SHA512:
6
+ metadata.gz: 8a94b000118680f1695f83deb55a6d2b370274954f34666e40bf8e081decf096321521ea9f3477eb4c192d5ca37b847c2df30f9264012ce486d8c531b3d7e6ce
7
+ data.tar.gz: 3a1207c759c78ce0b6e12d84f9083e130c5f15dfc12b28c0a0198afefe0cbea84679853d05dc2ed4d92160ffe39c49bf48b8674ff86901d428d642de09ca2c9b
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/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gdatastore_cache_store.gemspec
4
+ gemspec
5
+
6
+ gem 'google-cloud-datastore', '~> 1.1.0'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Julien Séveno
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,33 @@
1
+ # GdatastoreCacheStore
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gdatastore_cache_store`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gdatastore_cache_store'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gdatastore_cache_store
22
+
23
+ ## Usage
24
+
25
+ In your Rails application environment file :
26
+
27
+ ```ruby
28
+ config.cache_store = GdatastoreCacheStore.new('google-project-id', { EntityGenre: 'genre-of-your-entity', Keyfile: '/path/to/keyfile.json'})
29
+ ```
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gdatastore_cache_store"
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/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gdatastore_cache_store/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gdatastore_cache_store"
8
+ spec.version = GdatastoreCacheStore::VERSION
9
+ spec.authors = ["Julien Séveno"]
10
+ spec.email = ["julien.seveno@idol.io"]
11
+
12
+ spec.summary = %q{Use Google Datastore as a cache store for your Rails application}
13
+ spec.description = %q{Use Google Datastore as a cache store for your Rails application}
14
+ spec.homepage = "https://rubygems.org/gems/gdatastore_cache_store"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency "google-cloud-datastore", '~> 1.1', '>= 1.1.0'
31
+ spec.add_development_dependency "bundler", "~> 1.11"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ end
@@ -0,0 +1,3 @@
1
+ class GdatastoreCacheStore
2
+ version = VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,57 @@
1
+ require "gdatastore_cache_store/version"
2
+ require 'google/cloud/datastore'
3
+
4
+ class GdatastoreCacheStore
5
+ def initialize(project_id, options = { EntityGenre: 'Cache' })
6
+ @options = options.with_indifferent_access
7
+ %w(EntityGenre Keyfile).each do |required_key|
8
+ raise "options should contain #{required_key} parameter" unless @options.keys.include?(required_key)
9
+ end
10
+ @entity_genre = @options[:EntityGenre]
11
+ @datastore = Google::Cloud::Datastore.new(
12
+ project: project_id,
13
+ keyfile: @options[:Keyfile]
14
+ )
15
+ end
16
+
17
+ def options
18
+ @options
19
+ end
20
+
21
+ def read(key, _ = nil)
22
+ result = @datastore.find @entity_genre, key
23
+ return unless result
24
+
25
+ value = result['value']
26
+ return unless value.present?
27
+
28
+ result['kind'] == 'Hash' ? JSON.parse(value) : value
29
+ end
30
+
31
+ def write(key, value, _ = nil)
32
+ task = @datastore.entity cache_key(key) do |t|
33
+ t[:value] = value.is_a?(Hash) ? value.to_json : value
34
+ t[:kind] = value.class.to_s
35
+ end
36
+ @datastore.save task
37
+ end
38
+
39
+ def delete(key, _ = nil)
40
+ @datastore.delete cache_key(key)
41
+ end
42
+
43
+ def exist?(key, _ = nil)
44
+ read(key).present?
45
+ end
46
+
47
+ def cache_key(key)
48
+ @datastore.key @entity_genre, key
49
+ end
50
+
51
+ def fetch(key, _ = nil)
52
+ result = read(key)
53
+ return result if result.present?
54
+
55
+ write(key, yield)
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gdatastore_cache_store
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Julien Séveno
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: google-cloud-datastore
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.1.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.1.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.11'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.11'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ description: Use Google Datastore as a cache store for your Rails application
62
+ email:
63
+ - julien.seveno@idol.io
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - bin/console
74
+ - bin/setup
75
+ - gdatastore_cache_store.gemspec
76
+ - lib/gdatastore_cache_store.rb
77
+ - lib/gdatastore_cache_store/version.rb
78
+ homepage: https://rubygems.org/gems/gdatastore_cache_store
79
+ licenses:
80
+ - MIT
81
+ metadata:
82
+ allowed_push_host: https://rubygems.org
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.4.5
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Use Google Datastore as a cache store for your Rails application
103
+ test_files: []