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,53 +1,50 @@
1
- module Metasploit
2
- module Model
3
- # Allows registering the class name of assocations similar to ActiveRecord associations, so that ActiveModel
4
- # associations can be reflected with the same API as ActiveRecord associations.
5
- module Association
6
- extend ActiveSupport::Autoload
7
- extend ActiveSupport::Concern
1
+ # Allows registering the class name of assocations similar to ActiveRecord associations, so that ActiveModel
2
+ # associations can be reflected with the same API as ActiveRecord associations.
3
+ module Metasploit::Model::Association
4
+ extend ActiveSupport::Autoload
5
+ extend ActiveSupport::Concern
8
6
 
9
- autoload :Error
10
- autoload :Tree
7
+ autoload :Error
8
+ autoload :Reflection
9
+ autoload :Tree
11
10
 
12
- # Defines DSL for define associations on ActiveModels with {#association}, which can then be retrieved in bulk
13
- # with {#association_by_name} or a single association's reflection by name with {#reflect_on_association}.
14
- module ClassMethods
15
- # Registers an association.
16
- #
17
- # @param name [to_sym] Name of the association
18
- # @param options [Hash{Symbol => String}]
19
- # @option options [String] :class_name Name of association's class.
20
- # @return [Metasploit::Model::Association::Reflection] the reflection of the registered association.
21
- # @raise [Metasploit::Model::Invalid] if name is blank.
22
- # @raise [Metasploit::Model::Invalid] if :class_name is blank.
23
- def association(name, options={})
24
- association = Metasploit::Model::Association::Reflection.new(
25
- :model => self,
26
- :name => name.to_sym,
27
- :class_name => options[:class_name]
28
- )
29
- association.valid!
11
+ # Defines DSL for define associations on ActiveModels with {#association}, which can then be retrieved in bulk
12
+ # with {#association_by_name} or a single association's reflection by name with {#reflect_on_association}.
13
+ module ClassMethods
14
+ # Registers an association.
15
+ #
16
+ # @param name [to_sym] Name of the association
17
+ # @param options [Hash{Symbol => String}]
18
+ # @option options [String] :class_name Name of association's class.
19
+ # @return [Metasploit::Model::Association::Reflection] the reflection of the registered association.
20
+ # @raise [Metasploit::Model::Invalid] if name is blank.
21
+ # @raise [Metasploit::Model::Invalid] if :class_name is blank.
22
+ def association(name, options={})
23
+ association = Metasploit::Model::Association::Reflection.new(
24
+ :model => self,
25
+ :name => name.to_sym,
26
+ :class_name => options[:class_name]
27
+ )
28
+ association.valid!
30
29
 
31
- association_by_name[association.name] = association
32
- end
30
+ association_by_name[association.name] = association
31
+ end
33
32
 
34
- # Associations registered with {#association}.
35
- #
36
- # @return [Hash{Symbol => Metasploit::Model::Association::Reflection}] Maps
37
- # {Metasploit::Model::Association::Reflection#name} to {Metasploit::Model::Association::Reflection}.
38
- def association_by_name
39
- @association_by_name ||= {}
40
- end
33
+ # Associations registered with {#association}.
34
+ #
35
+ # @return [Hash{Symbol => Metasploit::Model::Association::Reflection}] Maps
36
+ # {Metasploit::Model::Association::Reflection#name} to {Metasploit::Model::Association::Reflection}.
37
+ def association_by_name
38
+ @association_by_name ||= {}
39
+ end
41
40
 
42
- # Returns reflection for association with the given name.
43
- #
44
- # @param name [#to_sym] name of the association whose reflection to retrieve.
45
- # @return [nil] if no association with the given `name`.
46
- # @return [Metasploit::Model::Association::Reflection] if association with the given `name`.
47
- def reflect_on_association(name)
48
- association_by_name[name.to_sym]
49
- end
50
- end
41
+ # Returns reflection for association with the given name.
42
+ #
43
+ # @param name [#to_sym] name of the association whose reflection to retrieve.
44
+ # @return [nil] if no association with the given `name`.
45
+ # @return [Metasploit::Model::Association::Reflection] if association with the given `name`.
46
+ def reflect_on_association(name)
47
+ association_by_name[name.to_sym]
51
48
  end
