journal 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.bundle/config ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ BUNDLE_PATH: bundler
3
+ BUNDLE_DISABLE_SHARED_GEMS: '1'
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ bundler/*
2
+ *.gem
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.9.3-p125@journal --create
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ # gem "mocha"
6
+ gem "rake"
7
+ gem "rspec"
8
+ gem 'active_support'
9
+ gem 'redis'
10
+
11
+
12
+ group :development do
13
+ gem "ruby-debug", :platforms => :mri_18
14
+ gem "ruby-debug19", :platforms => :mri_19
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ journal (0.0.2)
5
+ redis
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ active_support (3.0.0)
11
+ activesupport (= 3.0.0)
12
+ activesupport (3.0.0)
13
+ archive-tar-minitar (0.5.2)
14
+ columnize (0.3.6)
15
+ diff-lcs (1.1.3)
16
+ linecache (0.46)
17
+ rbx-require-relative (> 0.0.4)
18
+ linecache19 (0.5.12)
19
+ ruby_core_source (>= 0.1.4)
20
+ rake (0.9.2.2)
21
+ rbx-require-relative (0.0.9)
22
+ redis (2.2.2)
23
+ rspec (2.10.0)
24
+ rspec-core (~> 2.10.0)
25
+ rspec-expectations (~> 2.10.0)
26
+ rspec-mocks (~> 2.10.0)
27
+ rspec-core (2.10.0)
28
+ rspec-expectations (2.10.0)
29
+ diff-lcs (~> 1.1.3)
30
+ rspec-mocks (2.10.1)
31
+ ruby-debug (0.10.4)
32
+ columnize (>= 0.1)
33
+ ruby-debug-base (~> 0.10.4.0)
34
+ ruby-debug-base (0.10.4)
35
+ linecache (>= 0.3)
36
+ ruby-debug-base19 (0.11.25)
37
+ columnize (>= 0.3.1)
38
+ linecache19 (>= 0.5.11)
39
+ ruby_core_source (>= 0.1.4)
40
+ ruby-debug19 (0.11.6)
41
+ columnize (>= 0.3.1)
42
+ linecache19 (>= 0.5.11)
43
+ ruby-debug-base19 (>= 0.11.19)
44
+ ruby_core_source (0.1.5)
45
+ archive-tar-minitar (>= 0.5.2)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ active_support
52
+ journal!
53
+ rake
54
+ redis
55
+ rspec
56
+ ruby-debug
57
+ ruby-debug19
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2011 Thomas Riboulet riboulet@gmail.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Journal
2
+
3
+ This gem is intended to provide an easy way to log activities. It uses Redis as storage, if you want to use a similar thing with CouchDB or MongoDB or anyother DB please create a separate Gem for that.
4
+
5
+ ## How to use
6
+
7
+ Put the following line into your Gemfile
8
+
9
+ ```
10
+ gem "journal"
11
+ ```
12
+
13
+ Then create an initializer or some other file loaded by your app and put the following config in it (with proper values) :
14
+
15
+ ```Ruby
16
+ Journal.setup do |config|
17
+ config.host = ""
18
+ config.port = ""
19
+ config.expiry = 604800
20
+ config.password = ""
21
+ end
22
+ ```
23
+
24
+
25
+ ## how to call
26
+
27
+ To create an new entry you just have to call the Journal.log method passing the data you want and a key :
28
+
29
+ ```
30
+ Journal.log("oh", "some data")
31
+ ```
32
+
33
+ You can then retrieve a JournalEntry object using the Journal.last method :
34
+
35
+ ```
36
+ a = Journal.last("oh")
37
+ a.inspect
38
+ # #<JournalEntry:0x007f980c8dacd8 @key="awesome+key", @data="some data@1337007458", @timestamp="1337007458", @date=#<DateTime: 2012-05-14T16:57:38+02:00 ((2456062j,53858s,0n),+7200s,2299161j)>
39
+ ```
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ begin
2
+ require "bundler"
3
+ Bundler::GemHelper.install_tasks
4
+ rescue Exception => e
5
+ end
6
+
7
+ require "rake"
8
+ require "rspec"
9
+ require "rspec/core/rake_task"
10
+ require "journal"
11
+
12
+ RSpec::Core::RakeTask.new(:spec) do |spec|
13
+ spec.pattern = "spec/**/*_spec.rb"
14
+ end
15
+
16
+ RSpec::Core::RakeTask.new('spec:progress') do |spec|
17
+ spec.rspec_opts = %w(--format progress)
18
+ spec.pattern = "spec/**/*_spec.rb"
19
+ end
20
+
21
+ require "rake/rdoctask"
22
+ Rake::RDocTask.new do |rdoc|
23
+ rdoc.rdoc_dir = "rdoc"
24
+ rdoc.title = "Journal #{Journal::VERSION}"
25
+ rdoc.rdoc_files.include("README*")
26
+ rdoc.rdoc_files.include("lib/**/*.rb")
27
+ end
28
+
29
+ task :default => :spec
data/journal.gemspec ADDED
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'journal'
3
+ s.version = '0.0.2'
4
+ s.date = '2012-05-14'
5
+ s.summary = "Journal!"
6
+ s.description = "Simple way to log activity on an object using a redis db"
7
+ s.authors = [ "Thomas Riboulet"]
8
+ s.email = 'riboulet@gmail.com'
9
+ s.files = `git ls-files`.split("\n")
10
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
11
+ s.require_paths = ["lib"]
12
+ s.homepage = 'http://github.com/mcansky/journal'
13
+ s.add_dependency 'redis'
14
+ s.add_development_dependency 'rspec', '~> 2.7'
15
+ end
@@ -0,0 +1,6 @@
1
+ Journal.setup do |config|
2
+ config.host = ""
3
+ config.port = ""
4
+ config.expiry = 604800
5
+ config.password = ""
6
+ end
@@ -0,0 +1,10 @@
1
+ module Journal
2
+ def self.log(key, data, score)
3
+ return @@redis.zadd(key, score, "#{data}@#{score}")
4
+ end
5
+
6
+ def self.last(key, _count = 1)
7
+ return JournalEntry.new(key, @@redis.zrange(key, -1, -1).first) unless _count > 1
8
+ return JournalEntry.from_array(key, @@redis.zrange(key, _count * -1, -1).reverse)
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ module Journal
2
+ module Rack
3
+ # Rack middleware the reloads RailsConfig on every request (only use in dev mode)
4
+ class Reloader
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ Journal.load_and_set_settings!
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Journal
2
+ VERSION = '0.0.1'
3
+ end
data/lib/journal.rb CHANGED
@@ -1,6 +1,8 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
1
3
  require 'active_support/core_ext/module/attribute_accessors'
