metasploit-model 0.27.3 → 0.27.4

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