Module: ObjectAttorney
- Included in:
- Base
- Defined in:
- lib/object_attorney.rb,
lib/object_attorney/base.rb,
lib/object_attorney/errors.rb,
lib/object_attorney/helpers.rb,
lib/object_attorney/version.rb,
lib/object_attorney/accusation.rb,
lib/object_attorney/allegation.rb,
lib/object_attorney/class_methods.rb,
lib/object_attorney/validations/custom.rb
Defined Under Namespace
Modules: ClassMethods, Errors, Helpers, Validations
Classes: Accusation, Allegation, Base
Constant Summary
collapse
- VERSION =
'3.2.0'.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base_class) ⇒ Object
8
9
10
11
|
# File 'lib/object_attorney.rb', line 8
def self.included(base_class)
base_class.extend ClassMethods
base_class.extend ActiveModel::Validations::HelperMethods
end
|
Instance Method Details
#defendant ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/object_attorney.rb', line 13
def defendant
@defendant ||=
if parent_defendant
Helpers.extend_errors_if_necessary(parent_defendant)
Helpers.call_method!(parent_defendant, defendant_options[:name])
else
Helpers.call_method!(self, defendant_options[:name])
end
end
|
#defendant_is_innocent? ⇒ Boolean
Also known as:
valid?
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/object_attorney.rb', line 24
def defendant_is_innocent?
raise Errors::NoDefendantToDefendError if defendant_options.empty?
proven_innocent = [defendant].flatten.compact.map do |defendant|
innocent_of_all_accusations?(defendant)
end.all?
make_the_parent_guilty unless proven_innocent
proven_innocent
end
|
#invalid? ⇒ Boolean
38
39
40
|
# File 'lib/object_attorney.rb', line 38
def invalid?
!valid?
end
|