Class: Cardiac::Model::Base
- Inherits:
-
Object
- Object
- Cardiac::Model::Base
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
Declarations::RESOURCE_EXTENSION_BLOCK
Constants included
from Callbacks
Callbacks::CALLBACKS
Class Method Summary
collapse
Instance Method Summary
collapse
cache, uncached
#base_resource
#resource, #with_resource
Methods included from Callbacks
#destroy
Methods included from Dirty
#reload, #save, #save!
#assign_remote_errors, #remote_errors, #save, #save!, #valid?
#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.
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_scope ⇒ Object
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
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?
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
77
78
79
|
# File 'lib/cardiac/model/base.rb', line 77
def encode_with(coder)
coder['attributes'] = attributes
end
|
#freeze ⇒ Object
96
97
98
99
|
# File 'lib/cardiac/model/base.rb', line 96
def freeze
@attributes = @attributes.clone.freeze
self
end
|
#frozen? ⇒ Boolean
102
103
104
|
# File 'lib/cardiac/model/base.rb', line 102
def frozen?
@attributes.frozen?
end
|
#hash ⇒ Object
91
92
93
|
# File 'lib/cardiac/model/base.rb', line 91
def hash
id.hash
end
|
#init_with(coder) ⇒ Object
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
|
#inspect ⇒ Object
72
73
74
|
# File 'lib/cardiac/model/base.rb', line 72
def inspect
defined?(@attributes) && @attributes ? super : "#<#{self.class} not initialized>"
end
|
#readonly! ⇒ Object
119
120
121
|
# File 'lib/cardiac/model/base.rb', line 119
def readonly!
@readonly = true
end
|
#readonly? ⇒ Boolean
114
115
116
|
# File 'lib/cardiac/model/base.rb', line 114
def readonly?
@readonly
end
|
#slice(*methods) ⇒ Object
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
|