Class: ActiveRemote::Base

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Callbacks
Includes:
ActiveModel::Model, ActiveModel::Validations::Callbacks, Association, Attributes, DSL, Dirty, Integration, Persistence, PrimaryKey, QueryAttributes, RPC, ScopeKeys, Search, Serialization, Validations
Defined in:
lib/active_remote/base.rb

Instance Method Summary collapse

Methods included from Validations

#save, #save!, #valid?

Methods included from Dirty

#disable_dirty_tracking, #enable_dirty_tracking, #reload, #remote, #save, #save!, #skip_dirty_tracking

Methods included from Serialization

#add_errors

Methods included from Search

#reload

Methods included from ScopeKeys

#scope_key_hash, #scope_keys

Methods included from RPC

#assign_attributes_from_rpc, #remote_call, #rpc

Methods included from QueryAttributes

#query_attribute

Methods included from PrimaryKey

#primary_key

Methods included from Persistence

#delete, #delete!, #destroy, #destroy!, #has_errors?, #instantiate, #new_record?, #persisted?, #readonly!, #readonly?, #remote, #save, #save!, #success?, #update_attribute, #update_attributes, #update_attributes!

Methods included from Integration

#cache_key, #to_param

Methods included from Attributes

#==, #attribute, #attribute=, #attribute_method?, #attributes, #inspect, #read_attribute, #write_attribute

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/active_remote/base.rb', line 47

def initialize(attributes = {})
  @attributes = self.class.send(:default_attributes_hash).dup

  assign_attributes(attributes) if attributes

  @new_record = true

  skip_dirty_tracking do
    run_callbacks :initialize do
      yield self if block_given?
    end
  end
end

Instance Method Details

#freezeObject



72
73
74
75
# File 'lib/active_remote/base.rb', line 72

def freeze
  @attributes.freeze
  self
end

#frozen?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/active_remote/base.rb', line 77

def frozen?
  @attributes.frozen?
end

#init_with(attributes) ⇒ Object

Initialize an object with the attributes hash directly When used with allocate, bypasses initialize



63
64
65
66
67
68
69
70
# File 'lib/active_remote/base.rb', line 63

def init_with(attributes)
  @attributes = attributes
  @new_record = false

  run_callbacks :initialize

  self
end