lib/active_remote/base.rb in active_remote-2.4.0 vs lib/active_remote/base.rb in active_remote-3.0.0.pre1
- old
+ new
@@ -1,79 +1,84 @@
require 'active_model/callbacks'
-require 'active_attr/model'
require 'active_remote/association'
-require 'active_remote/attribute_defaults'
+require 'active_remote/attribute_assignment'
+require 'active_remote/attribute_definition'
require 'active_remote/attributes'
-require 'active_remote/bulk'
require 'active_remote/config'
require 'active_remote/dirty'
require 'active_remote/dsl'
require 'active_remote/integration'
require 'active_remote/persistence'
require 'active_remote/primary_key'
-require 'active_remote/publication'
+require 'active_remote/query_attributes'
require 'active_remote/rpc'
require 'active_remote/scope_keys'
require 'active_remote/search'
require 'active_remote/serialization'
require 'active_remote/typecasting'
require 'active_remote/validations'
module ActiveRemote
class Base
- extend ActiveModel::Callbacks
+ extend ::ActiveModel::Callbacks
+ extend ::ActiveModel::Naming
- include ActiveAttr::BasicModel
- include ActiveAttr::Attributes
- include ActiveAttr::BlockInitialization
- include ActiveAttr::ChainableInitialization
- include ActiveAttr::Logger
- include ActiveAttr::MassAssignment
- include ActiveAttr::AttributeDefaults
- include ActiveAttr::QueryAttributes
- include ActiveAttr::Serialization
+ include ::ActiveModel::Conversion
+ include ::ActiveModel::Validations
- include Association
- include AttributeDefaults
- include Attributes
- include Bulk
- include DSL
- include Integration
- include Persistence
- include PrimaryKey
- include Publication
- include RPC
- include ScopeKeys
- include Search
- include Serialization
- include Typecasting
+ include ::ActiveRemote::Association
+ include ::ActiveRemote::AttributeAssignment
+ include ::ActiveRemote::Attributes
+ include ::ActiveRemote::DSL
+ include ::ActiveRemote::Integration
+ include ::ActiveRemote::Persistence
+ include ::ActiveRemote::PrimaryKey
+ include ::ActiveRemote::QueryAttributes
+ include ::ActiveRemote::RPC
+ include ::ActiveRemote::ScopeKeys
+ include ::ActiveRemote::Search
+ include ::ActiveRemote::Serialization
+ include ::ActiveRemote::Typecasting
# Overrides some methods, providing support for dirty tracking,
# so it needs to be included last.
- include Dirty
+ include ::ActiveRemote::Dirty
# Overrides persistence methods, so it must included after
- include Validations
- include ActiveModel::Validations::Callbacks
+ include ::ActiveRemote::Validations
+ include ::ActiveModel::Validations::Callbacks
attr_reader :last_request, :last_response
define_model_callbacks :initialize, :only => :after
- def initialize(*)
+ def initialize(attributes = {})
@attributes ||= begin
attribute_names = self.class.attribute_names
- Hash[attribute_names.map { |key| [key, send(key)] }]
+ Hash[attribute_names.map { |key| [key, nil] }]
end
+ assign_attributes(attributes) if attributes
+
@new_record = true
skip_dirty_tracking do
run_callbacks :initialize do
- super
+ yield self if block_given?
end
end
+ end
+
+ # Initialize an object with the attributes hash directly
+ # When used with allocate, bypasses initialize
+ def init_with(attributes)
+ @attributes = attributes
+ @new_record = false
+
+ run_callbacks :initialize
+
+ self
end
def freeze
@attributes.freeze; self
end