metasploit-model 0.27.3-java → 0.27.4-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -1
- data/app/models/metasploit/model/association/reflection.rb +0 -3
- data/app/models/metasploit/model/module/ancestor/spec/template.rb +0 -3
- data/app/models/metasploit/model/module/class/spec/template.rb +0 -4
- data/app/models/metasploit/model/module/instance/spec/template.rb +0 -4
- data/app/models/metasploit/model/search/group/base.rb +0 -3
- data/app/models/metasploit/model/search/group/intersection.rb +0 -3
- data/app/models/metasploit/model/search/group/union.rb +0 -3
- data/app/models/metasploit/model/search/operation/association.rb +0 -2
- data/app/models/metasploit/model/search/operation/base.rb +0 -3
- data/app/models/metasploit/model/search/operation/boolean.rb +0 -2
- data/app/models/metasploit/model/search/operation/date.rb +0 -2
- data/app/models/metasploit/model/search/operation/group/base.rb +0 -2
- data/app/models/metasploit/model/search/operation/group/intersection.rb +0 -2
- data/app/models/metasploit/model/search/operation/group/union.rb +0 -2
- data/app/models/metasploit/model/search/operation/integer.rb +1 -5
- data/app/models/metasploit/model/search/operation/null.rb +0 -2
- data/app/models/metasploit/model/search/operation/set.rb +5 -2
- data/app/models/metasploit/model/search/operation/set/integer.rb +1 -3
- data/app/models/metasploit/model/search/operation/set/string.rb +1 -3
- data/app/models/metasploit/model/search/operation/string.rb +1 -5
- data/app/models/metasploit/model/search/operator/association.rb +0 -2
- data/app/models/metasploit/model/search/operator/attribute.rb +0 -2
- data/app/models/metasploit/model/search/operator/base.rb +0 -4
- data/app/models/metasploit/model/search/operator/delegation.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/app.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/author.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/authority.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/platform.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/ref.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/text.rb +0 -2
- data/app/models/metasploit/model/search/operator/group/base.rb +0 -2
- data/app/models/metasploit/model/search/operator/group/intersection.rb +0 -2
- data/app/models/metasploit/model/search/operator/group/union.rb +0 -2
- data/app/models/metasploit/model/search/operator/null.rb +0 -2
- data/app/models/metasploit/model/search/operator/single.rb +0 -2
- data/app/models/metasploit/model/search/query.rb +0 -3
- data/app/models/metasploit/model/spec/template.rb +0 -3
- data/app/models/metasploit/model/visitation/visitor.rb +0 -3
- data/lib/metasploit/model.rb +14 -8
- data/lib/metasploit/model/architecture.rb +320 -326
- data/lib/metasploit/model/association.rb +43 -46
- data/lib/metasploit/model/association/error.rb +29 -33
- data/lib/metasploit/model/association/tree.rb +119 -125
- data/lib/metasploit/model/author.rb +45 -51
- data/lib/metasploit/model/authority.rb +139 -146
- data/lib/metasploit/model/authority/bid.rb +0 -2
- data/lib/metasploit/model/authority/cve.rb +0 -2
- data/lib/metasploit/model/authority/msb.rb +0 -2
- data/lib/metasploit/model/authority/osvdb.rb +0 -2
- data/lib/metasploit/model/authority/pmasa.rb +0 -2
- data/lib/metasploit/model/authority/secunia.rb +0 -2
- data/lib/metasploit/model/authority/us_cert_vu.rb +0 -2
- data/lib/metasploit/model/authority/waraxe.rb +0 -2
- data/lib/metasploit/model/authority/zdi.rb +0 -2
- data/lib/metasploit/model/base.rb +0 -2
- data/lib/metasploit/model/derivation.rb +95 -99
- data/lib/metasploit/model/derivation/full_name.rb +16 -22
- data/lib/metasploit/model/email_address.rb +122 -128
- data/lib/metasploit/model/engine.rb +26 -21
- data/lib/metasploit/model/error.rb +3 -7
- data/lib/metasploit/model/file.rb +0 -2
- data/lib/metasploit/model/invalid.rb +11 -17
- data/lib/metasploit/model/login.rb +0 -3
- data/lib/metasploit/model/login/status.rb +0 -2
- data/lib/metasploit/model/module.rb +19 -23
- data/lib/metasploit/model/module/action.rb +50 -58
- data/lib/metasploit/model/module/ancestor.rb +456 -465
- data/lib/metasploit/model/module/ancestor/spec.rb +3 -2
- data/lib/metasploit/model/module/architecture.rb +27 -35
- data/lib/metasploit/model/module/author.rb +38 -47
- data/lib/metasploit/model/module/class.rb +358 -366
- data/lib/metasploit/model/module/class/spec.rb +3 -2
- data/lib/metasploit/model/module/handler.rb +28 -34
- data/lib/metasploit/model/module/instance.rb +586 -596
- data/lib/metasploit/model/module/instance/spec.rb +3 -2
- data/lib/metasploit/model/module/path.rb +157 -166
- data/lib/metasploit/model/module/platform.rb +25 -33
- data/lib/metasploit/model/module/rank.rb +71 -79
- data/lib/metasploit/model/module/reference.rb +25 -33
- data/lib/metasploit/model/module/stance.rb +15 -21
- data/lib/metasploit/model/module/target.rb +76 -84
- data/lib/metasploit/model/module/target/architecture.rb +27 -37
- data/lib/metasploit/model/module/target/platform.rb +27 -37
- data/lib/metasploit/model/module/type.rb +35 -41
- data/lib/metasploit/model/nilify_blanks.rb +39 -43
- data/lib/metasploit/model/platform.rb +231 -237
- data/lib/metasploit/model/real_pathname.rb +12 -16
- data/lib/metasploit/model/realm.rb +0 -2
- data/lib/metasploit/model/realm/key.rb +0 -2
- data/lib/metasploit/model/reference.rb +102 -108
- data/lib/metasploit/model/search.rb +94 -97
- data/lib/metasploit/model/search/association.rb +163 -169
- data/lib/metasploit/model/search/attribute.rb +131 -139
- data/lib/metasploit/model/search/group.rb +5 -2
- data/lib/metasploit/model/search/operation.rb +32 -29
- data/lib/metasploit/model/search/operation/group.rb +5 -2
- data/lib/metasploit/model/search/operation/value.rb +7 -0
- data/lib/metasploit/model/search/operation/{integer/value.rb → value/integer.rb} +1 -1
- data/lib/metasploit/model/search/operation/{string/value.rb → value/string.rb} +1 -1
- data/lib/metasploit/model/search/operator.rb +65 -65
- data/lib/metasploit/model/search/operator/deprecated.rb +8 -2
- data/lib/metasploit/model/search/operator/group.rb +5 -2
- data/lib/metasploit/model/search/operator/help.rb +71 -79
- data/lib/metasploit/model/search/with.rb +72 -78
- data/lib/metasploit/model/spec.rb +133 -136
- data/lib/metasploit/model/spec/error.rb +3 -9
- data/lib/metasploit/model/spec/i18n_exception_handler.rb +0 -2
- data/lib/metasploit/model/spec/pathname_collision.rb +19 -27
- data/lib/metasploit/model/spec/template/write.rb +0 -2
- data/lib/metasploit/model/spec/temporary_pathname.rb +47 -56
- data/lib/metasploit/model/translation.rb +0 -2
- data/lib/metasploit/model/version.rb +1 -1
- data/lib/metasploit/model/visitation.rb +7 -10
- data/lib/metasploit/model/visitation/visit.rb +79 -85
- data/metasploit-model.gemspec +1 -1
- data/spec/app/models/metasploit/model/search/operation/integer_spec.rb +1 -1
- data/spec/app/models/metasploit/model/search/operation/set/integer_spec.rb +1 -1
- data/spec/app/models/metasploit/model/search/operation/set/string_spec.rb +1 -1
- data/spec/app/models/metasploit/model/search/operation/string_spec.rb +1 -1
- data/spec/dummy/config/application.rb +1 -0
- data/spec/lib/metasploit/model/search/operation/{integer/value_spec.rb → value/integer_spec.rb} +2 -2
- data/spec/lib/metasploit/model/search/operation/{string/value_spec.rb → value/string_spec.rb} +2 -2
- data/spec/support/shared/examples/metasploit/model/search/operation/{integer/value.rb → value/integer.rb} +2 -2
- data/spec/support/shared/examples/metasploit/model/search/operation/{string/value.rb → value/string.rb} +2 -2
- metadata +16 -13
@@ -1,148 +1,141 @@
|
|
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
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
def extension
|
122
|
-
begin
|
123
|
-
extension_name.constantize
|
124
|
-
rescue NameError
|
125
|
-
nil
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
# Returns name of module that includes authority specific methods.
|
130
|
-
#
|
131
|
-
# @return [String] unless {#abbreviation} is blank.
|
132
|
-
# @return [nil] if {#abbreviation} is blank.
|
133
|
-
def extension_name
|
134
|
-
extension_name = nil
|
135
|
-
|
136
|
-
unless abbreviation.blank?
|
137
|
-
# underscore before camelize to eliminate -'s
|
138
|
-
relative_model_name = abbreviation.underscore.camelize
|
139
|
-
# don't scope to self.class.name so that authority extension are always resolved the same in Mdm and
|
140
|
-
# Metasploit::Framework.
|
141
|
-
extension_name = "Metasploit::Model::Authority::#{relative_model_name}"
|
142
|
-
end
|
143
|
-
|
144
|
-
extension_name
|
145
|
-
end
|
1
|
+
# Code shared between `Mdm::Authority` and `Metasploit::Framework::Authority`.
|
2
|
+
module Metasploit::Model::Authority
|
3
|
+
extend ActiveModel::Naming
|
4
|
+
extend ActiveSupport::Autoload
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
include Metasploit::Model::Translation
|
8
|
+
|
9
|
+
autoload :Bid
|
10
|
+
autoload :Cve
|
11
|
+
autoload :Msb
|
12
|
+
autoload :Osvdb
|
13
|
+
autoload :Pmasa
|
14
|
+
autoload :Secunia
|
15
|
+
autoload :UsCertVu
|
16
|
+
autoload :Waraxe
|
17
|
+
autoload :Zdi
|
18
|
+
|
19
|
+
included do
|
20
|
+
include ActiveModel::MassAssignmentSecurity
|
21
|
+
include ActiveModel::Validations
|
22
|
+
include Metasploit::Model::Search
|
23
|
+
|
24
|
+
#
|
25
|
+
# Mass Assignment Security
|
26
|
+
#
|
27
|
+
|
28
|
+
attr_accessible :abbreviation
|
29
|
+
attr_accessible :obsolete
|
30
|
+
attr_accessible :summary
|
31
|
+
attr_accessible :url
|
32
|
+
|
33
|
+
#
|
34
|
+
# Search Attributes
|
35
|
+
#
|
36
|
+
|
37
|
+
search_attribute :abbreviation, :type => :string
|
38
|
+
|
39
|
+
#
|
40
|
+
# Validations
|
41
|
+
#
|
42
|
+
|
43
|
+
validates :abbreviation,
|
44
|
+
:presence => true
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Associations
|
49
|
+
#
|
50
|
+
|
51
|
+
# @!attribute [rw] references
|
52
|
+
# {Metasploit::Model::Reference References} that use this authority's scheme for their
|
53
|
+
# {Metasploit::Model::Reference#authority}.
|
54
|
+
#
|
55
|
+
# @return [Array<Metasploit::Model::Reference>]
|
56
|
+
|
57
|
+
# @!attribute [r] module_instances
|
58
|
+
# {Metasploit::Model::Module::Instance Modules} that have a reference with this authority.
|
59
|
+
#
|
60
|
+
# @return [Array<Metasploit::Model::Module::Instance>]
|
61
|
+
|
62
|
+
# @!attribute [r] vulns
|
63
|
+
# Vulnerabilities that have a reference under this authority.
|
64
|
+
#
|
65
|
+
# @return [Array<Metasploit::Model::Vuln>]
|
66
|
+
|
67
|
+
#
|
68
|
+
# Attributes
|
69
|
+
#
|
70
|
+
|
71
|
+
# @!attribute [rw] abbreviation
|
72
|
+
# Abbreviation or initialism for authority, such as CVE for 'Common Vulnerability and Exposures'.
|
73
|
+
#
|
74
|
+
# @return [String]
|
75
|
+
|
76
|
+
# @!attribute [rw] obsolete
|
77
|
+
# Whether this authority is obsolete and no longer exists on the internet.
|
78
|
+
#
|
79
|
+
# @return [false]
|
80
|
+
# @return [true] {#url} may be `nil` because authory no longer has a web site.
|
81
|
+
|
82
|
+
# @!attribute [rw] summary
|
83
|
+
# An expansion of the {#abbreviation}.
|
84
|
+
#
|
85
|
+
# @return [String, nil]
|
86
|
+
|
87
|
+
# @!attribute [rw] url
|
88
|
+
# URL to the authority's home page or root URL for their {#references} database.
|
89
|
+
#
|
90
|
+
# @return [String, nil]
|
91
|
+
|
92
|
+
#
|
93
|
+
# Instance Methods
|
94
|
+
#
|
95
|
+
|
96
|
+
# Returns the {Metasploit::Model::Reference#url URL} for a {Metasploit::Model::Reference#designation designation}.
|
97
|
+
#
|
98
|
+
# @param designation [String] {Metasploit::Model::Reference#designation}.
|
99
|
+
# @return [String] {Metasploit::Model::Reference#url}
|
100
|
+
# @return [nil] if this {Metasploit::Model::Authority} is {#obsolete}.
|
101
|
+
# @return [nil] if this {Metasploit::Model::Authority} does have a way to derive URLS from designations.
|
102
|
+
def designation_url(designation)
|
103
|
+
url = nil
|
104
|
+
|
105
|
+
if extension
|
106
|
+
url = extension.designation_url(designation)
|
107
|
+
end
|
108
|
+
|
109
|
+
url
|
110
|
+
end
|
111
|
+
|
112
|
+
# Returns module that include authority specific methods.
|
113
|
+
#
|
114
|
+
# @return [Module] if {#abbreviation} has a corresponding module under the Metasploit::Model::Authority namespace.
|
115
|
+
# @return [nil] otherwise.
|
116
|
+
def extension
|
117
|
+
begin
|
118
|
+
extension_name.constantize
|
119
|
+
rescue NameError
|
120
|
+
nil
|
146
121
|
end
|
147
122
|
end
|
148
|
-
|
123
|
+
|
124
|
+
# Returns name of module that includes authority specific methods.
|
125
|
+
#
|
126
|
+
# @return [String] unless {#abbreviation} is blank.
|
127
|
+
# @return [nil] if {#abbreviation} is blank.
|
128
|
+
def extension_name
|
129
|
+
extension_name = nil
|
130
|
+
|
131
|
+
unless abbreviation.blank?
|
132
|
+
# underscore before camelize to eliminate -'s
|
133
|
+
relative_model_name = abbreviation.underscore.camelize
|
134
|
+
# don't scope to self.class.name so that authority extension are always resolved the same in Mdm and
|
135
|
+
# Metasploit::Framework.
|
136
|
+
extension_name = "Metasploit::Model::Authority::#{relative_model_name}"
|
137
|
+
end
|
138
|
+
|
139
|
+
extension_name
|
140
|
+
end
|
141
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'metasploit/model/authority'
|
2
|
-
|
3
1
|
# United States Computer Emergency Readiness Team Vulnerability Notes Database authority-specific code.
|
4
2
|
module Metasploit::Model::Authority::UsCertVu
|
5
3
|
# Returns URL to {Metasploit::Model::Reference#designation Vul ID's} page on US CERT Notes Database.
|
@@ -1,113 +1,109 @@
|
|
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
|
-
extend ActiveSupport::Autoload
|
50
|
-
extend ActiveSupport::Concern
|
1
|
+
# Allow to declare that attributes should be derived, which will set the attribute equal to derived_<attribute> if
|
2
|
+
# the attribute is `nil` before validation. Optionally, it can be checked if the attribute matches the
|
3
|
+
# derived_<attribute> in a validation.
|
4
|
+
#
|
5
|
+
#
|
6
|
+
# @example Full setup
|
7
|
+
# class Person < ActiveRecord::Base
|
8
|
+
# include Metasploit::Model::Derivation
|
9
|
+
#
|
10
|
+
# #
|
11
|
+
# # Attributes
|
12
|
+
# #
|
13
|
+
#
|
14
|
+
# # @!attributes [rw] first_name
|
15
|
+
# # First Name.
|
16
|
+
# #
|
17
|
+
# # @return [String]
|
18
|
+
#
|
19
|
+
# # @!attribute [rw] full_name
|
20
|
+
# # Full name. (Includes first and last name).
|
21
|
+
# #
|
22
|
+
# # @return [String]
|
23
|
+
#
|
24
|
+
# # @!attribute [rw] last_name
|
25
|
+
# # Last name.
|
26
|
+
# #
|
27
|
+
# # @return [String]
|
28
|
+
#
|
29
|
+
# #
|
30
|
+
# # Derivations
|
31
|
+
# #
|
32
|
+
#
|
33
|
+
# derives :full_name
|
34
|
+
#
|
35
|
+
# #
|
36
|
+
# # Methods
|
37
|
+
# #
|
38
|
+
#
|
39
|
+
# # Derives {#full_name} from {#first_name} and {#last_name}.
|
40
|
+
# #
|
41
|
+
# # @return [String] "<first_name> <last_name>"
|
42
|
+
# def derive_full_name
|
43
|
+
# "#{first_name} #{last_name}"
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
module Metasploit::Model::Derivation
|
47
|
+
extend ActiveSupport::Autoload
|
48
|
+
extend ActiveSupport::Concern
|
51
49
|
|
52
|
-
|
50
|
+
autoload :FullName
|
53
51
|
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
included do
|
53
|
+
include ActiveModel::Validations
|
54
|
+
include ActiveModel::Validations::Callbacks
|
57
55
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
# Defines class methods include {#derives}, which can be used to declare derived attributes after mixing in
|
62
|
-
# {Metasploit::Model::Derivation}.
|
63
|
-
module ClassMethods
|
64
|
-
# Declares that the attribute should be derived using the derived_<attribute> method if it is `nil` before
|
65
|
-
# validation.
|
66
|
-
#
|
67
|
-
# @param attribute [Symbol] the name of the attribute.
|
68
|
-
# @param options [Hash{Symbol => Boolean}]
|
69
|
-
# @option options [Boolean] :validate (false) If `true`, validates `attribute` using {DerivationValidator}. If
|
70
|
-
# `false`, does no validation on `attribute`.
|
71
|
-
# @return [void]
|
72
|
-
def derives(attribute, options={})
|
73
|
-
options.assert_valid_keys(:validate)
|
56
|
+
before_validation :derive
|
57
|
+
end
|
74
58
|
|
75
|
-
|
76
|
-
|
59
|
+
# Defines class methods include {#derives}, which can be used to declare derived attributes after mixing in
|
60
|
+
# {Metasploit::Model::Derivation}.
|
61
|
+
module ClassMethods
|
62
|
+
# Declares that the attribute should be derived using the derived_<attribute> method if it is `nil` before
|
63
|
+
# validation.
|
64
|
+
#
|
65
|
+
# @param attribute [Symbol] the name of the attribute.
|
66
|
+
# @param options [Hash{Symbol => Boolean}]
|
67
|
+
# @option options [Boolean] :validate (false) If `true`, validates `attribute` using {DerivationValidator}. If
|
68
|
+
# `false`, does no validation on `attribute`.
|
69
|
+
# @return [void]
|
70
|
+
def derives(attribute, options={})
|
71
|
+
options.assert_valid_keys(:validate)
|
77
72
|
|
78
|
-
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
73
|
+
validate = options.fetch(:validate, false)
|
74
|
+
validate_by_derived_attribute[attribute] = validate
|
82
75
|
|
83
|
-
|
84
|
-
|
85
|
-
# @return [Hash{Symbol => Boolean}]
|
86
|
-
def validate_by_derived_attribute
|
87
|
-
@validate_by_derived_attribute ||= {}
|
88
|
-
end
|
76
|
+
if validate
|
77
|
+
validates attribute, :derivation => true
|
89
78
|
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Maps a derived attribute (declared with {#derives}) to whether the attribute should validate as a derivation.
|
82
|
+
#
|
83
|
+
# @return [Hash{Symbol => Boolean}]
|
84
|
+
def validate_by_derived_attribute
|
85
|
+
@validate_by_derived_attribute ||= {}
|
86
|
+
end
|
87
|
+
end
|
90
88
|
|
91
|
-
|
92
|
-
|
93
|
-
|
89
|
+
#
|
90
|
+
# Instance Methods
|
91
|
+
#
|
94
92
|
|
95
|
-
|
93
|
+
private
|
96
94
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
95
|
+
# Derives each attribute in {ClassMethods#validate_by_derived_attribute} if the attribute is `nil`.
|
96
|
+
#
|
97
|
+
# @return [void]
|
98
|
+
def derive
|
99
|
+
self.class.validate_by_derived_attribute.each_key do |attribute|
|
100
|
+
value = send(attribute)
|
103
101
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
109
|
-
end
|
102
|
+
# explicitly check for `nil` in case attribute is Boolean
|
103
|
+
if value.nil?
|
104
|
+
derived_value = send("derived_#{attribute}")
|
105
|
+
send("#{attribute}=", derived_value)
|
110
106
|
end
|
111
107
|
end
|
112
108
|
end
|
113
|
-
end
|
109
|
+
end
|