rom-session 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/.gitignore +9 -0
  2. data/.rspec +2 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +22 -0
  6. data/Gemfile +30 -0
  7. data/Gemfile.devtools +55 -0
  8. data/Guardfile +19 -0
  9. data/LICENSE +20 -0
  10. data/README.md +21 -0
  11. data/Rakefile +4 -0
  12. data/config/devtools.yml +2 -0
  13. data/config/flay.yml +3 -0
  14. data/config/flog.yml +2 -0
  15. data/config/mutant.yml +3 -0
  16. data/config/reek.yml +96 -0
  17. data/config/rubocop.yml +45 -0
  18. data/lib/rom-session.rb +43 -0
  19. data/lib/rom/session.rb +62 -0
  20. data/lib/rom/session/environment.rb +66 -0
  21. data/lib/rom/session/identity_map.rb +43 -0
  22. data/lib/rom/session/mapper.rb +43 -0
  23. data/lib/rom/session/relation.rb +126 -0
  24. data/lib/rom/session/state.rb +50 -0
  25. data/lib/rom/session/state/created.rb +22 -0
  26. data/lib/rom/session/state/deleted.rb +25 -0
  27. data/lib/rom/session/state/persisted.rb +29 -0
  28. data/lib/rom/session/state/transient.rb +20 -0
  29. data/lib/rom/session/state/updated.rb +29 -0
  30. data/lib/rom/session/tracker.rb +69 -0
  31. data/lib/rom/session/version.rb +9 -0
  32. data/lib/rom/support/proxy.rb +50 -0
  33. data/rom-session.gemspec +24 -0
  34. data/spec/integration/session_spec.rb +71 -0
  35. data/spec/rcov.opts +7 -0
  36. data/spec/shared/unit/environment_context.rb +11 -0
  37. data/spec/shared/unit/relation_context.rb +18 -0
  38. data/spec/spec_helper.rb +70 -0
  39. data/spec/unit/rom/session/class_methods/start_spec.rb +23 -0
  40. data/spec/unit/rom/session/clean_predicate_spec.rb +21 -0
  41. data/spec/unit/rom/session/environment/element_reader_spec.rb +13 -0
  42. data/spec/unit/rom/session/flush_spec.rb +58 -0
  43. data/spec/unit/rom/session/mapper/load_spec.rb +44 -0
  44. data/spec/unit/rom/session/relation/delete_spec.rb +28 -0
  45. data/spec/unit/rom/session/relation/dirty_predicate_spec.rb +38 -0
  46. data/spec/unit/rom/session/relation/identity_spec.rb +11 -0
  47. data/spec/unit/rom/session/relation/new_spec.rb +50 -0
  48. data/spec/unit/rom/session/relation/save_spec.rb +50 -0
  49. data/spec/unit/rom/session/relation/state_spec.rb +26 -0
  50. data/spec/unit/rom/session/relation/track_spec.rb +23 -0
  51. data/spec/unit/rom/session/relation/tracking_predicate_spec.rb +23 -0
  52. data/spec/unit/rom/session/state_spec.rb +79 -0
  53. metadata +167 -0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ Gemfile.lock
