This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Rename Resource::State -> Resource::PersistenceState.

Also rename accessor: Resource#persisted_state -> #persistence_state and add previous accessor as a deprecated alias in dm-core/backwards.rb.
  • Loading branch information...
emmanuel committed Jul 24, 2011
1 parent f3f9ec9 commit 5c5690d41db698598bf061b7543386f2b7bf7c48
View
@@ -52,13 +52,13 @@ module Undefined; end
require 'dm-core/query/sort'
require 'dm-core/resource'
-require 'dm-core/resource/state'
-require 'dm-core/resource/state/transient'
-require 'dm-core/resource/state/immutable'
-require 'dm-core/resource/state/persisted'
-require 'dm-core/resource/state/clean'
-require 'dm-core/resource/state/deleted'
-require 'dm-core/resource/state/dirty'
+require 'dm-core/resource/persistence_state'
+require 'dm-core/resource/persistence_state/transient'
+require 'dm-core/resource/persistence_state/immutable'
+require 'dm-core/resource/persistence_state/persisted'
+require 'dm-core/resource/persistence_state/clean'
+require 'dm-core/resource/persistence_state/deleted'
+require 'dm-core/resource/persistence_state/dirty'
require 'dm-core/property'
require 'dm-core/property/typecast/numeric'
@@ -108,6 +108,8 @@ module Undefined; end
require 'dm-core/core_ext/kernel' # TODO: do not load automatically
require 'dm-core/core_ext/symbol' # TODO: do not load automatically
+require 'dm-core/backwards' # TODO: do not load automatically
+
# A logger should always be present. Lets be consistent with DO
DataMapper::Logger.new(StringIO.new, :fatal)
@@ -365,7 +365,7 @@ def destroy!
end
each do |resource|
- resource.persisted_state = Resource::State::Immutable.new(resource)
+ resource.persistence_state = Resource::PersistenceState::Immutable.new(resource)
end
clear
View
@@ -0,0 +1,13 @@
+require "dm-core/support/deprecate"
+
+module DataMapper
+ module Resource
+ extend Deprecate
+
+ deprecate :persisted_state, :persistence_state
+ deprecate :persisted_state=, :persistence_state=
+ deprecate :persisted_state?, :persistence_state?
+
+ end # module Resource
+
+end # module DataMapper
@@ -919,7 +919,7 @@ def destroy!
end
each do |resource|
- resource.persisted_state = Resource::State::Immutable.new(resource)
+ resource.persistence_state = Resource::PersistenceState::Immutable.new(resource)
end
clear
View
@@ -627,13 +627,13 @@ def load(records, query)
resource.instance_variable_set(:@_repository, repository)
if identity_map
- resource.persisted_state = Resource::State::Clean.new(resource) unless resource.persisted_state?
+ resource.persistence_state = Resource::PersistenceState::Clean.new(resource) unless resource.persistence_state?
# defer setting the IdentityMap so second level caches can
# record the state of the resource after loaded
identity_map[key_values] = resource
else
- resource.persisted_state = Resource::State::Immutable.new(resource)
+ resource.persistence_state = Resource::PersistenceState::Immutable.new(resource)
end
resource
@@ -206,7 +206,7 @@ def create_reader_for(property)
def #{name}
return #{instance_variable_name} if defined?(#{instance_variable_name})
property = properties[#{name.inspect}]
- #{instance_variable_name} = property ? persisted_state.get(property) : nil
+ #{instance_variable_name} = property ? persistence_state.get(property) : nil
end
RUBY
@@ -234,8 +234,8 @@ def create_writer_for(property)
#{writer_visibility}
def #{writer_name}(value)
property = properties[#{name.inspect}]
- self.persisted_state = persisted_state.set(property, value)
- persisted_state.get(property)
+ self.persistence_state = persistence_state.set(property, value)
+ persistence_state.get(property)
end
RUBY
end
@@ -337,7 +337,7 @@ def #{reader_name}(query = nil)
# of 1:1, the underlying collection is hidden in a
# private ivar, and the resource is in a known ivar
- persisted_state.get(relationships[#{name.inspect}], query)
+ persistence_state.get(relationships[#{name.inspect}], query)
end
RUBY
end
@@ -357,8 +357,8 @@ def create_relationship_writer(relationship)
#{writer_visibility}
def #{writer_name}(target)
relationship = relationships[#{name.inspect}]
- self.persisted_state = persisted_state.set(relationship, target)
- persisted_state.get(relationship)
+ self.persistence_state = persistence_state.set(relationship, target)
+ persistence_state.get(relationship)
end
RUBY
end
View
@@ -76,24 +76,24 @@ def self.included(model)
# Get the persisted state for the resource
#
- # @return [Resource::State]
+ # @return [Resource::PersistenceState]
# the current persisted state for the resource
#
# @api private
- def persisted_state
- @_state ||= Resource::State::Transient.new(self)
+ def persistence_state
+ @_persistence_state ||= Resource::PersistenceState::Transient.new(self)
end
# Set the persisted state for the resource
#
- # @param [Resource::State]
+ # @param [Resource::PersistenceState]
# the new persisted state for the resource
#
# @return [undefined]
#
# @api private
- def persisted_state=(state)
- @_state = state
+ def persistence_state=(state)
+ @_persistence_state = state
end
# Test if the persisted state is set
@@ -102,8 +102,8 @@ def persisted_state=(state)
# true if the persisted state is set
#
# @api private
- def persisted_state?
- defined?(@_state) ? true : false
+ def persistence_state?
+ defined?(@_persistence_state) ? true : false
end
# Repository this resource belongs to in the context of this collection
@@ -149,7 +149,7 @@ def key
#
# @api public
def new?
- persisted_state.kind_of?(State::Transient)
+ persistence_state.kind_of?(PersistenceState::Transient)
end
# Checks if this Resource instance is saved
@@ -159,7 +159,7 @@ def new?
#
# @api public
def saved?
- persisted_state.kind_of?(State::Persisted)
+ persistence_state.kind_of?(PersistenceState::Persisted)
end
# Checks if this Resource instance is destroyed
@@ -179,7 +179,8 @@ def destroyed?
#
# @api public
def clean?
- persisted_state.kind_of?(State::Clean) || persisted_state.kind_of?(State::Immutable)
+ persistence_state.kind_of?(PersistenceState::Clean) ||
+ persistence_state.kind_of?(PersistenceState::Immutable)
end
# Checks if the resource has unsaved changes
@@ -201,7 +202,7 @@ def dirty?
#
# @api public
def readonly?
- persisted_state.kind_of?(State::Immutable)
+ persistence_state.kind_of?(PersistenceState::Immutable)
end
# Returns the value of the attribute.
@@ -237,7 +238,7 @@ def readonly?
# @api public
def attribute_get(name)
property = properties[name]
- persisted_state.get(property) if property
+ persistence_state.get(property) if property
end
alias_method :[], :attribute_get
@@ -279,7 +280,7 @@ def attribute_get(name)
# @api public
def attribute_set(name, value)
property = properties[name]
- self.persisted_state = persisted_state.set(property, value) if property
+ self.persistence_state = persistence_state.set(property, value) if property
end
alias_method :[]=, :attribute_set
@@ -334,7 +335,7 @@ def attributes=(attributes)
raise ArgumentError, "The attribute '#{name}' is not accessible in #{model}"
end
when Associations::Relationship, Property
- self.persisted_state = persisted_state.set(name, value)
+ self.persistence_state = persistence_state.set(name, value)
end
end
end
@@ -358,7 +359,7 @@ def reload
clear_subjects
end
- self.persisted_state = persisted_state.rollback
+ self.persistence_state = persistence_state.rollback
self
end
@@ -550,8 +551,8 @@ def inspect
#
# @api semipublic
def original_attributes
- if persisted_state.respond_to?(:original_attributes)
- persisted_state.original_attributes.dup.freeze
+ if persistence_state.respond_to?(:original_attributes)
+ persistence_state.original_attributes.dup.freeze
else
{}.freeze
end
@@ -753,7 +754,7 @@ def initialize_copy(original)
instance_variable_set(ivar, DataMapper::Ext.try_dup(instance_variable_get(ivar)))
end
- self.persisted_state = persisted_state.class.new(self)
+ self.persistence_state = persistence_state.class.new(self)
end
# Returns name of the repository this object
@@ -952,7 +953,7 @@ def child_associations
#
# @api private
def _persist
- self.persisted_state = persisted_state.commit
+ self.persistence_state = persistence_state.commit
end
# This method executes the hooks before and after resource creation
@@ -995,7 +996,7 @@ def update_with_hooks
#
# @api private
def _destroy(execute_hooks = true)
- self.persisted_state = persisted_state.delete
+ self.persistence_state = persistence_state.delete
_persist
end
@@ -1125,8 +1126,8 @@ def cmp?(other, operator)
# @api private
def set_default_value(subject)
- return unless persisted_state.respond_to?(:set_default_value, true)
- persisted_state.__send__(:set_default_value, subject)
+ return unless persistence_state.respond_to?(:set_default_value, true)
+ persistence_state.__send__(:set_default_value, subject)
end
# Execute all the queued up hooks for a given type and name
@@ -2,7 +2,7 @@ module DataMapper
module Resource
# the state of the resource (abstract)
- class State
+ class PersistenceState
extend Equalizer
equalize :resource
@@ -70,6 +70,6 @@ def set_child_key(relationship)
set(relationship, get(relationship))
end
- end # class State
+ end # class PersistenceState
end # module Resource
end # module DataMapper
@@ -1,17 +1,17 @@
module DataMapper
module Resource
- class State
+ class PersistenceState
# a persisted/unmodified resource
class Clean < Persisted
def set(subject, value)
if not_modified?(subject, value)
self
else
- # assign to persisted_state so that if Dirty#set calls
+ # assign to persistence_state so that if Dirty#set calls
# a Relationship#set, which modifies a Property, the same
# Dirty state instance will be reused.
- state = resource.persisted_state = Dirty.new(resource)
+ state = resource.persistence_state = Dirty.new(resource)
state.set(subject, value)
end
end
@@ -35,6 +35,6 @@ def not_modified?(subject, value)
end
end # class Clean
- end # class State
+ end # class PersistenceState
end # module Resource
end # module DataMapper
@@ -1,6 +1,6 @@
module DataMapper
module Resource
- class State
+ class PersistenceState
# a persisted/deleted resource
class Deleted < Persisted
@@ -25,6 +25,6 @@ def delete_resource
end
end # class Deleted
- end # class State
+ end # class PersistenceState
end # module Resource
end # module DataMapper
@@ -1,6 +1,6 @@
module DataMapper
module Resource
- class State
+ class PersistenceState
# a persisted/dirty resource
class Dirty < Persisted
@@ -91,6 +91,6 @@ def valid_attributes?
end
end # class Dirty
- end # class State
+ end # class PersistenceState
end # module Resource
end # module DataMapper
@@ -1,9 +1,9 @@
module DataMapper
module Resource
- class State
+ class PersistenceState
# a not-persisted/unmodifiable resource
- class Immutable < State
+ class Immutable < PersistenceState
def get(subject, *args)
unless subject.loaded?(resource) || subject.kind_of?(Associations::Relationship)
raise ImmutableError, 'Immutable resource cannot be lazy loaded'
@@ -29,6 +29,6 @@ def rollback
end
end # class Immutable
- end # class State
+ end # class PersistenceState
end # module Resource
end # module DataMapper
@@ -1,9 +1,9 @@
module DataMapper
module Resource
- class State
+ class PersistenceState
# a persisted resource (abstract)
- class Persisted < State
+ class Persisted < PersistenceState
def get(subject, *args)
lazy_load(subject)
super
@@ -24,6 +24,6 @@ def lazy_load(subject)
end
end # class Persisted
- end # class State
+ end # class PersistenceState
end # module Resource
end # module DataMapper
Oops, something went wrong.

0 comments on commit 5c5690d

Please sign in to comment.