euston-projections 1.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Rakefile +161 -0
- data/euston-projections.gemspec +34 -0
- data/lib/euston-projections/idempotence.rb +39 -0
- data/lib/euston-projections/mongo_projection.rb +28 -0
- data/lib/euston-projections/mongo_projection_event_handler.rb +21 -0
- data/lib/euston-projections/version.rb +5 -0
- data/lib/euston-projections.rb +5 -0
- metadata +124 -0
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
#############################################################################
|
5
|
+
#
|
6
|
+
# Helper functions
|
7
|
+
#
|
8
|
+
#############################################################################
|
9
|
+
|
10
|
+
def name
|
11
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
12
|
+
end
|
13
|
+
|
14
|
+
def version
|
15
|
+
line = File.read("lib/#{name}/version.rb")[/^\s*VERSION\s*=\s*.*/]
|
16
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
17
|
+
end
|
18
|
+
|
19
|
+
def date
|
20
|
+
Date.today.to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
def rubyforge_project
|
24
|
+
name
|
25
|
+
end
|
26
|
+
|
27
|
+
def gemspec_file
|
28
|
+
"#{name}.gemspec"
|
29
|
+
end
|
30
|
+
|
31
|
+
def gem_file
|
32
|
+
"#{name}-#{version}.gem"
|
33
|
+
end
|
34
|
+
|
35
|
+
def replace_header(head, header_name, provider = nil)
|
36
|
+
if provider
|
37
|
+
value = send(provider)
|
38
|
+
else
|
39
|
+
value = "'#{send(header_name)}'"
|
40
|
+
end
|
41
|
+
|
42
|
+
provider ||= header_name
|
43
|
+
head.sub!(/(\.#{header_name}\s*= ).*/) { "#{$1}#{value}"}
|
44
|
+
end
|
45
|
+
|
46
|
+
def platform
|
47
|
+
jruby? ? '-java' : ''
|
48
|
+
end
|
49
|
+
|
50
|
+
def platform_dependant_gem_file
|
51
|
+
"#{name}-#{version}#{platform}.gem"
|
52
|
+
end
|
53
|
+
|
54
|
+
def platform_dependent_version
|
55
|
+
"'#{version}#{platform}'"
|
56
|
+
end
|
57
|
+
|
58
|
+
def jruby?
|
59
|
+
RUBY_PLATFORM.to_s == 'java'
|
60
|
+
end
|
61
|
+
|
62
|
+
def trim_array_ends array
|
63
|
+
array.shift
|
64
|
+
array.pop
|
65
|
+
array
|
66
|
+
end
|
67
|
+
|
68
|
+
#############################################################################
|
69
|
+
#
|
70
|
+
# Custom tasks
|
71
|
+
#
|
72
|
+
#############################################################################
|
73
|
+
|
74
|
+
default_rspec_opts = %w[--colour --format Fuubar]
|
75
|
+
|
76
|
+
desc "Run all examples"
|
77
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
78
|
+
t.rspec_opts = default_rspec_opts
|
79
|
+
end
|
80
|
+
|
81
|
+
#############################################################################
|
82
|
+
#
|
83
|
+
# Packaging tasks
|
84
|
+
#
|
85
|
+
#############################################################################
|
86
|
+
|
87
|
+
def built_gem
|
88
|
+
@built_gem ||= Dir["#{name}*.gem"].first
|
89
|
+
end
|
90
|
+
|
91
|
+
desc "Create tag v#{platform_dependent_version} and build and push #{platform_dependant_gem_file} to Rubygems"
|
92
|
+
task :release => :build do
|
93
|
+
unless `git branch` =~ /^\* master$/
|
94
|
+
puts "You must be on the master branch to release!"
|
95
|
+
exit!
|
96
|
+
end
|
97
|
+
|
98
|
+
sh "git commit --allow-empty -a -m 'Release #{platform_dependent_version}'"
|
99
|
+
sh "git tag v#{platform_dependent_version}"
|
100
|
+
sh "git push origin master"
|
101
|
+
sh "git push origin v#{platform_dependent_version}"
|
102
|
+
|
103
|
+
command = "gem push pkg/#{platform_dependant_gem_file}"
|
104
|
+
|
105
|
+
if jruby?
|
106
|
+
puts "--------------------------------------------------------------------------------------"
|
107
|
+
puts "can't push to rubygems using jruby at the moment, so switch to mri and run: #{command}"
|
108
|
+
puts "--------------------------------------------------------------------------------------"
|
109
|
+
else
|
110
|
+
sh command
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
desc "Build #{platform_dependant_gem_file} into the pkg directory"
|
115
|
+
task :build => :gemspec do
|
116
|
+
sh "mkdir -p pkg"
|
117
|
+
sh "gem build #{gemspec_file}"
|
118
|
+
sh "mv #{built_gem} pkg"
|
119
|
+
end
|
120
|
+
|
121
|
+
desc "Generate #{gemspec_file}"
|
122
|
+
task :gemspec => :validate do
|
123
|
+
# read spec file and split out manifest section
|
124
|
+
spec = File.read(gemspec_file)
|
125
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
126
|
+
|
127
|
+
# replace name version and date
|
128
|
+
replace_header(head, :name)
|
129
|
+
replace_header(head, :version)
|
130
|
+
replace_header(head, :date)
|
131
|
+
#comment this out if your rubyforge_project has a different name
|
132
|
+
#replace_header(head, :rubyforge_project)
|
133
|
+
|
134
|
+
# determine file list from git ls-files
|
135
|
+
files = `git ls-files`.
|
136
|
+
split("\n").
|
137
|
+
sort.
|
138
|
+
reject { |file| file =~ /^\./ }.
|
139
|
+
reject { |file| file =~ /^(rdoc|pkg)/ }.
|
140
|
+
map { |file| " #{file}" }.
|
141
|
+
join("\n")
|
142
|
+
|
143
|
+
# piece file back together and write
|
144
|
+
manifest = " s.files = %w[\n#{files}\n ]\n"
|
145
|
+
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
146
|
+
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
147
|
+
puts "Updated #{gemspec_file}"
|
148
|
+
end
|
149
|
+
|
150
|
+
desc "Validate #{gemspec_file}"
|
151
|
+
task :validate do
|
152
|
+
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
|
153
|
+
unless libfiles.empty?
|
154
|
+
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
|
155
|
+
exit!
|
156
|
+
end
|
157
|
+
unless Dir['VERSION*'].empty?
|
158
|
+
puts "A `VERSION` file at root level violates Gem best practices."
|
159
|
+
exit!
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'euston-projections'
|
3
|
+
s.version = '1.0.0'
|
4
|
+
s.platform = RUBY_PLATFORM.to_s == 'java' ? 'java' : Gem::Platform::RUBY
|
5
|
+
s.authors = ['Lee Henson', 'Guy Boertje']
|
6
|
+
s.email = ['lee.m.henson@gmail.com', 'guyboertje@gmail.com']
|
7
|
+
s.summary = %q{Default projection classes for Euston.}
|
8
|
+
s.description = ""
|
9
|
+
s.homepage = 'http://github.com/leemhenson/euston-projections'
|
10
|
+
|
11
|
+
# = MANIFEST =
|
12
|
+
s.files = %w[
|
13
|
+
Gemfile
|
14
|
+
Rakefile
|
15
|
+
euston-projections.gemspec
|
16
|
+
lib/euston-projections.rb
|
17
|
+
lib/euston-projections/idempotence.rb
|
18
|
+
lib/euston-projections/mongo_projection.rb
|
19
|
+
lib/euston-projections/mongo_projection_event_handler.rb
|
20
|
+
lib/euston-projections/version.rb
|
21
|
+
]
|
22
|
+
# = MANIFEST =
|
23
|
+
|
24
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
25
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
26
|
+
|
27
|
+
s.add_dependency 'activesupport', '~> 3.0.10'
|
28
|
+
s.add_dependency 'euston-eventstore', '~> 1.2.0'
|
29
|
+
s.add_dependency 'mongoid', '~> 2.1.0'
|
30
|
+
|
31
|
+
s.add_development_dependency 'awesome_print', '~> 0.4.0'
|
32
|
+
s.add_development_dependency 'fuubar', '~> 0.0.0'
|
33
|
+
s.add_development_dependency 'rspec', '~> 2.6.0'
|
34
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Euston
|
2
|
+
module Projections
|
3
|
+
module Idempotence
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module InstanceMethods
|
7
|
+
def if_unhandled obj, headers
|
8
|
+
return if obj.already_processed_message? headers.id
|
9
|
+
|
10
|
+
obj.add_to_history headers.id
|
11
|
+
|
12
|
+
unless headers.source_message.nil? || obj.already_processed_message?(headers.source_message[:headers][:id])
|
13
|
+
obj.add_to_history headers.source_message[:headers][:id]
|
14
|
+
end
|
15
|
+
|
16
|
+
yield
|
17
|
+
end
|
18
|
+
|
19
|
+
def if_unhandled_or_new document_type, id, headers
|
20
|
+
document = document_type.find(id) || document_type.new(_id: id)
|
21
|
+
|
22
|
+
if_unhandled document, headers do
|
23
|
+
yield document
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def if_exists_and_unhandled document_type, id, headers
|
28
|
+
document = document_type.find id
|
29
|
+
|
30
|
+
raise ArgumentError, "Expected to find a #{document_type} with id #{id}, but none exists." if document.nil?
|
31
|
+
|
32
|
+
if_unhandled document, headers do
|
33
|
+
yield document
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Euston
|
2
|
+
module Projections
|
3
|
+
module MongoProjection
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Mongoid::Document
|
6
|
+
|
7
|
+
included do
|
8
|
+
field :_history, :type => Hash, :default => {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_to_history message_id
|
12
|
+
_history[message_id] = Time.now.to_f unless already_processed_message? message_id
|
13
|
+
end
|
14
|
+
|
15
|
+
def already_processed_message? message_id
|
16
|
+
_history.has_key? message_id
|
17
|
+
end
|
18
|
+
|
19
|
+
def processed_message_ids
|
20
|
+
_history.keys
|
21
|
+
end
|
22
|
+
|
23
|
+
def prune_history_older_than time
|
24
|
+
_history.reject! { |id, timestamp| timestamp < time }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Euston
|
2
|
+
module Projections
|
3
|
+
module MongoProjectionEventHandler
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
include EventHandler
|
7
|
+
include Idempotence
|
8
|
+
include EventStore::Persistence::Mongodb::MongoConcurrencyDetection
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def concurrent_subscribes *args, &consumer
|
12
|
+
subscribes *args do |*block_args|
|
13
|
+
detect_mongo_concurrency do
|
14
|
+
instance_exec *block_args, &consumer
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: euston-projections
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
6
|
+
platform: java
|
7
|
+
authors:
|
8
|
+
- Lee Henson
|
9
|
+
- Guy Boertje
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-10-13 00:00:00.000000000 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: activesupport
|
18
|
+
version_requirements: &2218 !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.10
|
23
|
+
none: false
|
24
|
+
requirement: *2218
|
25
|
+
prerelease: false
|
26
|
+
type: :runtime
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: euston-eventstore
|
29
|
+
version_requirements: &2236 !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.0
|
34
|
+
none: false
|
35
|
+
requirement: *2236
|
36
|
+
prerelease: false
|
37
|
+
type: :runtime
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: mongoid
|
40
|
+
version_requirements: &2252 !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.1.0
|
45
|
+
none: false
|
46
|
+
requirement: *2252
|
47
|
+
prerelease: false
|
48
|
+
type: :runtime
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: awesome_print
|
51
|
+
version_requirements: &2268 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.4.0
|
56
|
+
none: false
|
57
|
+
requirement: *2268
|
58
|
+
prerelease: false
|
59
|
+
type: :development
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: fuubar
|
62
|
+
version_requirements: &2286 !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 0.0.0
|
67
|
+
none: false
|
68
|
+
requirement: *2286
|
69
|
+
prerelease: false
|
70
|
+
type: :development
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rspec
|
73
|
+
version_requirements: &2302 !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.6.0
|
78
|
+
none: false
|
79
|
+
requirement: *2302
|
80
|
+
prerelease: false
|
81
|
+
type: :development
|
82
|
+
description: ''
|
83
|
+
email:
|
84
|
+
- lee.m.henson@gmail.com
|
85
|
+
- guyboertje@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- Gemfile
|
91
|
+
- Rakefile
|
92
|
+
- euston-projections.gemspec
|
93
|
+
- lib/euston-projections.rb
|
94
|
+
- lib/euston-projections/idempotence.rb
|
95
|
+
- lib/euston-projections/mongo_projection.rb
|
96
|
+
- lib/euston-projections/mongo_projection_event_handler.rb
|
97
|
+
- lib/euston-projections/version.rb
|
98
|
+
has_rdoc: true
|
99
|
+
homepage: http://github.com/leemhenson/euston-projections
|
100
|
+
licenses: []
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
none: false
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
none: false
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.5.1
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: Default projection classes for Euston.
|
123
|
+
test_files: []
|
124
|
+
...
|