2
+ *.rbx
3
+ *.rbc
4
+ .yardoc/
5
+ doc/
6
+ measurements/
7
+ coverage/
8
+ profiling/
9
+ tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ #--backtrace
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rom
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3
data/.travis.yml ADDED
@@ -0,0 +1,22 @@
1
+ language: ruby
2
+ bundler_args: --without yard guard benchmarks
3
+ script: "bundle exec rake ci"
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - jruby-19mode
8
+ - rbx-19mode
9
+ - ruby-head
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: jruby-19mode
13
+ - rvm: ruby-head
14
+ notifications:
15
+ irc:
16
+ channels:
17
+ - irc.freenode.org#rom-rb
18
+ on_success: never
19
+ on_failure: change
20
+ email:
21
+ on_success: never
22
+ on_failure: change
data/Gemfile ADDED
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ module GemfileHelper
6
+ def self.source(name)
7
+ if Dir.exist?("../#{name}")
8
+ { path: "../#{name}" }
9
+ else
10
+ { git: "https://github.com/rom-rb/#{name}.git" }
11
+ end
12
+ end
13
+ end
14
+
15
+ gemspec
16
+
17
+ gem 'axiom', '~> 0.1.1'
18
+ gem 'axiom-memory-adapter', '~> 0.0.2'
19
+
20
+ gem 'rom-relation', GemfileHelper.source('rom-relation')
21
+ gem 'rom-mapper', GemfileHelper.source('rom-mapper')
22
+
23
+ gem 'devtools', git: 'https://github.com/rom-rb/devtools.git'
24
+
25
+ group :test do
26
+ gem 'bogus', '~> 0.1'
27
+ end
28
+
29
+ # added by devtools
30
+ eval_gemfile 'Gemfile.devtools'
data/Gemfile.devtools ADDED
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ group :development do
4
+ gem 'rake', '~> 10.1.0'
5
+ gem 'rspec', '~> 2.14.1'
6
+ gem 'yard', '~> 0.8.7'
7
+ end
8
+
9
+ group :yard do
10
+ gem 'kramdown', '~> 1.1.0'
11
+ end
12
+
13
+ group :guard do
14
+ gem 'guard', '~> 1.8.1'
15
+ gem 'guard-bundler', '~> 1.0.0'
16
+ gem 'guard-rspec', '~> 3.0.2'
17
+ gem 'guard-rubocop', '~> 0.2.0'
18
+ gem 'guard-mutant', '~> 0.0.1'
19
+
20
+ # file system change event handling
21
+ gem 'listen', '~> 1.3.0'
22
+ gem 'rb-fchange', '~> 0.0.6', require: false
23
+ gem 'rb-fsevent', '~> 0.9.3', require: false
24
+ gem 'rb-inotify', '~> 0.9.0', require: false
25
+
26
+ # notification handling
27
+ gem 'libnotify', '~> 0.8.0', require: false
28
+ gem 'rb-notifu', '~> 0.0.4', require: false
29
+ gem 'terminal-notifier-guard', '~> 1.5.3', require: false
30
+ end
31
+
32
+ group :metrics do
33
+ gem 'coveralls', '~> 0.6.7'
34
+ gem 'flay', '~> 2.4.0'
35
+ gem 'flog', '~> 4.1.1'
36
+ gem 'reek', '~> 1.3.2'
37
+ gem 'rubocop', '~> 0.11.0'
38
+ gem 'simplecov', '~> 0.7.1'
39
+ gem 'yardstick', '~> 0.9.7', git: 'https://github.com/dkubb/yardstick.git'
40
+
41
+ platforms :ruby_19, :ruby_20 do
42
+ gem 'mutant', git: 'https://github.com/mbj/mutant.git'
43
+ gem 'yard-spellcheck', '~> 0.1.5'
44
+ end
45
+ end
46
+
47
+ group :benchmarks do
48
+ gem 'rbench', '~> 0.2.3'
49
+ end
50
+
51
+ platform :jruby do
52
+ group :jruby do
53
+ gem 'jruby-openssl', '~> 0.8.5'
54
+ end
55
+ end
data/Guardfile ADDED
@@ -0,0 +1,19 @@
1
+ guard :rspec do
2
+ #run all specs if configuration is modified
3
+ watch('Guardfile') { 'spec' }
4
+ watch('Gemfile.lock') { 'spec' }
5
+ watch('spec/spec_helper.rb') { 'spec' }
6
+
7
+ # run all specs if supporting files files are modified
8
+ watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec' }
9
+
10
+ # run unit specs if associated lib code is modified
11
+ watch(%r{\Alib/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}"] }
12
+ watch(%r{\Alib/(.+)/support/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}/#{m[2]}"] }
13
+ watch("lib/#{File.basename(File.expand_path('../', __FILE__))}.rb") { 'spec' }
14
+
15
+ # run a spec if it is modified
16
+ watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
17
+
18
+ notification :tmux, :display_message => true
19
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Ruby Object Mapper Team
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.md ADDED
@@ -0,0 +1,21 @@
1
+ # rom-session
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rom-session.png)][gem]
4
+ [![Build Status](https://travis-ci.org/rom-rb/rom-session.png?branch=master)][travis]
5
+ [![Dependency Status](https://gemnasium.com/rom-rb/rom-session.png)][gemnasium]
6
+ [![Code Climate](https://codeclimate.com/github/rom-rb/rom-session.png)][codeclimate]
7
+ [![Coverage Status](https://coveralls.io/repos/rom-rb/rom-session/badge.png?branch=master)][coveralls]
8
+
9
+ [gem]: https://rubygems.org/gems/rom-session
10
+ [travis]: https://travis-ci.org/rom-rb/rom-session
11
+ [gemnasium]: https://gemnasium.com/rom-rb/rom-session
12
+ [codeclimate]: https://codeclimate.com/github/rom-rb/rom-session
13
+ [coveralls]: https://coveralls.io/r/rom-rb/rom-session
14
+
15
+ Session and state tracker for [Ruby Object Mapper](http://rom-rb.org).
16
+
17
+ See ROM's [README](https://github.com/rom-rb/rom) for more information.
18
+
19
+ ## License
20
+
21
+ See LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+
3
+ require 'devtools'
4
+ Devtools.init_rake_tasks
@@ -0,0 +1,2 @@
1
+ ---
2
+ unit_test_timeout: 1.0
data/config/flay.yml ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ threshold: 9
3
+ total_score: 126
data/config/flog.yml ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 14.1
data/config/mutant.yml ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ name: rom-session
3
+ namespace: 'ROM::Session'
data/config/reek.yml ADDED
@@ -0,0 +1,96 @@
1
+ UncommunicativeParameterName:
2
+ accept: []
3
+ exclude: []
4
+ enabled: true
5
+ reject:
6
+ - !ruby/regexp /^.$/
7
+ - !ruby/regexp /[0-9]$/
8
+ - !ruby/regexp /[A-Z]/
9
+ TooManyMethods:
10
+ max_methods: 12
11
+ enabled: true
12
+ exclude: []
13
+ max_instance_variables: 3
14
+ UncommunicativeMethodName:
15
+ accept: []
16
+ exclude: []
17
+ enabled: true
18
+ reject:
19
+ - !ruby/regexp /^[a-z]$/
20
+ - !ruby/regexp /[0-9]$/
21
+ - !ruby/regexp /[A-Z]/
22
+ LongParameterList:
23
+ enabled: true
24
+ max_params: 2
25
+ overrides: {}
26
+ exclude:
27
+ - ROM::Session::IdentityMap#store
28
+ FeatureEnvy:
29
+ enabled: true
30
+ exclude:
31
+ - ROM::Session::ObjectNotTrackedError
32
+ - ROM::Proxy
33
+ ClassVariable:
34
+ exclude: []
35
+ enabled: true
36
+ BooleanParameter:
37
+ exclude: []
38
+ enabled: true
39
+ IrresponsibleModule:
40
+ exclude: []
41
+ enabled: true
42
+ UncommunicativeModuleName:
43
+ accept: []
44
+ exclude: []
45
+ enabled: true
46
+ reject:
47
+ - !ruby/regexp /^.$/
48
+ - !ruby/regexp /[0-9]$/
49
+ NestedIterators:
50
+ ignore_iterators: []
51
+ exclude: []
52
+ enabled: true
53
+ max_allowed_nesting: 1
54
+ TooManyStatements:
55
+ max_statements: 7
56
+ exclude: []
57
+ enabled: true
58
+ DuplicateMethodCall:
59
+ allow_calls: []
60
+ exclude: []
61
+ enabled: false
62
+ max_calls: 1
63
+ UtilityFunction:
64
+ enabled: true
65
+ max_helper_calls: 0
66
+ exclude:
67
+ - ROM::Session::ObjectNotTrackedError
68
+ - ROM::Proxy
69
+ Attribute:
70
+ exclude: []
71
+ enabled: false
72
+ UncommunicativeVariableName:
73
+ accept: []
74
+ exclude: []
75
+ enabled: true
76
+ reject:
77
+ - !ruby/regexp /^.$/
78
+ - !ruby/regexp /[0-9]$/
79
+ - !ruby/regexp /[A-Z]/
80
+ RepeatedConditional:
81
+ enabled: true
82
+ max_ifs: 1
83
+ DataClump:
84
+ enabled: true
85
+ max_copies: 0
86
+ min_clump_size: 2
87
+ exclude:
88
+ - ROM::Session::Tracker
89
+ ControlParameter:
90
+ exclude: []
91
+ enabled: true
92
+ LongYieldList:
93
+ max_params: 0
94
+ enabled: true
95
+ exclude:
96
+ - ROM::Session#self.start
@@ -0,0 +1,45 @@
1
+ AllCops:
2
+ Includes:
3
+ - '**/*.rake'
4
+ - 'Gemfile'
5
+ - 'Gemfile.devtools'
6
+ Excludes:
7
+ - '**/vendor/**'
8
+
9
+ # Avoid parameter lists longer than five parameters.
10
+ ParameterLists:
11
+ Max: 3
12
+ CountKeywordArgs: true
13
+
14
+ # Avoid more than `Max` levels of nesting.
15
+ BlockNesting:
16
+ Max: 3
17
+
18
+ # Align with the style guide.
19
+ CollectionMethods:
20
+ PreferredMethods:
21
+ collect: 'map'
22
+ inject: 'reduce'
23
+ find: 'detect'
24
+ find_all: 'select'
25
+
26
+ # Do not force public/protected/private keyword to be indented at the same
27
+ # level as the def keyword. My personal preference is to outdent these keywords
28
+ # because I think when scanning code it makes it easier to identify the
29
+ # sections of code and visually separate them. When the keyword is at the same
30
+ # level I think it sort of blends in with the def keywords and makes it harder
31
+ # to scan the code and see where the sections are.
32
+ AccessControl:
33
+ Enabled: false
34
+
35
+ LineLength:
36
+ Max: 108
37
+
38
+ Blocks:
39
+ Enabled: false
40
+
41
+ Documentation:
42
+ Enabled: false
43
+
44
+ EmptyLineBetweenDefs:
45
+ Enabled: false # TODO: re-enable once SpecHelper.mock_model case is properly handled
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+
3
+ require 'adamantium'
4
+ require 'equalizer'
5
+ require 'abstract_type'
6
+ require 'concord'
7
+
8
+ require 'rom-relation'
9
+ require 'rom-mapper'
10
+
11
+ module ROM
12
+
13
+ # Session namespace
14
+ class Session
15
+
16
+ # Raised when an object is expected to be tracked and it's not
17
+ #
18
+ class ObjectNotTrackedError < StandardError
19
+ def initialize(object)
20
+ super("Tracker doesn't include #{object.inspect}")
21
+ end
22
+ end
23
+
24
+ end # Session
25
+
26
+ end # ROM
27
+
28
+ require 'rom/support/proxy'
29
+
30
+ require 'rom/session'
31
+
32
+ require 'rom/session/environment'
33
+ require 'rom/session/tracker'
34
+ require 'rom/session/identity_map'
35
+ require 'rom/session/relation'
36
+ require 'rom/session/mapper'
37
+
38
+ require 'rom/session/state'
39
+ require 'rom/session/state/transient'
40
+ require 'rom/session/state/persisted'
41
+ require 'rom/session/state/created'
42
+ require 'rom/session/state/updated'
43
+ require 'rom/session/state/deleted'
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+
3
+ module ROM
4
+
5
+ # Extends ROM's environment with IdentityMap and state-tracking functionality
6
+ #
7
+ # @api public
8
+ class Session
9
+ include Concord.new(:environment)
10
+
11
+ # Start a new session
12
+ #
13
+ # @example
14
+ #
15
+ # ROM::Session.start(env) do |session|
16
+ # user = session[:users].new(name: 'Jane')
17
+ # session[:users].save(user)
18
+ # session[:users].flush
19
+ # end
20
+ #
21
+ # @param [ROM::Environment] rom's environment
22
+ #
23
+ # @yieldparam [Session::Environment]
24
+ #
25
+ # @api public
26
+ def self.start(environment)
27
+ yield(new(Environment.build(environment)))
28
+ end
29
+
30
+ # Return a session relation identified by name
31
+ #
32
+ # @param [Symbol] relation name
33
+ #
34
+ # @return [Session::Relation]
35
+ #
36
+ # @api public
37
+ def [](relation_name)
38
+ environment[relation_name]
39
+ end
40
+
41
+ # Flush this session committing all the state changes
42
+ #
43
+ # @return [Session]
44
+ #
45
+ # @api public
46
+ def flush
47
+ environment.commit
48
+ self
49
+ end
50
+
51
+ # Return if there are any pending state changes
52
+ #
53
+ # @return [Boolean]
54
+ #
55
+ # @api public
56
+ def clean?
57
+ environment.clean?
58
+ end
59
+
60
+ end # Session
61
+
62
+ end # ROM