52
49
  end
53
- end
50
+ end
@@ -1,40 +1,36 @@
1
- module Metasploit
2
- module Model
3
- module Association
4
- # Error raised by {Metasploit::Model::Association::ClassMethods#reflect_on_association!}.
5
- class Error < Metasploit::Model::Error
6
- #
7
- # Attributes
8
- #
1
+ module Metasploit::Model::Association
2
+ # Error raised by {Metasploit::Model::Association::ClassMethods#reflect_on_association!}.
3
+ class Error < Metasploit::Model::Error
4
+ #
5
+ # Attributes
6
+ #
9
7
 
10
- # @!attribute [r] model
11
- # ActiveModel on which the association with {#name} was not found.
12
- #
13
- # @return [Class]
14
- attr_reader :model
8
+ # @!attribute [r] model
9
+ # ActiveModel on which the association with {#name} was not found.
10
+ #
11
+ # @return [Class]
12
+ attr_reader :model
15
13
 
16
- # @!attribute [r] name
17
- # Name of association that was not registered on {#model}.
18
- #
19
- # @return [Symbol]
20
- attr_reader :name
14
+ # @!attribute [r] name
15
+ # Name of association that was not registered on {#model}.
16
+ #
17
+ # @return [Symbol]
18
+ attr_reader :name
21
19
 
22
- #
23
- # Methods
24
- #
20
+ #
21
+ # Methods
22
+ #
25
23
 
26
- # @param attributes [Hash{Symbol => Object}]
27
- # @option attributes [Class] :model ActiveModel that is missing association with :name.
28
- # @option attributes [Symbol] :name name of the association that is missing.
29
- # @raise [KeyError] if :model is not given
30
- # @raise [KeyError] if :name is not given
31
- def initialize(attributes={})
32
- @model = attributes.fetch(:model)
33
- @name = attributes.fetch(:name)
24
+ # @param attributes [Hash{Symbol => Object}]
25
+ # @option attributes [Class] :model ActiveModel that is missing association with :name.
26
+ # @option attributes [Symbol] :name name of the association that is missing.
27
+ # @raise [KeyError] if :model is not given
28
+ # @raise [KeyError] if :name is not given
29
+ def initialize(attributes={})
30
+ @model = attributes.fetch(:model)
31
+ @name = attributes.fetch(:name)
34
32
 
35
- super("#{model} does not have #{name} association.")
36
- end
37
- end
33
+ super("#{model} does not have #{name} association.")
38
34
  end
39
35
  end