2
- require "journal/handler.rb"
3
- require "journal/version.rb"
4
+ require "journal/version"
5
+ require "journal/handler"
4
6
  require 'rubygems'
5
7
  require 'redis'
6
8
 
data/redis.cf.sample ADDED
@@ -0,0 +1 @@
1
+ requirepass 34524GVQSDCA2CT34CZDX2
@@ -0,0 +1,141 @@
1
+ require 'spec_helper'
2
+
3
+ describe Journal do
4
+
5
+ context "Test Configuration" do
6
+ before :each do
7
+ Journal.setup do |config|
8
+ config.host = "localhost"
9
+ config.port = "6379"
10
+ config.expiry = 604800
11
+ config.password = "34524GVQSDCA2CT34CZDX2"
12
+ end
13
+ end
14
+ it { Journal.host.should eql("localhost") }
15
+ it { Journal.port.should eql("6379") }
16
+ it { Journal.expiry.should eql(604800) }
17
+ it { Journal.password.should eql("34524GVQSDCA2CT34CZDX2") }
18
+ end
19
+
20
+ context "Test Configuration again !" do
21
+ it { Journal.host.should eql("localhost") }
22
+ it { Journal.port.should eql("6379") }
23
+ it { Journal.expiry.should eql(604800) }
24
+ it { Journal.password.should eql("34524GVQSDCA2CT34CZDX2") }
25
+ end
26
+
27
+ context "Test Configuration" do
28
+ before :each do
29
+ Journal.setup do |config|
30
+ config.host = "localhost"
31
+ config.port = "6379"
32
+ config.expiry = 604800
33
+ config.password = "34524GVQSDCA2CT34CZDX2"
34
+ end
35
+ Journal.load_and_set_settings!
36
+ end
37
+ it "Test constantes" do
38
+ ['JOURNAL_HOST','JOURNAL_PORT','JOURNAL_EXPIRY','JOURNAL_PASSWORD'].each do |constant|
39
+ Kernel.const_defined?(constant).should be_true
40
+ end
41
+ end
42
+ it { JOURNAL_HOST.should eql("localhost") }
43
+ it { JOURNAL_PORT.should eql("6379") }
44
+ it { JOURNAL_EXPIRY.should eql(604800) }
45
+ it { JOURNAL_PASSWORD.should eql("34524GVQSDCA2CT34CZDX2") }
46
+ end
47
+
48
+ context "Test Redis link" do
49
+ before :each do
50
+ Journal.setup do |config|
51
+ config.host = "localhost"
52
+ config.port = "6379"
53
+ config.expiry = 604800
54
+ config.password = "34524GVQSDCA2CT34CZDX2"
55
+ end
56
+ Journal.load_and_set_settings!
57
+ Journal.redis
58
+ end
59
+ it { Journal.redis.should_not eql nil }
60
+ it { Journal.redis.class.should eql Redis }
61
+ end
62
+
63
+ context "Test Function" do
64
+ before :each do
65
+ Journal.setup do |config|
66
+ config.host = "localhost"
67
+ config.port = "6379"
68
+ config.expiry = 604800
69
+ config.password = "34524GVQSDCA2CT34CZDX2"
70
+ end
71
+ Journal.load_and_set_settings!
72
+ Journal.redis
73
+ Journal.redis.flushdb
74
+ end
75
+ it "Test setting an entry" do
76
+ key = "awesome+key"
77
+ data = "created object num 42"
78
+ timestamp = Time.now.to_i
79
+ Journal.log(key, data, timestamp)
80
+ Journal.redis.zrange(key,0,1).first.should eql "#{data}@#{timestamp}"
81
+ end
82
+
83
+ it "Test creating a JournalEntry" do
84
+ key = "awesome+key"
85
+ data = "created object num 42"
86
+ timestamp = Time.now.to_i
87
+ JournalEntry.new(key, "#{data}@#{timestamp}").entry.should eql "#{data}"
88
+ end
89
+
90
+ it "Test getting date from a JournalEntry" do
91
+ key = "awesome+key"
92
+ data = "created object num 42"
93
+ timestamp = Time.now.to_i
94
+ JournalEntry.new(key, "#{data}@#{timestamp}").date.should eql Time.at(timestamp).to_datetime
95
+ end
96
+
97
+ it "Test setting an entry" do
98
+ key = "awesome+key"
99
+ data = "created object num 42"
100
+ timestamp = Time.now.to_i
101
+ Journal.log(key, data, timestamp).should eql true
102
+ end
103
+
104
+ it "Test getting an entry" do
105
+ key = "awesome+key"
106
+ data = "created object num 42"
107
+ timestamp = Time.now.to_i
108
+ Journal.log(key, data, timestamp)
109
+ Journal.last(key).class.should eql JournalEntry
110
+ end
111
+
112
+ it "Test getting last entry" do
113
+ key = "awesome+key"
114
+ data = "created object num 42"
115
+ timestamp = Time.now.to_i
116
+ Journal.log(key, data, timestamp)
117
+ Journal.log(key, data, timestamp + 10)
118
+ Journal.last(key).raw.should eql "#{data}@#{timestamp + 10}"
119
+ end
120
+
121
+ it "Test getting back several entries" do
122
+ key = "awesome+key"
123
+ data = "created object num 42"
124
+ timestamp = Time.now.to_i
125
+ Journal.log(key, data, timestamp)
126
+ Journal.log(key, data, timestamp + 10)
127
+ Journal.last(key,10).class.should eql Array
128
+ end
129
+
130
+ it "Test getting back several entries from the end" do
131
+ key = "awesome+key"
132
+ data = "created object num 42"
133
+ timestamp = Time.now.to_i
134
+ Journal.log(key, data, timestamp)
135
+ Journal.log(key, data, timestamp + 10)
136
+ Journal.last(key,10).first.class.should eql JournalEntry
137
+ end
138
+
139
+ end
140
+
141
+ end
@@ -0,0 +1,8 @@
1
+ require 'journal'
2
+ require 'journal_entry'
3
+ require 'bundler/setup'
4
+
5
+ RSpec.configure do |c|
6
+ c.run_all_when_everything_filtered = true
7
+ # config.mock_with :mocha
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: journal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,14 +10,52 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-05-14 00:00:00.000000000 Z
13
- dependencies: []
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redis
16
+ requirement: &70105044468000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70105044468000
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70105044467400 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '2.7'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70105044467400
14
36
  description: Simple way to log activity on an object using a redis db
15
37
  email: riboulet@gmail.com
16
38
  executables: []
17
39
  extensions: []
18
40
  extra_rdoc_files: []
19
41
  files:
42
+ - .bundle/config
43
+ - .gitignore
44
+ - .rvmrc
45
+ - Gemfile
46
+ - Gemfile.lock
47
+ - LICENSE
48
+ - README.md
49
+ - Rakefile
50
+ - journal.gemspec
51
+ - lib/generators/templates/journal.rb
20
52
  - lib/journal.rb
53
+ - lib/journal/handler.rb
54
+ - lib/journal/rack/reloader.rb
55
+ - lib/journal/version.rb
56
+ - redis.cf.sample
57
+ - spec/journal_spec.rb
58
+ - spec/spec_helper.rb
21
59
  homepage: http://github.com/mcansky/journal
22
60
  licenses: []
23
61
  post_install_message:
@@ -42,4 +80,6 @@ rubygems_version: 1.8.15
42
80
  signing_key:
43
81
  specification_version: 3
44
82
  summary: Journal!
45
- test_files: []
83
+ test_files:
84
+ - spec/journal_spec.rb
85
+ - spec/spec_helper.rb