Module: Datapathy::Model
- Extended by:
- ActiveModel::Naming, ActiveSupport::Concern
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations, Crud, DynamicFinders
- Included in:
- Service
- Defined in:
- lib/datapathy/model.rb,
lib/datapathy/model/crud.rb,
lib/datapathy/model/dynamic_finders.rb
Defined Under Namespace
Modules: ClassMethods, Crud, DynamicFinders
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Crud
#create, #delete, #save, #update
Instance Attribute Details
#new_record ⇒ Object
Returns the value of attribute new_record.
24
25
26
|
# File 'lib/datapathy/model.rb', line 24
def new_record
@new_record
end
|
Instance Method Details
#==(other) ⇒ Object
60
61
62
|
# File 'lib/datapathy/model.rb', line 60
def ==(other)
self.key == (other && other.key)
end
|
#adapter ⇒ Object
68
69
70
|
# File 'lib/datapathy/model.rb', line 68
def adapter
self.class.adapter
end
|
#initialize(attributes = {}) ⇒ Object
26
27
28
29
30
|
# File 'lib/datapathy/model.rb', line 26
def initialize(attributes = {})
@attributes = {}
merge(attributes)
@new_record = true
end
|
#key ⇒ Object
48
49
50
|
# File 'lib/datapathy/model.rb', line 48
def key
send(self.class.key)
end
|
#key=(value) ⇒ Object
52
53
54
|
# File 'lib/datapathy/model.rb', line 52
def key=(value)
send(:"#{self.class.key}=", value)
end
|
#merge(attributes = {}) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/datapathy/model.rb', line 36
def merge(attributes = {})
attributes.each do |name, value|
method = :"#{name}="
send(method, value) if respond_to?(method)
end
end
|
#merge!(attributes = {}) ⇒ Object
43
44
45
46
|
# File 'lib/datapathy/model.rb', line 43
def merge!(attributes = {})
@attributes = @attributes || {}
@attributes.merge!(attributes)
end
|
#model ⇒ Object
56
57
58
|
# File 'lib/datapathy/model.rb', line 56
def model
self.class
end
|
#new_record? ⇒ Boolean
64
65
66
|
# File 'lib/datapathy/model.rb', line 64
def new_record?
@new_record
end
|
#persisted_attributes ⇒ Object
32
33
34
|
# File 'lib/datapathy/model.rb', line 32
def persisted_attributes
@attributes
end
|
#valid? ⇒ Boolean
override the ActiveModel::Validations one, because its dumb
73
74
75
76
|
# File 'lib/datapathy/model.rb', line 73
def valid?
_run_validate_callbacks if errors.empty?
errors.empty?
end
|