yakiniku 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +10 -0
- data/lib/yakiniku.rb +47 -0
- data/lib/yakiniku/data_store.rb +34 -0
- data/lib/yakiniku/version.rb +3 -0
- data/spec/data_store_spec.rb +38 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/yakiniku_spec.rb +51 -0
- data/yakiniku.gemspec +33 -0
- metadata +215 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b74dd36df1ee0791601cf423171835425ba618d4
|
4
|
+
data.tar.gz: e46ea515dc18738e6ec1e8d1b923f392ec123a00
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5c766bc90df54cecdc109d02d5fb4e546865f69149f2329dec01120dacd4a02c171d9f5988998ddda0e40398eac58a0edca8d05c4c30744de8792fa93b03141c
|
7
|
+
data.tar.gz: 65db3950be6e70cfdedd123705c31c4289820ea3dbd92ecd5433af60b9bd1501a27ee9aaa33b9709bc41cdbcf5495a09622a08dacedef3d8246f0bac01fb1bfa
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 rex
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Yakiniku
|
2
|
+
|
3
|
+
Yakiniku
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'yakiniku'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install yakiniku
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/rx007/yakiniku/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
# Default directory to look in is `/specs`
|
5
|
+
# Run with `rake spec`
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
7
|
+
task.rspec_opts = ['--color', '--format', 'documentation']
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :spec
|
data/lib/yakiniku.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'yakiniku/version'
|
2
|
+
require 'yakiniku/data_store'
|
3
|
+
require 'crimp'
|
4
|
+
|
5
|
+
module Yakiniku
|
6
|
+
def self.transforms(data, till_midnight = 60)
|
7
|
+
identifier = Crimp.signature(data)
|
8
|
+
cloned_data = deep_copy data
|
9
|
+
transformed = yield cloned_data
|
10
|
+
|
11
|
+
store({
|
12
|
+
:id => identifier,
|
13
|
+
:original => data,
|
14
|
+
:transformed => transformed
|
15
|
+
})
|
16
|
+
|
17
|
+
check(identifier, till_midnight)
|
18
|
+
|
19
|
+
identifier
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.get(id)
|
23
|
+
DataStore.instance.get(id)[:transformed]
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.midnight(id)
|
27
|
+
reset_data_at(id)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def self.store(data)
|
33
|
+
DataStore.instance.set(data)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.deep_copy(object)
|
37
|
+
Marshal.load(Marshal.dump(object))
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.check(id, seconds)
|
41
|
+
Thread.new { sleep seconds; reset_data_at id }
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.reset_data_at(id)
|
45
|
+
DataStore.instance.reset(id)
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
class DataStore
|
4
|
+
include Singleton
|
5
|
+
|
6
|
+
def set(data)
|
7
|
+
hash_data = {
|
8
|
+
:original => data[:original],
|
9
|
+
:transformed => data[:transformed]
|
10
|
+
}
|
11
|
+
|
12
|
+
container.store(data[:id], hash_data)
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(id)
|
16
|
+
container.fetch(id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def reset(id)
|
20
|
+
original = container.fetch(id)[:original]
|
21
|
+
hash_data = {
|
22
|
+
:original => original,
|
23
|
+
:transformed => original
|
24
|
+
}
|
25
|
+
|
26
|
+
container.store(id, hash_data)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def container
|
32
|
+
@store ||= Hash.new
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DataStore do
|
4
|
+
let(:instance) { DataStore.instance }
|
5
|
+
let(:original) { 'bar' }
|
6
|
+
let(:transformed) { 'BAR' }
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
instance.set({
|
10
|
+
:id => 'foo',
|
11
|
+
:original => original,
|
12
|
+
:transformed => transformed
|
13
|
+
})
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'set(data)' do
|
17
|
+
it 'stores original and transformed data' do
|
18
|
+
expect(instance.get('foo')[:original]).to eq(original)
|
19
|
+
expect(instance.get('foo')[:transformed]).to eq(transformed)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'get(id)' do
|
24
|
+
it 'returns data object' do
|
25
|
+
expect(instance.get('foo')).to be_a Hash
|
26
|
+
expect(instance.get('foo').key?(:original)).to be true
|
27
|
+
expect(instance.get('foo').key?(:transformed)).to be true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'reset(id)' do
|
32
|
+
it 'replaces the transformed data with original data' do
|
33
|
+
instance.reset('foo')
|
34
|
+
foo = instance.get('foo')
|
35
|
+
expect(foo[:original]).to eq(foo[:transformed])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yakiniku do
|
4
|
+
let(:data) {{ :key => 'value' }}
|
5
|
+
let(:till_midnight) { 0 }
|
6
|
+
|
7
|
+
def create_new_instance
|
8
|
+
@id = subject.transforms(data, till_midnight) do |data|
|
9
|
+
data.each do |key, value|
|
10
|
+
data.tap { |d| d[key].upcase! }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.transforms(data, till_midnight)' do
|
16
|
+
it 'returns a md5 hash of the provided data' do
|
17
|
+
create_new_instance
|
18
|
+
expect(@id).to be_a String
|
19
|
+
expect(@id).to eq '24e73d3a4f027ff81ed4f32c8a9b8713'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.get(id)' do
|
24
|
+
context 'before midnight (before time expired)' do
|
25
|
+
it 'returns the transformed data' do
|
26
|
+
Yakiniku.stub(:check)
|
27
|
+
create_new_instance
|
28
|
+
expect(subject.get(@id)).to eq({ :key => 'VALUE' })
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'past midnight (after time expired)' do
|
33
|
+
it 'returns the original data' do
|
34
|
+
create_new_instance
|
35
|
+
Yakiniku.reset_data_at @id
|
36
|
+
expect(subject.get(@id)).to eq({ :key => 'value' })
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '.midnight(id)' do
|
42
|
+
context 'before midnight (before time expired)' do
|
43
|
+
it 'restores the data to its original state' do
|
44
|
+
Yakiniku.stub(:check)
|
45
|
+
create_new_instance
|
46
|
+
subject.midnight(@id)
|
47
|
+
expect(subject.get(@id)).to eq({ :key => 'value' })
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/yakiniku.gemspec
ADDED
@@ -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 'yakiniku/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "yakiniku"
|
8
|
+
spec.version = Yakiniku::VERSION
|
9
|
+
spec.authors = ["rex"]
|
10
|
+
spec.email = ["rx007@me.com"]
|
11
|
+
spec.summary = "Yakiniku"
|
12
|
+
spec.description = "Shows yakiniku"
|
13
|
+
spec.homepage = "https://github.com/rx007/yakiniku"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "rspec-nc"
|
25
|
+
spec.add_development_dependency "guard"
|
26
|
+
spec.add_development_dependency "guard-rspec"
|
27
|
+
spec.add_development_dependency "pry"
|
28
|
+
spec.add_development_dependency "pry-remote"
|
29
|
+
spec.add_development_dependency "pry-nav"
|
30
|
+
spec.add_development_dependency "coveralls"
|
31
|
+
|
32
|
+
spec.add_runtime_dependency "crimp"
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yakiniku
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- rex
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-23 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: rake
|
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: rspec
|
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-nc
|
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: guard
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-remote
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry-nav
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: coveralls
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: crimp
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description: Shows yakiniku
|
168
|
+
email:
|
169
|
+
- rx007@me.com
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- ".coveralls.yml"
|
175
|
+
- ".travis.yml"
|
176
|
+
- Gemfile
|
177
|
+
- Guardfile
|
178
|
+
- LICENSE.txt
|
179
|
+
- README.md
|
180
|
+
- Rakefile
|
181
|
+
- lib/yakiniku.rb
|
182
|
+
- lib/yakiniku/data_store.rb
|
183
|
+
- lib/yakiniku/version.rb
|
184
|
+
- spec/data_store_spec.rb
|
185
|
+
- spec/spec_helper.rb
|
186
|
+
- spec/yakiniku_spec.rb
|
187
|
+
- yakiniku.gemspec
|
188
|
+
homepage: https://github.com/rx007/yakiniku
|
189
|
+
licenses:
|
190
|
+
- MIT
|
191
|
+
metadata: {}
|
192
|
+
post_install_message:
|
193
|
+
rdoc_options: []
|
194
|
+
require_paths:
|
195
|
+
- lib
|
196
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - ">="
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: '0'
|
201
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
|
+
requirements:
|
203
|
+
- - ">="
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '0'
|
206
|
+
requirements: []
|
207
|
+
rubyforge_project:
|
208
|
+
rubygems_version: 2.2.2
|
209
|
+
signing_key:
|
210
|
+
specification_version: 4
|
211
|
+
summary: Yakiniku
|
212
|
+
test_files:
|
213
|
+
- spec/data_store_spec.rb
|
214
|
+
- spec/spec_helper.rb
|
215
|
+
- spec/yakiniku_spec.rb
|