-
Notifications
You must be signed in to change notification settings - Fork 0
/
active_model_template.rb
92 lines (68 loc) · 1.74 KB
/
active_model_template.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
class ActiveModelTemplate
# ActiveAttr::Model
# includes from ActiveAttr:
# ActiveAttr::BasicModel
# ActiveAttr::Attributes
# ActiveAttr::AttributeDefaults
# ActiveAttr::QueryAttributes
# ActiveAttr::Typecasting
# ActiveAttr::TypecastedAttributes
# ActiveAttr::Logger
# ActiveAttr::ChainableInitialization
# ActiveAttr::BlockInitialization
# ActiveAttr::MassAssignment
# ActiveAttr::MassAssignmentSecurity
# includes from ActiveModel:
# ActiveModel::Naming
# ActiveModel::AttributeMethods
# ActiveModel::Conversion
# ActiveModel::Validations
# ActiveModel::Translation
# ActiveModel::MassAssignmentSecurity
# ActiveModel::Serialization
# ActiveModel::Serializers::JSON
# ActiveModel::Serializers::Xml
include ActiveAttr::Model
include ActiveModel::Dirty
extend ActiveModel::Callbacks
#### ATTRIBUTES ####
attribute :model_length, :type => Integer, :default => "Some title"
attr_reader :errors
#### VALIDATIONS ####
#### CALLBACKS ####
# Provides before, around, and after callbacks for create
define_model_callbacks :create, :validation
before_validation do
end
after_validation do
end
before_create do
end
after_create do
end
#### METHODS ####
def initialize(*)
super
@errors = ActiveModel::Errors.new(self)
end
def create
if valid?
run_callbacks :create do
# Your create action methods here
true
end
else
false
end
end
def persisted?
false
end
protected
def run_validations!
run_callbacks :validation do
run_callbacks :validate
errors.empty?
end
end
end