40
- end
36
+ end
@@ -1,130 +1,124 @@
1
- module Metasploit
2
- module Model
3
- module Association
4
- # Functions for turning a compact tree of compact as passed to
5
- # {Metasploit::Model::Search::Association::ClassMethods#search_associations} into an expanded
6
- # {Metasploit::Model::Search::Association::ClassMethods#search_association_tree}.
7
- module Tree
8
- # Expands a `compact` association into an expanded association tree.
9
- #
10
- # @param compact [Array, Hash{Symbol => Array,Hash,Symbol}, Symbol] a compact association as passed to
11
- # {Metasploit::Model::Search::Association::ClassMethods#search_associations}.
12
- # @return [Hash{Symbol => Hash,nil}]
13
- def self.expand(compact)
14
- case compact
15
- when Array
16
- compact.reduce({}) { |hash, association|
17
- hash.merge(expand(association))
18
- }
19
- when Hash
20
- child_by_parent = compact
21
-
22
- child_by_parent.each_with_object({}) { |(parent, child), hash|
23
- hash[parent] = expand(child)
24
- }
25
- when Symbol
26
- association = compact
27
-
28
- {association => nil}
29
- end
30
- end
31
-
32
- # @note Unlike `Hash#deep_merge`, `second_expanded`'s values aren't favored over `first`'s values. Instead whichever
33
- # side is present is used and if both `first` and `second_expanded` are present, then their `Hash#key`s' values are
34
- # recursively merged.
35
- #
36
- # Merges two expanded association trees.
37
- #
38
- # @param first_expanded [nil, Hash{Symbol => nil,Hash}] An expanded association tree as from {expand}
39
- # @param second_expanded [nil, Hash{Symbol => nil,Hash}] An expanded association tree as from {expand}
40
- # @return [nil, Hash{Symbol => nil,Hash}] a new expanded association tree.
41
- def self.merge(first_expanded, second_expanded)
42
- if first_expanded.nil? && second_expanded.nil?
43
- nil
44
- elsif !first_expanded.nil? && second_expanded.nil?
45
- first_expanded
46
- elsif first_expanded.nil? && !second_expanded.nil?
47
- second_expanded
48
- else
49
- first_keys = first_expanded.keys
50
- key_set = Set.new(first_keys)
51
-
52
- second_keys = second_expanded.keys
53
- key_set.merge(second_keys)
54
-
55
- key_set.each_with_object({}) do |key, merged|
56
- first_child = first_expanded[key]
57
- second_child = second_expanded[key]
58
-
59
- merged[key] = merge(first_child, second_child)
60
- end
61
- end
62
- end
63
-
64
- # Calculates association operators for the `expanded` association tree.
65
- #
66
- # @param expanded [Hash{Symbol => Hash,nil}, nil] An expanded association tree.
67
- # @param options [Hash{Symbol => Class}]
68
- # @option options [Class, #reflect_on_association] :class The `Class` on which the top-level key associations in
69
- # `expanded` are declared.
70
- # @return [Array<Metasploit::Model::Search::Operator::Association>]
71
- def self.operators(expanded, options={})
72
- expanded ||= {}
73
-
74
- options.assert_valid_keys(:class)
75
- klass = options.fetch(:class)
76
-
77
- expanded.flat_map { |parent_association, child_tree|
78
- reflection = reflect_on_association_on_class(parent_association, klass)
79
- association_class = reflection.klass
80
-
81
- association_search_with_operators = association_class.search_with_operator_by_name.each_value
82
-
83
- child_tree_operators = operators(
84
- child_tree,
85
- class: reflection.klass
86
- )
1
+ # Functions for turning a compact tree of compact as passed to
2
+ # {Metasploit::Model::Search::Association::ClassMethods#search_associations} into an expanded
3
+ # {Metasploit::Model::Search::Association::ClassMethods#search_association_tree}.
4
+ module Metasploit::Model::Association::Tree
5
+ # Expands a `compact` association into an expanded association tree.
6
+ #
7
+ # @param compact [Array, Hash{Symbol => Array,Hash,Symbol}, Symbol] a compact association as passed to
8
+ # {Metasploit::Model::Search::Association::ClassMethods#search_associations}.
9
+ # @return [Hash{Symbol => Hash,nil}]
10
+ def self.expand(compact)
11
+ case compact
12
+ when Array
13
+ compact.reduce({}) { |hash, association|
14
+ hash.merge(expand(association))
15
+ }
16
+ when Hash
17
+ child_by_parent = compact
18
+
19
+ child_by_parent.each_with_object({}) { |(parent, child), hash|
20
+ hash[parent] = expand(child)
21
+ }
22
+ when Symbol
23
+ association = compact
24
+
25
+ {association => nil}
26
+ end
27
+ end
87
28
 
88
- [association_search_with_operators, child_tree_operators].flat_map { |enumerator|
89
- enumerator.map { |source_operator|
90
- Metasploit::Model::Search::Operator::Association.new(
91
- association: parent_association,
92
- klass: klass,
93
- source_operator: source_operator
94
- )
95
- }
96
- }
97
- }
98
- end
99
-
100
- private
101
-
102
- # Return the association reflection for `association` on `klass`.
103
- #
104
- # @param association [Symbol] name of an association on `klass`.
105
- # @param klass [#reflect_on_association] `Class` on which `association` is declared.
106
- # @return [#klass] Association reflection that can give the `#klass` pointed to by the association.
107
- # @raise [Metasploit::Model::Association::Error] if `association` is not declared on `klass`.
108
- # @raise [NameError] if `klass` does not respond to `reflect_on_association`.
109
- def self.reflect_on_association_on_class(association, klass)
110
- begin
111
- reflection = klass.reflect_on_association(association)
112
- rescue NameError
113
- raise NameError,
114
- "#{self} does not respond to reflect_on_association. " \
115
- "It can be added to ActiveModels by including Metasploit::Model::Association into the class."
116
- end
29
+ # @note Unlike `Hash#deep_merge`, `second_expanded`'s values aren't favored over `first`'s values. Instead whichever
30
+ # side is present is used and if both `first` and `second_expanded` are present, then their `Hash#key`s' values are
31
+ # recursively merged.
32
+ #
33
+ # Merges two expanded association trees.
34
+ #
35
+ # @param first_expanded [nil, Hash{Symbol => nil,Hash}] An expanded association tree as from {expand}
36
+ # @param second_expanded [nil, Hash{Symbol => nil,Hash}] An expanded association tree as from {expand}
37
+ # @return [nil, Hash{Symbol => nil,Hash}] a new expanded association tree.
38
+ def self.merge(first_expanded, second_expanded)
39
+ if first_expanded.nil? && second_expanded.nil?
40
+ nil
41
+ elsif !first_expanded.nil? && second_expanded.nil?
42
+ first_expanded
43
+ elsif first_expanded.nil? && !second_expanded.nil?
44
+ second_expanded
45
+ else
46
+ first_keys = first_expanded.keys
47
+ key_set = Set.new(first_keys)
48
+
49
+ second_keys = second_expanded.keys
50
+ key_set.merge(second_keys)
51
+
52
+ key_set.each_with_object({}) do |key, merged|
53
+ first_child = first_expanded[key]
54
+ second_child = second_expanded[key]
55
+
56
+ merged[key] = merge(first_child, second_child)
57
+ end
58
+ end
59
+ end
117
60
 
