content_caching 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f76b31f135b71b97dae7f0b560366afd49d65fe
4
- data.tar.gz: 47b2f2a7756927158656355120605006ad701f1b
3
+ metadata.gz: e0b99af4b7bbf5dec7d6c5fa999226cfcb6ad860
4
+ data.tar.gz: 24cba441648f98ba6f64ec6cfbc8a7ebeb68fb29
5
5
  SHA512:
6
- metadata.gz: f49f744dad7212723fd9f42451824ef08e19edbf5ee17b8df29784d998709562322cb923f93cc201fea5e16d32a3b8adc2fcd3bb52fae87fcd8aff090eece266
7
- data.tar.gz: d9a7187010d2d3d420b18f58ff0001f6c35f8fe68befeead4507ae4b8fbd8c2f7bb4e3c865e202e4510f58b9a00ebebf11c05e083d3a375cd2585c76ff161e4a
6
+ metadata.gz: 3c06a7fdf04c7fcb5f4cdfec0b437ee9c444db9d6f1585fa350116c543267d88ce65d6cd65bf891e5e515d72872834049a3d0b06eeda6c6461cc42a16277e369
7
+ data.tar.gz: 5e72d78eef4c344910b62aa019ae3dd7f43704f976a15423cb19fda681c62d9116b0b962b611083ab5355b7c5407acbd04bdd3345129df4308e5d813529f0688
data/.gitignore CHANGED
@@ -20,3 +20,5 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+
24
+ spec/setting.yml
data/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ### VERSION 0.1.0
2
+
3
+ * bug fix
4
+ *
5
+
6
+ * refactoring
7
+ *
8
+
9
+ * enhancements
10
+ *
11
+
12
+ * backwards incompatible changes
13
+ * signature of wrapper have been change
14
+
15
+ * deprecations
16
+ *
17
+
18
+ * todos
19
+ *
20
+
1
21
  ### VERSION 0.0.1
2
22
 
3
23
  * bug fix
data/Gemfile CHANGED
@@ -5,4 +5,5 @@ gemspec
5
5
 
6
6
  group :test do
7
7
  gem 'pry'
8
+ gem 'configatron'
8
9
  end
data/README.md CHANGED
@@ -10,19 +10,89 @@
10
10
 
11
11
  Add this line to your application's Gemfile:
12
12
 
13
+ ```
13
14
  gem 'content_caching'
15
+ ```
14
16
 
15
17
  And then execute:
16
18
 
19
+ ```
17
20
  $ bundle
21
+ ```
18
22
 
19
23
  Or install it yourself as:
20
24
 
25
+ ```
21
26
  $ gem install content_caching
27
+ ```
22
28
 
23
29
  ## Usage
24
30
 
25
- TODO: Write usage instructions here
31
+ You can configure content_caching for playing with local storage or aws s3
32
+
33
+ By befault content_caching provide filesystem configuration like that
34
+
35
+ ```
36
+ { adapter: :fs, options: { directory: 'tmp' }}
37
+ ```
38
+
39
+ is pretty basic, but you can change these configuration
40
+
41
+ fs sample
42
+
43
+ ```
44
+ ContentCaching.configure do |config|
45
+ config.adapter = { adapter: :fs, options: { directory: 'public/htmls' }}
46
+ end
47
+ ```
48
+
49
+ AWS s3 sample
50
+
51
+ ```
52
+ ContentCaching.configure do |config|
53
+ config.adapter = { adapter: :aws,
54
+ options: { directory: directory, aws_access_key_id: api_key_id,
55
+ aws_secret_access_key: api_key_access }}
56
+ end
57
+ ```
58
+
59
+ for s3 you need provide extra information, bucket name, api key and secret
60
+
61
+ ContentCaching implement the following interface
62
+
63
+ ```
64
+ Query
65
+ .url()
66
+
67
+ Command
68
+ .store()
69
+ .delete()
70
+ ```
71
+
72
+ When you initialize an Document you need pass an object who respond to .to_path() contract. content_caching provide an Wrapper for help you.
73
+
74
+ ```
75
+ wrapper = ContentCaching::Wrapper.new('path of your document')
76
+ content_caching = ContentCaching::Document.new(wrapper)
77
+ ```
78
+
79
+ You can store any content when you pass an Object respond to .read() contract to method .store()
80
+
81
+ ```
82
+ content_caching.store StringIO.new('foo')
83
+ ```
84
+
85
+ You can ask for full path
86
+
87
+ ```
88
+ content_caching.url
89
+ ```
90
+
91
+ And you can delete file
92
+
93
+ ```
94
+ content_caching.delete
95
+ ```
26
96
 
27
97
  ## Contributing
28
98
 
