hoodie 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hoodie.rb +17 -0
- data/lib/hoodie/configuration.rb +9 -3
- data/lib/hoodie/{stash/memoizable.rb → memoizable.rb} +0 -0
- data/lib/hoodie/stash.rb +5 -79
- data/lib/hoodie/stash/cache.rb +98 -0
- data/lib/hoodie/stash/disk_store.rb +4 -4
- data/lib/hoodie/stash/mem_store.rb +119 -118
- data/lib/hoodie/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8239c5f1758d3b1410a3fff7cf54a0cfd1da5f72
|
4
|
+
data.tar.gz: ba500bccbbb541fb088a03306c9c1bbc7b975cc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a604c03ae6205db87d7efa9d47e12f922ea2dc8140ab95694c944feaf0ae81945e4b20c16616414288f1517818300c9616c452b8678e1fa59af7e6fc32d6521
|
7
|
+
data.tar.gz: 59fdb057c73eafd26b40b8878299f28a7fc0834f0f3e83bc472b07c2a1dd7633186c2da1258c7152d0d53034c83c26f7e8c51fe0740d38fb6743a6109d9e952f
|
data/lib/hoodie.rb
CHANGED
@@ -52,6 +52,23 @@ module Hoodie
|
|
52
52
|
configuration.logging
|
53
53
|
end
|
54
54
|
|
55
|
+
# @param [Symbol] value
|
56
|
+
# Sets the Stash Store.
|
57
|
+
#
|
58
|
+
# @return [Hoodie]
|
59
|
+
#
|
60
|
+
def self.store=(value)
|
61
|
+
configuration.store = value
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [Symbol]
|
66
|
+
# The Stash Store setting.
|
67
|
+
#
|
68
|
+
def self.store
|
69
|
+
configuration.store
|
70
|
+
end
|
71
|
+
|
55
72
|
# Provides access to the global configuration.
|
56
73
|
#
|
57
74
|
# @example
|
data/lib/hoodie/configuration.rb
CHANGED
@@ -30,14 +30,19 @@ module Hoodie
|
|
30
30
|
# @return [Symbol] Set the desired loging level.
|
31
31
|
attr_accessor :level
|
32
32
|
|
33
|
+
# @!attribute [ro] store
|
34
|
+
# @return [Symbol] The current Stash Store.
|
35
|
+
attr_accessor :store
|
36
|
+
|
33
37
|
# Initialized a configuration instance
|
34
38
|
#
|
35
39
|
# @return [undefined]
|
36
40
|
#
|
37
41
|
# @api private
|
38
42
|
def initialize(options={})
|
39
|
-
@logging = options.fetch(:logging,
|
40
|
-
@level = options.fetch(:level,
|
43
|
+
@logging = options.fetch(:logging, false)
|
44
|
+
@level = options.fetch(:level, :info)
|
45
|
+
@store = options.fetch(:store, :memstore)
|
41
46
|
@crypto = Crypto::Configuration.new
|
42
47
|
|
43
48
|
yield self if block_given?
|
@@ -63,7 +68,8 @@ module Hoodie
|
|
63
68
|
# @api private
|
64
69
|
def to_h
|
65
70
|
{ logging: logging,
|
66
|
-
level: level
|
71
|
+
level: level,
|
72
|
+
store: store
|
67
73
|
}.freeze
|
68
74
|
end
|
69
75
|
end
|
File without changes
|
data/lib/hoodie/stash.rb
CHANGED
@@ -17,10 +17,10 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
require_relative 'stash/disk_store'
|
21
|
+
require_relative 'stash/mem_store'
|
22
|
+
require_relative 'stash/cache'
|
23
|
+
require_relative 'utils/os'
|
24
24
|
|
25
25
|
module Hoodie
|
26
26
|
# Define the basic cache and default store objects
|
@@ -42,80 +42,6 @@ module Hoodie
|
|
42
42
|
end
|
43
43
|
|
44
44
|
# Default store type
|
45
|
-
DEFAULT_STORE =
|
46
|
-
|
47
|
-
# Key/value cache store
|
48
|
-
class Cache
|
49
|
-
|
50
|
-
# @!attribute [r] :store
|
51
|
-
# @return [Stash::DiskStore] location of Stash::DiskStore store.
|
52
|
-
attr_reader :store
|
53
|
-
|
54
|
-
# Initializes a new empty store
|
55
|
-
#
|
56
|
-
def initialize(params = {})
|
57
|
-
params = { store: params } unless params.is_a? Hash
|
58
|
-
@store = params.fetch(:store) { Hoodie::DEFAULT_STORE.new }
|
59
|
-
end
|
60
|
-
|
61
|
-
# Clear the whole stash store or the value of a key
|
62
|
-
#
|
63
|
-
# @param key [Symbol, String] (optional) representing the key to
|
64
|
-
# clear.
|
65
|
-
#
|
66
|
-
# @return nothing.
|
67
|
-
#
|
68
|
-
def clear!(key = nil)
|
69
|
-
key = key.to_sym unless key.nil?
|
70
|
-
@store.clear! key
|
71
|
-
end
|
72
|
-
|
73
|
-
# Retrieves the value for a given key, if nothing is set,
|
74
|
-
# returns KeyError
|
75
|
-
#
|
76
|
-
# @param key [Symbol, String] representing the key
|
77
|
-
#
|
78
|
-
# @raise [KeyError] if no such key found
|
79
|
-
#
|
80
|
-
# @return [Hash, Array, String] value for key
|
81
|
-
#
|
82
|
-
def [](key = nil)
|
83
|
-
key ||= Stash.caller_name
|
84
|
-
fail KeyError, 'Key not cached' unless include? key.to_sym
|
85
|
-
@store[key.to_sym]
|
86
|
-
end
|
87
|
-
|
88
|
-
# Retrieves the value for a given key, if nothing is set,
|
89
|
-
# run the code, cache the result, and return it
|
90
|
-
#
|
91
|
-
# @param key [Symbol, String] representing the key
|
92
|
-
# @param block [&block] that returns the value to set (optional)
|
93
|
-
#
|
94
|
-
# @return [Hash, Array, String] value for key
|
95
|
-
#
|
96
|
-
def cache(key = nil, &code)
|
97
|
-
key ||= Stash.caller_name
|
98
|
-
@store[key.to_sym] ||= code.call
|
99
|
-
end
|
100
|
-
|
101
|
-
# return the size of the store as an integer
|
102
|
-
#
|
103
|
-
# @return [Fixnum]
|
104
|
-
#
|
105
|
-
def size
|
106
|
-
@store.size
|
107
|
-
end
|
108
|
-
|
109
|
-
# return a boolean indicating presence of the given key in the store
|
110
|
-
#
|
111
|
-
# @param key [Symbol, String] a string or symbol representing the key
|
112
|
-
#
|
113
|
-
# @return [Boolean]
|
114
|
-
#
|
115
|
-
def include?(key = nil)
|
116
|
-
key ||= Stash.caller_name
|
117
|
-
@store.include? key.to_sym
|
118
|
-
end
|
119
|
-
end
|
45
|
+
DEFAULT_STORE = MemStore.new
|
120
46
|
end
|
121
47
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
4
|
+
# License: Apache License, Version 2.0
|
5
|
+
# Copyright: (C) 2014-2015 Stefano Harding
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
module Hoodie
|
21
|
+
module Stash
|
22
|
+
# Disk stashing method variable caching hash, string, array store.
|
23
|
+
#
|
24
|
+
# Key/value cache store
|
25
|
+
class Cache
|
26
|
+
|
27
|
+
# @!attribute [r] :store
|
28
|
+
# @return [Stash] location of Stash store object.
|
29
|
+
attr_reader :store
|
30
|
+
|
31
|
+
# Initializes a new empty store
|
32
|
+
#
|
33
|
+
def initialize(params = {})
|
34
|
+
params = { store: params } unless params.is_a? Hash
|
35
|
+
@store = params.fetch(:store) { DEFAULT_STORE }
|
36
|
+
end
|
37
|
+
|
38
|
+
# Clear the whole stash store or the value of a key
|
39
|
+
#
|
40
|
+
# @param key [Symbol, String] (optional) representing the key to
|
41
|
+
# clear.
|
42
|
+
#
|
43
|
+
# @return nothing.
|
44
|
+
#
|
45
|
+
def clear!(key = nil)
|
46
|
+
key = key.to_sym unless key.nil?
|
47
|
+
@store.clear! key
|
48
|
+
end
|
49
|
+
|
50
|
+
# Retrieves the value for a given key, if nothing is set,
|
51
|
+
# returns KeyError
|
52
|
+
#
|
53
|
+
# @param key [Symbol, String] representing the key
|
54
|
+
#
|
55
|
+
# @raise [KeyError] if no such key found
|
56
|
+
#
|
57
|
+
# @return [Hash, Array, String] value for key
|
58
|
+
#
|
59
|
+
def [](key = nil)
|
60
|
+
key ||= Stash.caller_name
|
61
|
+
fail KeyError, 'Key not cached' unless include? key.to_sym
|
62
|
+
@store[key.to_sym]
|
63
|
+
end
|
64
|
+
|
65
|
+
# Retrieves the value for a given key, if nothing is set,
|
66
|
+
# run the code, cache the result, and return it
|
67
|
+
#
|
68
|
+
# @param key [Symbol, String] representing the key
|
69
|
+
# @param block [&block] that returns the value to set (optional)
|
70
|
+
#
|
71
|
+
# @return [Hash, Array, String] value for key
|
72
|
+
#
|
73
|
+
def cache(key = nil, &code)
|
74
|
+
key ||= Stash.caller_name
|
75
|
+
@store[key.to_sym] ||= code.call
|
76
|
+
end
|
77
|
+
|
78
|
+
# return the size of the store as an integer
|
79
|
+
#
|
80
|
+
# @return [Fixnum]
|
81
|
+
#
|
82
|
+
def size
|
83
|
+
@store.size
|
84
|
+
end
|
85
|
+
|
86
|
+
# return a boolean indicating presence of the given key in the store
|
87
|
+
#
|
88
|
+
# @param key [Symbol, String] a string or symbol representing the key
|
89
|
+
#
|
90
|
+
# @return [Boolean]
|
91
|
+
#
|
92
|
+
def include?(key = nil)
|
93
|
+
key ||= Stash.caller_name
|
94
|
+
@store.include? key.to_sym
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -20,10 +20,10 @@
|
|
20
20
|
require 'tmpdir'
|
21
21
|
|
22
22
|
module Hoodie
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
class
|
23
|
+
module Stash
|
24
|
+
# Disk stashing method variable caching hash, string, array store.
|
25
|
+
#
|
26
|
+
class DiskStore
|
27
27
|
|
28
28
|
# @!attribute [r] :store
|
29
29
|
# @return [Stash::DiskStore] location of Stash::DiskStore store.
|
@@ -18,136 +18,137 @@
|
|
18
18
|
#
|
19
19
|
|
20
20
|
module Hoodie
|
21
|
-
|
22
|
-
|
23
|
-
class MemStash
|
24
|
-
include Enumerable
|
25
|
-
|
26
|
-
# @!attribute [r] :store
|
27
|
-
# @return [Stash::MemStash] location of Stash::DiskStore store.
|
28
|
-
attr_reader :store
|
29
|
-
|
30
|
-
# Initializes a new store object.
|
31
|
-
#
|
32
|
-
# @param data [Hash] (optional) data to load into the stash.
|
33
|
-
#
|
34
|
-
# @return nothing.
|
21
|
+
module Stash
|
22
|
+
# Basic cache object stash store (uses a Hash)
|
35
23
|
#
|
36
|
-
|
37
|
-
@store = {}
|
38
|
-
end
|
24
|
+
class MemStore
|
39
25
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
# clear.
|
44
|
-
#
|
45
|
-
# @return nothing.
|
46
|
-
#
|
47
|
-
def clear!(key = nil)
|
48
|
-
key.nil? ? @store.clear : @store.delete(key)
|
49
|
-
end
|
26
|
+
# @!attribute [r] :store
|
27
|
+
# @return [Stash::MemStash] location of Stash::DiskStore store.
|
28
|
+
attr_reader :store
|
50
29
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
def [](key)
|
61
|
-
@store[key]
|
62
|
-
end
|
30
|
+
# Initializes a new store object.
|
31
|
+
#
|
32
|
+
# @param data [Hash] (optional) data to load into the stash.
|
33
|
+
#
|
34
|
+
# @return nothing.
|
35
|
+
#
|
36
|
+
def initialize(_ = {})
|
37
|
+
@store = {}
|
38
|
+
end
|
63
39
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
# => "in the hash stash cache store"
|
75
|
-
#
|
76
|
-
# data = { id: 'trig', name: 'Trigster Jay', passwd: 'f00d' }
|
77
|
-
# stash[:juser] = data
|
78
|
-
# => {
|
79
|
-
# :id => "trig",
|
80
|
-
# :name => "Trigster Jay",
|
81
|
-
# :passwd => "f00d"
|
82
|
-
# }
|
83
|
-
#
|
84
|
-
# @param key [Symbol, String] string or symbol representing the key
|
85
|
-
# @param value [Object] any object that represents the value (optional)
|
86
|
-
# @param block [&block] that returns the value to set (optional)
|
87
|
-
#
|
88
|
-
# @return nothing.
|
89
|
-
#
|
90
|
-
def []=(key, value)
|
91
|
-
@store[key] = value
|
92
|
-
end
|
40
|
+
# Clear the whole stash store or the value of a key
|
41
|
+
#
|
42
|
+
# @param key [Symbol, String] (optional) representing the key to
|
43
|
+
# clear.
|
44
|
+
#
|
45
|
+
# @return nothing.
|
46
|
+
#
|
47
|
+
def clear!(key = nil)
|
48
|
+
key.nil? ? @store.clear : @store.delete(key)
|
49
|
+
end
|
93
50
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
@
|
102
|
-
|
51
|
+
# Retrieves the value for a given key, if nothing is set,
|
52
|
+
# returns KeyError
|
53
|
+
#
|
54
|
+
# @param key [Symbol, String] representing the key
|
55
|
+
#
|
56
|
+
# @raise [KeyError] if no such key found
|
57
|
+
#
|
58
|
+
# @return [Hash, Array, String] value for key
|
59
|
+
#
|
60
|
+
def [](key)
|
61
|
+
@store[key]
|
62
|
+
end
|
103
63
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
64
|
+
# Store the given value with the given key, either an an argument
|
65
|
+
# or block. If a previous value was set it will be overwritten
|
66
|
+
# with the new value.
|
67
|
+
#
|
68
|
+
# @example store a value
|
69
|
+
#
|
70
|
+
# stash.set('name') { 'Trigster' }
|
71
|
+
# => "Trigster"
|
72
|
+
#
|
73
|
+
# stash[:cash] = 'in the hash stash cache store'
|
74
|
+
# => "in the hash stash cache store"
|
75
|
+
#
|
76
|
+
# data = { id: 'trig', name: 'Trigster Jay', passwd: 'f00d' }
|
77
|
+
# stash[:juser] = data
|
78
|
+
# => {
|
79
|
+
# :id => "trig",
|
80
|
+
# :name => "Trigster Jay",
|
81
|
+
# :passwd => "f00d"
|
82
|
+
# }
|
83
|
+
#
|
84
|
+
# @param key [Symbol, String] string or symbol representing the key
|
85
|
+
# @param value [Object] any object that represents the value (optional)
|
86
|
+
# @param block [&block] that returns the value to set (optional)
|
87
|
+
#
|
88
|
+
# @return nothing.
|
89
|
+
#
|
90
|
+
def []=(key, value)
|
112
91
|
@store[key] = value
|
113
92
|
end
|
114
|
-
end
|
115
93
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
94
|
+
# Iterates over all key-value pairs.
|
95
|
+
#
|
96
|
+
# @param block [&block] that will receive the key/value of each pair
|
97
|
+
#
|
98
|
+
# @yield the string key and value.
|
99
|
+
#
|
100
|
+
def each(&_block)
|
101
|
+
@store.each { |k, v| yield(k, v) }
|
102
|
+
end
|
123
103
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
104
|
+
# Loads a hash of data into the stash.
|
105
|
+
#
|
106
|
+
# @param hash [Hash] of data with either String or Symbol keys.
|
107
|
+
#
|
108
|
+
# @return nothing.
|
109
|
+
#
|
110
|
+
def load(data)
|
111
|
+
data.each do |key, value|
|
112
|
+
@store[key] = value
|
113
|
+
end
|
114
|
+
end
|
134
115
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
@store.value? value
|
143
|
-
end
|
116
|
+
# return the size of the store as an integer
|
117
|
+
#
|
118
|
+
# @return [Fixnum]
|
119
|
+
#
|
120
|
+
def size
|
121
|
+
@store.size
|
122
|
+
end
|
144
123
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
124
|
+
# return a boolean indicating presence of the given key in the store
|
125
|
+
#
|
126
|
+
# @param key [Symbol, String] a string or symbol representing the key
|
127
|
+
#
|
128
|
+
# @return [Boolean]
|
129
|
+
#
|
130
|
+
def include?(key)
|
131
|
+
@store.include? key
|
132
|
+
end
|
133
|
+
alias_method :key?, :include?
|
134
|
+
|
135
|
+
# return a boolean indicating presence of the given value in the store
|
136
|
+
#
|
137
|
+
# @param value [String] a string representing the value
|
138
|
+
#
|
139
|
+
# @return [Boolean]
|
140
|
+
#
|
141
|
+
def value?(value)
|
142
|
+
@store.value? value
|
143
|
+
end
|
144
|
+
|
145
|
+
# return all keys in the store as an array
|
146
|
+
#
|
147
|
+
# @return [Array<String, Symbol>] all the keys in store
|
148
|
+
#
|
149
|
+
def keys
|
150
|
+
@store.keys
|
151
|
+
end
|
151
152
|
end
|
152
153
|
end
|
153
154
|
end
|
data/lib/hoodie/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoodie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Harding
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -108,10 +108,11 @@ files:
|
|
108
108
|
- lib/hoodie/inflections/inflections.rb
|
109
109
|
- lib/hoodie/inflections/rules_collection.rb
|
110
110
|
- lib/hoodie/logging.rb
|
111
|
+
- lib/hoodie/memoizable.rb
|
111
112
|
- lib/hoodie/stash.rb
|
113
|
+
- lib/hoodie/stash/cache.rb
|
112
114
|
- lib/hoodie/stash/disk_store.rb
|
113
115
|
- lib/hoodie/stash/mem_store.rb
|
114
|
-
- lib/hoodie/stash/memoizable.rb
|
115
116
|
- lib/hoodie/utils.rb
|
116
117
|
- lib/hoodie/utils/ansi.rb
|
117
118
|
- lib/hoodie/utils/crypto.rb
|