Class: Cardiac::Model::Base

Inherits:
Object
  • Object
show all
Extended by:
ResourceCache::ClassMethods
Includes:
ActiveAttr::Model, ActiveSupport::Configurable, Attributes, CacheDecoration, Callbacks, Declarations, Dirty, Operations, Persistence, Querying, Validations
Defined in:
lib/cardiac/model/base.rb

Constant Summary

Constants included from Declarations

Declarations::RESOURCE_EXTENSION_BLOCK

Constants included from Callbacks

Callbacks::CALLBACKS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ResourceCache::ClassMethods

cache, uncached

Methods included from Declarations

#base_resource

Methods included from DeclarationMethods

#resource, #with_resource

Methods included from Callbacks

#destroy

Methods included from Dirty

#reload, #save, #save!

Methods included from Validations

#assign_remote_errors, #remote_errors, #save, #save!, #valid?

Methods included from Persistence

#delete, #destroy, #destroy!, #destroyed?, #new_record?, #persisted?, #reload, #save, #save!, #update, #update!, #update_attribute

Methods included from Attributes

#id, #remote_attributes, #to_key, #typecast_attribute

Constructor Details

#initialize(attributes = nil, options = {}) ⇒ Base

Returns a new instance of Base.

See Also:

  • ActiveRecord::Core#initialize


42
43
44
45
46
47
# File 'lib/cardiac/model/base.rb', line 42

def initialize(attributes = nil, options = {})
  super
  init_internals
  init_changed_attributes
  run_callbacks :initialize unless _initialize_callbacks.empty?
end

Class Method Details

.i18n_scopeObject

Subclasses have an internationalization scope separate from active model.



37
38
39
# File 'lib/cardiac/model/base.rb', line 37

def self.i18n_scope
  :cardiac_model
end

Instance Method Details

#<=>(other_object) ⇒ Object

See Also:

  • ActiveRecord::Core#<=>


107
108
109
110
111
# File 'lib/cardiac/model/base.rb', line 107

def <=>(other_object)
  if other_object.is_a?(self.class)
    self.to_key <=> other_object.to_key
  end
end

#==(comparison_object) ⇒ Object Also known as: eql?

See Also:

  • ActiveRecord::Core#==


82
83
84
85
86
87
# File 'lib/cardiac/model/base.rb', line 82

def ==(comparison_object)
  super ||
    comparison_object.instance_of?(self.class) &&
    id.present? &&
    comparison_object.id == id
end

#encode_with(coder) ⇒ Object

See Also:

  • ActiveRecord::Core#encode_with


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

def encode_with(coder)
  coder['attributes'] = attributes
end

#freezeObject

See Also:

  • ActiveRecord::Core#freeze


96
97
98
99
# File 'lib/cardiac/model/base.rb', line 96

def freeze
  @attributes = @attributes.clone.freeze
  self
end

#frozen?Boolean

Returns:

  • (Boolean)

See Also:

  • ActiveRecord::Core#frozen


102
103
104
# File 'lib/cardiac/model/base.rb', line 102

def frozen?
  @attributes.frozen?
end

#hashObject

See Also:

  • ActiveRecord::Core#hash


91
92
93
# File 'lib/cardiac/model/base.rb', line 91

def hash
  id.hash
end

#init_with(coder) ⇒ Object

See Also:

  • ActiveRecord::Core#init_with


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cardiac/model/base.rb', line 50

def init_with(coder)
  _remote = coder['remote']
  self.attributes = _remote ? {} : coder['attributes']
  init_internals
  @new_record = false
  if _remote
    _remote = {} unless Hash===_remote
    self.attributes = decode_remote_attributes( unwrap_remote_attributes(coder['attributes'], _remote),
                                                _remote )
    @changed_attributes.clear
  end
  run_callbacks :find
  run_callbacks :initialize
  self
end

#inspectObject

See Also:

  • ActiveRecord::Core#inspect


72
73
74
# File 'lib/cardiac/model/base.rb', line 72

def inspect
  defined?(@attributes) && @attributes ? super : "#<#{self.class} not initialized>"
end

#readonly!Object

See Also:

  • ActiveRecord::Core#readonly!


119
120
121
# File 'lib/cardiac/model/base.rb', line 119

def readonly!
  @readonly = true
end

#readonly?Boolean

Returns:

  • (Boolean)

See Also:

  • ActiveRecord::Core#readonly?


114
115
116
# File 'lib/cardiac/model/base.rb', line 114

def readonly?
  @readonly
end

#slice(*methods) ⇒ Object

See Also:

  • ActiveRecord::Core#slice


67
68
69
# File 'lib/cardiac/model/base.rb', line 67

def slice(*methods)
  Hash[methods.map { |method| [method, public_send(method)] }].with_indifferent_access
end