118
- unless reflection
119
- raise Metasploit::Model::Association::Error.new(
120
- model: klass,
121
- name: association
122
- )
123
- end
61
+ # Calculates association operators for the `expanded` association tree.
62
+ #
63
+ # @param expanded [Hash{Symbol => Hash,nil}, nil] An expanded association tree.
64
+ # @param options [Hash{Symbol => Class}]
65
+ # @option options [Class, #reflect_on_association] :class The `Class` on which the top-level key associations in
66
+ # `expanded` are declared.
67
+ # @return [Array<Metasploit::Model::Search::Operator::Association>]
68
+ def self.operators(expanded, options={})
69
+ expanded ||= {}
70
+
71
+ options.assert_valid_keys(:class)
72
+ klass = options.fetch(:class)
73
+
74
+ expanded.flat_map { |parent_association, child_tree|
75
+ reflection = reflect_on_association_on_class(parent_association, klass)
76
+ association_class = reflection.klass
77
+
78
+ association_search_with_operators = association_class.search_with_operator_by_name.each_value
79
+
80
+ child_tree_operators = operators(
81
+ child_tree,
82
+ class: reflection.klass
83
+ )
84
+
85
+ [association_search_with_operators, child_tree_operators].flat_map { |enumerator|
86
+ enumerator.map { |source_operator|
87
+ Metasploit::Model::Search::Operator::Association.new(
88
+ association: parent_association,
89
+ klass: klass,
90
+ source_operator: source_operator
91
+ )
92
+ }
93
+ }
94
+ }
95
+ end
124
96
 