@@ -15,7 +15,8 @@ module ContentCaching
15
15
  def store document_path, content
16
16
  retry_3_times do
17
17
  content.rewind if content.respond_to?(:rewind)
18
- s3_interface.put self.options[:directory], document_path, content.read
18
+ s3_interface.put self.options[:directory], document_path,
19
+ (content.respond_to?(:read) ? content.read : content)
19
20
  end
20
21
  end
21
22
 
@@ -25,10 +25,6 @@ module ContentCaching
25
25
 
26
26
  private
27
27
 
28
- def document_path
29
- @wrapper.document_path
30
- end
31
-
32
28
  def adapter
33
29
  @adapter ||= Aws::new(@options)
34
30
  end
@@ -2,16 +2,17 @@ module ContentCaching
2
2
  module Adapter
3
3
  class Fs
4
4
 
5
- def store document_path, document_name, content
6
- Pathname(url(document_path, document_name)).write content.read
5
+ def store document_path, content
6
+ content.rewind if content.respond_to?(:rewind)
7
+ Pathname(url(document_path)).write content.respond_to?(:read) ? content.read : content
7
8
  end
8
9
 
9
- def url document_path, document_name
10
- "#{document_path}/#{document_name}"
10
+ def url document_url
11
+ document_url
11
12
  end
12
13
 
13
- def delete document_path, document_name
14
- Pathname(url(document_path, document_name)).delete
14
+ def delete document_path
15
+ Pathname(url(document_path)).delete
15
16
  end
16
17
 
17
18
  end
@@ -12,22 +12,26 @@ module ContentCaching
12
12
  end
13
13
 
14
14
  def url
15
- adapter.url document_path, document_name
15
+ adapter.url document_url
16
16
  end
17
17
 
18
18
  def store content
19
- adapter.store document_path, document_name, content
19
+ adapter.store document_path, content
20
20
  end
21
21
 
22
22
  def delete
23
- adapter.delete document_path, document_name
23
+ adapter.delete document_path
24
24
  end
25
25
 
26
26
  private
27
27
 
28
+ def document_url
29
+ @options[:host] + '/' + Pathname(@wrapper.to_path).cleanpath.to_path
30
+ end
31
+
28
32
  def document_path
29
- return @wrapper.document_path unless @options[:directory]
30
- Pathname([@options[:directory], @wrapper.document_path].join('/')).cleanpath.to_path
33
+ return @wrapper.to_path unless @options[:directory]
34
+ Pathname([@options[:directory], @wrapper.to_path].join('/')).cleanpath.to_path
31
35
  end
32
36
 
33
37
  def adapter
@@ -16,13 +16,8 @@ module ContentCaching
16
16
 
17
17
  private
18
18
 
19
- def document_name
20
- @wrapper.document_name
21
- end
22
-
23
19
  def document_path
24
- return @wrapper.document_path unless @options[:directory]
25
- Pathname([@options[:directory], @wrapper.document_path].join('/')).cleanpath.to_path
20
+ @wrapper.to_path
26
21
  end
27
22
 
28
23
  end
@@ -3,7 +3,7 @@ module ContentCaching
3
3
  attr_accessor :adapter
4
4
 
5
5
  def initialize
6
- @adapter = { adapter: :fs, options: { directory: 'tmp' }}
6
+ @adapter = { adapter: :fs, options: { host: 'http://0.0.0.0:3000', directory: 'tmp' }}
7
7
  end
8
8
  end
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module ContentCaching
2
- VERSION = "0.0.1"
2
+ VERSION = '0.1.0'
3
3
  end
@@ -0,0 +1,7 @@
1
+ module ContentCaching
2
+ class Wrapper < Struct.new(:path)
3
+ def to_path
4
+ self.path
5
+ end
6
+ end
7
+ end
@@ -1,5 +1,6 @@
1
1
  require_relative 'content_caching/version'
2
2
  require_relative 'content_caching/configuration'
3
+ require_relative 'content_caching/wrapper'
3
4
  require_relative 'content_caching/adapters/base'
4
5
 
5
6
  begin
@@ -5,7 +5,7 @@ module ContentCaching
5
5
  let(:configuration) { Configuration.new }
6
6
 
7
7
  describe '#adapter' do
8
- let(:adapter) {{ adapter: :fs, options: { directory: 'tmp' }}}
8
+ let(:adapter) {{ adapter: :fs, options: { host: 'http://0.0.0.0:3000', directory: 'tmp' }}}
9
9
  it 'the default is fs' do
10
10
  expect(configuration.adapter).to eq(adapter)
11
11
  end
@@ -1,33 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  require 'pathname'
4
+ # require 'configatron'
4
5
 
5
6
  module ContentCaching
6
7
  describe Document do
