couchbase_model_logging 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'couchbase', "~> 1.1.2"
4
+
5
+ group :development do
6
+ gem "minitest"
7
+ gem "minitest-reporters", ">= 0.5.0"
8
+ gem "rdoc", "~> 3.12"
9
+ gem "bundler"
10
+ gem "jeweler", "~> 1.8.3"
11
+ gem "simplecov"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ ansi (1.4.3)
5
+ builder (3.0.0)
6
+ couchbase (1.1.2)
7
+ yajl-ruby (~> 1.1.0)
8
+ git (1.2.5)
9
+ hashie (1.2.0)
10
+ jeweler (1.8.4)
11
+ bundler (~> 1.0)
12
+ git (>= 1.2.5)
13
+ rake
14
+ rdoc
15
+ json (1.7.3)
16
+ minitest (3.2.0)
17
+ minitest-reporters (0.9.0)
18
+ ansi
19
+ builder
20
+ minitest (>= 2.0, < 4.0)
21
+ powerbar
22
+ multi_json (1.3.6)
23
+ powerbar (1.0.7)
24
+ ansi (~> 1.4.0)
25
+ hashie (>= 1.1.0)
26
+ rake (0.9.2.2)
27
+ rdoc (3.12)
28
+ json (~> 1.4)
29
+ simplecov (0.6.4)
30
+ multi_json (~> 1.0)
31
+ simplecov-html (~> 0.5.3)
32
+ simplecov-html (0.5.3)
33
+ yajl-ruby (1.1.0)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bundler
40
+ couchbase (~> 1.1.2)
41
+ jeweler (~> 1.8.3)
42
+ minitest
43
+ minitest-reporters (>= 0.5.0)
44
+ rdoc (~> 3.12)
45
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Adrian Madrid
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = couchbase_model_logging
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to couchbase_model_logging
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Adrian Madrid. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "couchbase_model_logging"
18
+ gem.homepage = "http://github.com/aemadrid/couchbase_model_logging"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Simple model logging into Couchbase}
21
+ gem.description = %Q{ditto}
22
+ gem.email = "aemadrid@gmail.com"
23
+ gem.authors = ["Adrian Madrid"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:spec) do |test|
30
+ test.libs << 'lib' << 'spec'
31
+ test.pattern = 'spec/**/*_spec.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ =begin
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'spec'
39
+ test.pattern = 'spec/**/*_spec.rb'
40
+ test.verbose = true
41
+ test.rcov_opts << '--exclude "gems/*"'
42
+ end
43
+ =end
44
+
45
+ task :default => :spec
46
+
47
+ require 'rdoc/task'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "couchbase_model_logging #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "couchbase_model_logging"
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Adrian Madrid"]
12
+ s.date = "2012-07-22"
13
+ s.description = "ditto"
14
+ s.email = "aemadrid@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "couchbase_model_logging.gemspec",
28
+ "lib/couchbase_model_logging.rb",
29
+ "lib/couchbase_model_logging/client.rb",
30
+ "lib/couchbase_model_logging/exceptions.rb",
31
+ "lib/couchbase_model_logging/logger.rb",
32
+ "spec/couchbase_model_logging_spec.rb",
33
+ "spec/helper.rb"
34
+ ]
35
+ s.homepage = "http://github.com/aemadrid/couchbase_model_logging"
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = "1.8.15"
39
+ s.summary = "Simple model logging into Couchbase"
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<couchbase>, ["~> 1.1.2"])
46
+ s.add_development_dependency(%q<minitest>, [">= 0"])
47
+ s.add_development_dependency(%q<minitest-reporters>, [">= 0.5.0"])
48
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
49
+ s.add_development_dependency(%q<bundler>, [">= 0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
51
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<couchbase>, ["~> 1.1.2"])
54
+ s.add_dependency(%q<minitest>, [">= 0"])
55
+ s.add_dependency(%q<minitest-reporters>, [">= 0.5.0"])
56
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
57
+ s.add_dependency(%q<bundler>, [">= 0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
59
+ s.add_dependency(%q<simplecov>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<couchbase>, ["~> 1.1.2"])
63
+ s.add_dependency(%q<minitest>, [">= 0"])
64
+ s.add_dependency(%q<minitest-reporters>, [">= 0.5.0"])
65
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
66
+ s.add_dependency(%q<bundler>, [">= 0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
68
+ s.add_dependency(%q<simplecov>, [">= 0"])
69
+ end
70
+ end
71
+
@@ -0,0 +1,47 @@
1
+ require 'couchbase'
2
+
3
+ module CouchbaseModelLogging
4
+
5
+ class Client
6
+
7
+ attr_accessor :host, :port, :pool, :bucket, :protocol
8
+
9
+ def initialize(options = { })
10
+ self.protocol = options[:protocol] || 'http'
11
+ self.host = options[:host] || 'localhost'
12
+ self.port = options[:port] || 8091
13
+ self.pool = options[:pool] || 'default'
14
+ self.bucket = options[:bucket] || 'default'
15
+ end
16
+
17
+ def url
18
+ "#{protocol}://#{host}:#{port}/pools/#{pool}/buckets/#{bucket}"
19
+ end
20
+
21
+ def native_client
22
+ @native_client ||= ::Couchbase.connect url
23
+ end
24
+
25
+ def respond_to?(meth)
26
+ native_client.respond_to?(meth) || super
27
+ end
28
+
29
+ def method_missing(meth, *args, &blk)
30
+ if native_client.respond_to? meth
31
+ call_info = caller[0] =~ /\/([\w\.]+):(\d+):in `(\w+)'/ ? "#{$1}:#{$2} #{$3}" : "unknown"
32
+ #puts "mm : #{meth} : #{args.inspect} | from #{call_info}"
33
+ native_client.send meth, *args, &blk
34
+ else
35
+ super
36
+ end
37
+ end
38
+
39
+ alias_method :decorator_methods, :methods
40
+
41
+ def methods
42
+ (decorator_methods + native_client.methods).uniq
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,6 @@
1
+ module CouchbaseModelLogging
2
+
3
+ class ReplacementError < StandardError
4
+ end
5
+
6
+ end
@@ -0,0 +1,54 @@
1
+ require 'yaml'
2
+
3
+ module CouchbaseModelLogging
4
+
5
+ class Logger
6
+
7
+ attr_accessor :client, :prefix, :separator
8
+
9
+ def initialize(client, prefix = nil, options = { })
10
+ self.client = client
11
+ self.prefix = prefix
12
+ self.separator = options[:separator] || '[SEP]'
13
+ end
14
+
15
+ def key?(key)
16
+ !get(key).nil?
17
+ end
18
+
19
+ def encode(hash)
20
+ yaml = hash.to_yaml
21
+ raise CouchbaseModelLogging::ReplacementError, "Found separator [#{separator}] in YAML string" if yaml.index(separator)
22
+ yaml + separator
23
+ end
24
+
25
+ def add(key, hash = { })
26
+ yaml = encode hash
27
+ pref_key = prefixed_key_for key
28
+ begin
29
+ client.append pref_key, yaml, :format => :plain
30
+ rescue ::Couchbase::Error::NotStored
31
+ client.add pref_key, yaml, :format => :plain
32
+ end
33
+ end
34
+
35
+ def get(key)
36
+ client.get(prefixed_key_for(key), :format => :plain)
37
+ end
38
+
39
+ def decode(str)
40
+ return [] if str.nil? || str.empty?
41
+ str.split(separator).map { |yaml| YAML.load yaml }
42
+ end
43
+
44
+ def all(key)
45
+ decode get(key)
46
+ end
47
+
48
+ def prefixed_key_for(key)
49
+ prefix.nil? ? key.to_s : "#{prefix}::#{key}"
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,7 @@
1
+ libdir = File.dirname(__FILE__)
2
+ full_libdir = File.expand_path(libdir)
3
+ $LOAD_PATH.unshift(full_libdir) unless $LOAD_PATH.include?(libdir) || $LOAD_PATH.include?(full_libdir)
4
+
5
+ require 'couchbase_model_logging/exceptions'
6
+ require 'couchbase_model_logging/client'
7
+ require 'couchbase_model_logging/logger'
@@ -0,0 +1,61 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+
3
+ describe 'CouchbaseModelLogging' do
4
+
5
+ let(:bucket) { ENV["TEST_CML_BUCKET"] || "default" }
6
+ let(:client) { CouchbaseModelLogging::Client.new :bucket => bucket }
7
+
8
+ describe 'Client' do
9
+ it { client.url.must_equal "http://localhost:8091/pools/default/buckets/#{bucket}" }
10
+ it { client.native_client.class.name.must_equal "Couchbase::Bucket" }
11
+ end
12
+
13
+ describe 'Logger' do
14
+
15
+ let(:prefix) { "test_cml" }
16
+
17
+ subject { CouchbaseModelLogging::Logger.new client, prefix }
18
+
19
+ it "should add one entry correctly" do
20
+ key = "t1"
21
+ hsh = { :a => 1, :b => 2 }
22
+ client.delete subject.prefixed_key_for(key)
23
+
24
+ subject.add key, hsh
25
+ subject.key?(key).must_equal true
26
+
27
+ encoded = subject.get key
28
+ encoded.must_equal subject.encode(hsh)
29
+
30
+ decoded = subject.decode encoded
31
+ decoded.must_equal [hsh]
32
+
33
+ ary = subject.all key
34
+ ary.size.must_equal 1
35
+ ary[0].must_equal hsh
36
+ end
37
+
38
+ it "should add several entries correctly" do
39
+ key = "t2"
40
+ client.delete subject.prefixed_key_for(key)
41
+
42
+ subject.add key, :a => 1, :b => 2
43
+ subject.add key, :b => 2, :c => 3
44
+ subject.add key, :c => 3, :d => 4
45
+
46
+ subject.key?(key).must_equal true
47
+
48
+ ary = subject.all key
49
+ ary.size.must_equal 3
50
+ ary[0].must_equal :a => 1, :b => 2
51
+ ary[1].must_equal :b => 2, :c => 3
52
+ ary[2].must_equal :c => 3, :d => 4
53
+ end
54
+
55
+ it "should get an empty response when missing" do
56
+ key = "missing_key"
57
+ subject.all(key).must_equal []
58
+ end
59
+
60
+ end
61
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ unless Object.const_defined?(:SPEC_HELPER_LOADED)
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require 'minitest/autorun'
12
+
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
+ require 'couchbase_model_logging'
16
+
17
+ Object.const_set :SPEC_HELPER_LOADED, true
18
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: couchbase_model_logging
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adrian Madrid
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: couchbase
16
+ requirement: &70164419550260 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70164419550260
25
+ - !ruby/object:Gem::Dependency
26
+ name: minitest
27
+ requirement: &70164419549680 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70164419549680
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest-reporters
38
+ requirement: &70164419549040 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 0.5.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70164419549040
47
+ - !ruby/object:Gem::Dependency
48
+ name: rdoc
49
+ requirement: &70164419548440 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70164419548440
58
+ - !ruby/object:Gem::Dependency
59
+ name: bundler
60
+ requirement: &70164419547760 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70164419547760
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: &70164419546700 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.8.3
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70164419546700
80
+ - !ruby/object:Gem::Dependency
81
+ name: simplecov
82
+ requirement: &70164419545480 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70164419545480
91
+ description: ditto
92
+ email: aemadrid@gmail.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files:
96
+ - LICENSE.txt
97
+ - README.rdoc
98
+ files:
99
+ - .document
100
+ - Gemfile
101
+ - Gemfile.lock
102
+ - LICENSE.txt
103
+ - README.rdoc
104
+ - Rakefile
105
+ - VERSION
106
+ - couchbase_model_logging.gemspec
107
+ - lib/couchbase_model_logging.rb
108
+ - lib/couchbase_model_logging/client.rb
109
+ - lib/couchbase_model_logging/exceptions.rb
110
+ - lib/couchbase_model_logging/logger.rb
111
+ - spec/couchbase_model_logging_spec.rb
112
+ - spec/helper.rb
113
+ homepage: http://github.com/aemadrid/couchbase_model_logging
114
+ licenses:
115
+ - MIT
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ segments:
127
+ - 0
128
+ hash: -4477326598625326586
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 1.8.15
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Simple model logging into Couchbase
141
+ test_files: []