Class: ROM::Session::Relation
- Inherits:
-
Relation
- Object
- Relation
- ROM::Session::Relation
- Includes:
- Proxy
- Defined in:
- lib/rom/session/relation.rb
Overview
Adds session-specific functionality on top of ROM’s relation.
A session relation builds a queue of state changes that will be committed when a session is flushed.
Class Method Summary collapse
Instance Method Summary collapse
-
#delete(object) ⇒ Session::Relation
Transient an object into a deleted state.
-
#dirty?(object) ⇒ Boolean
Check if a tracked object is dirty.
-
#identity(object) ⇒ Array
Return object’s identity.
-
#initialize(relation, tracker) ⇒ Relation
constructor
private
A new instance of Relation.
-
#new(*args, &block) ⇒ Object
Build a new object instance and start tracking.
-
#save(object) ⇒ Session::Relation
Transition an object into a saved state.
-
#state(object) ⇒ Session::State
Return current state of the tracked object.
-
#track(object) ⇒ Session::Relation
Start tracking an object within this session.
-
#tracking?(object) ⇒ Boolean
Check if an object is being tracked.
Methods included from Proxy
Constructor Details
#initialize(relation, tracker) ⇒ Relation
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Relation.
25 26 27 |
# File 'lib/rom/session/relation.rb', line 25 def initialize(relation, tracker) @relation, @tracker = relation, tracker end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ROM::Proxy
Class Method Details
.build(relation, tracker) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 22 |
# File 'lib/rom/session/relation.rb', line 19 def self.build(relation, tracker) mapper = Mapper.build(relation.mapper, tracker) new(relation.inject_mapper(mapper), tracker) end |
Instance Method Details
#delete(object) ⇒ Session::Relation
Transient an object into a deleted state
51 52 53 54 |
# File 'lib/rom/session/relation.rb', line 51 def delete(object) tracker.queue(state(object).delete(relation)) self end |
#dirty?(object) ⇒ Boolean
Check if a tracked object is dirty
108 109 110 |
# File 'lib/rom/session/relation.rb', line 108 def dirty?(object) state(object).transient? || mapper.dirty?(object) end |
#identity(object) ⇒ Array
Return object’s identity
74 75 76 |
# File 'lib/rom/session/relation.rb', line 74 def identity(object) mapper.identity(object) end |
#new(*args, &block) ⇒ Object
Build a new object instance and start tracking
95 96 97 98 99 |
# File 'lib/rom/session/relation.rb', line 95 def new(*args, &block) object = mapper.new_object(*args, &block) track(object) object end |
#save(object) ⇒ Session::Relation
Transition an object into a saved state
Transient object’s state turns into Created Persisted object’s state turns into Updated
39 40 41 42 |
# File 'lib/rom/session/relation.rb', line 39 def save(object) tracker.queue(state(object).save(relation)) self end |
#state(object) ⇒ Session::State
Return current state of the tracked object
63 64 65 |
# File 'lib/rom/session/relation.rb', line 63 def state(object) tracker.fetch(object) end |
#track(object) ⇒ Session::Relation
Start tracking an object within this session
85 86 87 88 |
# File 'lib/rom/session/relation.rb', line 85 def track(object) tracker.store_transient(object, mapper) self end |
#tracking?(object) ⇒ Boolean
Check if an object is being tracked
119 120 121 |
# File 'lib/rom/session/relation.rb', line 119 def tracking?(object) tracker.include?(object) end |