8
+ let(:wrapper) { Wrapper.new(path) }
9
+ let(:content_caching) { Document.new(wrapper) }
7
10
 
8
11
  context 'fs' do
9
- let(:wrapper) { OpenStruct.new(options) }
10
- let(:content_caching) { Document.new(wrapper) }
11
-
12
- context 'options' do
13
-
14
- context 'without document path' do
15
- let(:options) {{ document_name: 'page.html', document_path: nil }}
16
- specify do
17
- expect(content_caching.url).to eq('tmp/page.html')
18
- end
19
- end
20
-
21
- context 'with document path' do
22
- let(:options) {{ document_name: 'page.html', document_path: 'pages' }}
23
- specify do
24
- expect(content_caching.url).to eq('tmp/pages/page.html')
25
- end
12
+ context 'without document path' do
13
+ let(:path) { 'page.html' }
14
+ specify do
15
+ expect(content_caching.url).to eq('http://0.0.0.0:3000/page.html')
26
16
  end
27
17
  end
28
18
 
29
19
  describe '#store' do
30
- let(:options) {{ document_name: 'page.html', document_path: 'public/pages' }}
20
+ let(:path) { 'public/pages/page.html' }
31
21
 
32
22
  before do
33
23
  content_caching.store Pathname('spec/fixtures/page.html')
@@ -47,15 +37,16 @@ module ContentCaching
47
37
  end
48
38
 
49
39
  context 'aws', pending: true do
50
- let(:wrapper) { OpenStruct.new(options) }
51
- let(:options) {{ document_name: nil, document_path: 'test/page.html' }}
52
- let(:content_caching) { Document.new(wrapper) }
40
+ let(:path) { 'test/page.html' }
53
41
  let(:adapter) do
54
42
  { adapter: :aws,
55
- options: { directory: 'bucket-name', aws_access_key_id: 'aws_access_key_id',
56
- aws_secret_access_key: 'aws_secret_access_key' }
43
+ options: { directory: directory, aws_access_key_id: api_key_id,
44
+ aws_secret_access_key: api_key_access }
57
45
  }
58
46
  end
47
+ let(:directory) { configatron.directory }
48
+ let(:api_key_id) { configatron.api_key_id }
49
+ let(:api_key_access) { configatron.api_key_access }
59
50
 
60
51
  before do
61
52
  ContentCaching.configure do |config|
@@ -65,7 +56,7 @@ module ContentCaching
65
56
 
66
57
  describe '#url' do
67
58
 
68
- let(:url) { 'https://bucket-name.s3.amazonaws.com:443/test/page.html' }
59
+ let(:url) { "https://#{directory}.s3.amazonaws.com:443/test/page.html" }
69
60
 
70
61
  specify do
71
62
  expect(content_caching.url).to match(url)
@@ -89,7 +80,7 @@ module ContentCaching
89
80
 
90
81
  specify do
91
82
  expect(
92
- Aws::S3::Key.new(bucket, options[:document_path])
83
+ Aws::S3::Key.new(bucket, path)
93
84
  ).to be_exists
94
85
  end
95
86
 
@@ -97,7 +88,7 @@ module ContentCaching
97
88
  before do content_caching.delete end
98
89
  specify do
99
90
  expect(
100
- Aws::S3::Key.new(bucket, options[:document_path])
91
+ Aws::S3::Key.new(bucket, path)
101
92
  ).to_not be_exists
102
93
  end
103
94
  end
data/spec/spec_helper.rb CHANGED
@@ -18,6 +18,17 @@ end
18
18
 
19
19
  require_relative '../lib/content_caching'
20
20
 
21
+ require 'configatron'
22
+
23
+ if File.exist?('spec/setting.yml')
24
+ require 'yaml'
25
+ configatron.configure_from_hash(YAML.load_file('spec/setting.yml'))
26
+ else
27
+ configatron.directory = 'bucket-name'
28
+ configatron.api_key_id = 'api_key_id'
29
+ configatron.api_key_access = 'api_key_access'
30
+ end
31
+
21
32
  RSpec.configure do |config|
22
33
  config.filter_run focused: true
23
34
  config.run_all_when_everything_filtered = true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: content_caching
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel AZEMAR
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-22 00:00:00.000000000 Z
11
+ date: 2014-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -138,6 +138,7 @@ files:
138
138
  - lib/content_caching/adapters/implementation.rb
139
139
  - lib/content_caching/configuration.rb
140
140
  - lib/content_caching/version.rb
141
+ - lib/content_caching/wrapper.rb
141
142
  - spec/content_caching/adapters/fs_adapter_spec.rb
142
143
  - spec/content_caching/configuration_spec.rb
143
144
  - spec/content_caching_spec.rb