125
- reflection
126
- end
127
- end
97
+ private
98
+
99
+ # Return the association reflection for `association` on `klass`.
100
+ #
101
+ # @param association [Symbol] name of an association on `klass`.
102
+ # @param klass [#reflect_on_association] `Class` on which `association` is declared.
103
+ # @return [#klass] Association reflection that can give the `#klass` pointed to by the association.
104
+ # @raise [Metasploit::Model::Association::Error] if `association` is not declared on `klass`.
105
+ # @raise [NameError] if `klass` does not respond to `reflect_on_association`.
106
+ def self.reflect_on_association_on_class(association, klass)
107
+ begin
108
+ reflection = klass.reflect_on_association(association)
109
+ rescue NameError
110
+ raise NameError,
111
+ "#{self} does not respond to reflect_on_association. " \
112
+ "It can be added to ActiveModels by including Metasploit::Model::Association into the class."
128
113
  end
114
+
115
+ unless reflection
116
+ raise Metasploit::Model::Association::Error.new(
117
+ model: klass,
118
+ name: association
119
+ )
120
+ end
121
+
122
+ reflection
129
123
  end
130
- end
124
+ end
@@ -1,60 +1,54 @@
1
- require 'metasploit/model/translation'
1
+ # Code shared between `Mdm::Author` and `Metasploit::Framework::Author`.
2
+ module Metasploit::Model::Author
3
+ extend ActiveModel::Naming
4
+ extend ActiveSupport::Concern
2
5
 
3
- module Metasploit
4
- module Model
5
- # Code shared between `Mdm::Author` and `Metasploit::Framework::Author`.
6
- module Author
7
- extend ActiveModel::Naming
8
- extend ActiveSupport::Concern
6
+ include Metasploit::Model::Translation
9
7
 
10
- include Metasploit::Model::Translation
8
+ included do
9
+ include ActiveModel::MassAssignmentSecurity
10
+ include ActiveModel::Validations
11
+ include Metasploit::Model::Search
11
12
 
12
- included do
13
- include ActiveModel::MassAssignmentSecurity
14
- include ActiveModel::Validations
15
- include Metasploit::Model::Search
13
+ #
14
+ # Mass Assignment Security
15
+ #
16
16
 
17
- #
18
- # Mass Assignment Security
19
- #
17
+ attr_accessible :name
20
18
 
21
- attr_accessible :name
19
+ #
20
+ # Search Attributes
21
+ #
22
22
 
23
- #
24
- # Search Attributes
25
- #
23
+ search_attribute :name, :type => :string
26
24
 
27
- search_attribute :name, :type => :string
25
+ #
26
+ # Validations
27
+ #
28
28
 
29
- #
30
- # Validations
31
- #
32
-
33
- validates :name, :presence => true
34
- end
35
-
36
- #
37
- # Associations
38
- #
39
-
40
- # @!attribute [r] email_addresses
41
- # Email addresses used by this author across all {#module_instances}.
42
- #
43
- # @return [Array<Metasploit::Model::EmailAddress>]
44
-
45
- # @!attribute [r] module_instances
46
- # Modules written by this author.
47
- #
48
- # @return [Array<Metasploit::Model::Module::Instance>]
49
-
50
- #
51
- # Attributes
52
- #
53
-
54
- # @!attribute [rw] name
55
- # Full name (First + Last name) or handle of author.
56
- #
57
- # @return [String]
58
- end
29
+ validates :name, :presence => true
59
30
  end
60
- end
31
+
32
+ #
33
+ # Associations
34
+ #
35
+
36
+ # @!attribute [r] email_addresses
37
+ # Email addresses used by this author across all {#module_instances}.
38
+ #
39
+ # @return [Array<Metasploit::Model::EmailAddress>]
40
+
41
+ # @!attribute [r] module_instances
42
+ # Modules written by this author.
43
+ #
44
+ # @return [Array<Metasploit::Model::Module::Instance>]
45
+
46
+ #
47
+ # Attributes
48
+ #
49
+
50
+ # @!attribute [rw] name
51
+ # Full name (First + Last name) or handle of author.
52
+ #
53
+ # @return [String]
54
+ end