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,176 +1,170 @@
1
- module Metasploit
2
- module Model
3
- module Search
4
- # Use search operators registered on an associated class using
5
- # {Metasploit::Model::Search::Attribute::ClassMethods#search_attribute},
6
- # {Metasploit::Model::Search::With::ClassMethods#search_with}.
7
- #
8
- # Searchable associations are declared explicitly so that associations cycles can be avoided and the search
9
- # interface can be tuned for clarity and complexity.
10
- #
11
- # # Testing
12
- #
13
- # {ClassMethods#search_association} calls can be tested with the 'search_association' shared example. First,
14
- # ensure the shared examples from `metasploit-model` are required in your `spec_helper.rb`:
15
- #
16
- # # spec/spec_helper.rb
17
- # support_glob = Metasploit::Model::Engine.root.join('spec', 'support', '**', '*.rb')
18
- #
19
- # Dir.glob(support_glob) do |path|
20
- # require path
21
- # end
22
- #
23
- # In the spec for the `Class` that called `search_association`, use the 'search_association' shared example:
24
- #
25
- # # spec/app/models/my_class_spec.rb
26
- # require 'spec_helper'
27
- #
28
- # describe MyClass do
29
- # context 'search' do
30
- # context 'associations' do
31
- # it_should_be_like 'search_association', :association_name
32
- # end
33
- # end
34
- # end
35
- #
36
- # @example Search near and far associations
37
- # class Root
38
- # include Metasploit::Model::Association
39
- # include Metasploit::Model::Search
40
- #
41
- # #
42
- # # Associations
43
- # #
44
- #
45
- # association :children,
46
- # class_name: 'Child'
47
- #
48
- # #
49
- # # Search
50
- # #
51
- #
52
- # search_association children: :grandchildren
53
- # end
54
- #
55
- # class Child
56
- # include Metasploit::Model::Association
57
- # include Metasploit::Model::Search
58
- #
59
- # #
60
- # # Associations
61
- # #
62
- #
63
- # association :grandchildren,
64
- # class_name: 'Grandchild'
65
- #
66
- # #
67
- # # Search
68
- # #
69
- #
70
- # search_attribute :name,
71
- # type: :string
72
- # end
73
- #
74
- # class Grandchild
75
- # include Metasploit::Model::Search
76
- #
77
- # search_attribute :age,
78
- # type: :integer
79
- # end
80
- #
81
- # Root.search_operator_by_name.each_value
82
- # # :'children.name'
83
- # # :'children.grandchildren.age'
84
- #
85
- # Child.search_operator_by_name.each_value
86
- # # :name
87
- # # @note ``:'grandchildren.age'`` is not in `Child`'s operators because it didn't declare
88
- # # `search_association :grandchildren`, only `Root` did.
89
- #
90
- # Grandchild.search_operator_name
91
- # # :age
92
- #
93
- module Association
94
- extend ActiveSupport::Concern
1
+ # Use search operators registered on an associated class using
2
+ # {Metasploit::Model::Search::Attribute::ClassMethods#search_attribute},
3
+ # {Metasploit::Model::Search::With::ClassMethods#search_with}.
4
+ #
5
+ # Searchable associations are declared explicitly so that associations cycles can be avoided and the search
6
+ # interface can be tuned for clarity and complexity.
7
+ #
8
+ # # Testing
9
+ #
10
+ # {ClassMethods#search_association} calls can be tested with the 'search_association' shared example. First,
11
+ # ensure the shared examples from `metasploit-model` are required in your `spec_helper.rb`:
12
+ #
13
+ # # spec/spec_helper.rb
14
+ # support_glob = Metasploit::Model::Engine.root.join('spec', 'support', '**', '*.rb')
15
+ #
16
+ # Dir.glob(support_glob) do |path|
17
+ # require path
18
+ # end
19
+ #
20
+ # In the spec for the `Class` that called `search_association`, use the 'search_association' shared example:
21
+ #
22
+ # # spec/app/models/my_class_spec.rb
23
+ # require 'spec_helper'
24
+ #
25
+ # describe MyClass do
26
+ # context 'search' do
27
+ # context 'associations' do
28
+ # it_should_be_like 'search_association', :association_name
29
+ # end
30
+ # end
31
+ # end
32
+ #
33
+ # @example Search near and far associations
34
+ # class Root
35
+ # include Metasploit::Model::Association
36
+ # include Metasploit::Model::Search
37
+ #
38
+ # #
39
+ # # Associations
40
+ # #
41
+ #
42
+ # association :children,
43
+ # class_name: 'Child'
44
+ #
45
+ # #
46
+ # # Search
47
+ # #
48
+ #
49
+ # search_association children: :grandchildren
50
+ # end
51
+ #
52
+ # class Child
53
+ # include Metasploit::Model::Association
54
+ # include Metasploit::Model::Search
55
+ #
56
+ # #
57
+ # # Associations
58
+ # #
59
+ #
60
+ # association :grandchildren,
61
+ # class_name: 'Grandchild'
62
+ #
63
+ # #
64
+ # # Search
65
+ # #
66
+ #
67
+ # search_attribute :name,
68
+ # type: :string
69
+ # end
70
+ #
71
+ # class Grandchild
72
+ # include Metasploit::Model::Search
73
+ #
74
+ # search_attribute :age,
75
+ # type: :integer
76
+ # end
77
+ #
78
+ # Root.search_operator_by_name.each_value
79
+ # # :'children.name'
80
+ # # :'children.grandchildren.age'
81
+ #
82
+ # Child.search_operator_by_name.each_value
83
+ # # :name
84
+ # # @note ``:'grandchildren.age'`` is not in `Child`'s operators because it didn't declare
85
+ # # `search_association :grandchildren`, only `Root` did.
86
+ #
87
+ # Grandchild.search_operator_name
88
+ # # :age
89
+ #
90
+ module Metasploit::Model::Search::Association
91
+ extend ActiveSupport::Concern
95
92
 
96
- # Adds {#search_association} DSL to make {Metasploit::Model::Search::Operator::Association association search
97
- # operators}.
98
- module ClassMethods
99
- # @note Use {#search_associations} to declare multiple associations or a tree of far associations as
100
- # searchable.
101
- #
102
- # Registers association for search.
103
- #
104
- # @example a single searchable association
105
- # search_association :children
106
- #
107
- # @param association [#to_sym] name of association to search.
108
- # @return [void]
109
- # @see #search_associations
110
- def search_association(association)
111
- search_association_tree[association.to_sym] ||= nil
112
- end
93
+ # Adds {#search_association} DSL to make {Metasploit::Model::Search::Operator::Association association search
94
+ # operators}.
95
+ module ClassMethods
96
+ # @note Use {#search_associations} to declare multiple associations or a tree of far associations as
97
+ # searchable.
98
+ #
99
+ # Registers association for search.
100
+ #
101
+ # @example a single searchable association
102
+ # search_association :children
103
+ #
104
+ # @param association [#to_sym] name of association to search.
105
+ # @return [void]
106
+ # @see #search_associations
107
+ def search_association(association)
108
+ search_association_tree[association.to_sym] ||= nil
109
+ end
113
110
 
114
- # Registers a tree of near and far associations for search. When a tree is used, all intermediate association
115
- # on the paths are used, so `search_association children: :grandchildren` makes both `children.granchildren`
116
- # *and* `children` as search operator prefixes.
117
- #
118
- # @example a single search association
119
- # search_associations :children
120
- #
121
- # @example multiple near associations
122
- # search_associations :first,
123
- # :second
124
- #
125
- # @example far association
126
- # search_associations near: :far
127
- #
128
- # @example multiple far associations
129
- # search_associations near: [
130
- # :first_far,
131
- # :second_far
132
- # ]
133
- #
134
- # @example mix of near and far associations
135
- # # Keep associations in order by near association names by mixing Symbols and Hash{Symbol => Object}
136
- # search_associations :apple,
137
- # {
138
- # banana: :peel
139
- # },
140
- # :cucumber
141
- #
142
- #
143
- # @param associations [Array<Array, Hash, Symbol>, Hash, Symbol]
144
- # @return [void]
145
- # @see search_association
146
- def search_associations(*associations)
147
- expanded_associations = Metasploit::Model::Association::Tree.expand(associations)
111
+ # Registers a tree of near and far associations for search. When a tree is used, all intermediate association
112
+ # on the paths are used, so `search_association children: :grandchildren` makes both `children.granchildren`
113
+ # *and* `children` as search operator prefixes.
114
+ #
115
+ # @example a single search association
116
+ # search_associations :children
117
+ #
118
+ # @example multiple near associations
119
+ # search_associations :first,
120
+ # :second
121
+ #
122
+ # @example far association
123
+ # search_associations near: :far
124
+ #
125
+ # @example multiple far associations
126
+ # search_associations near: [
127
+ # :first_far,
128
+ # :second_far
129
+ # ]
130
+ #
131
+ # @example mix of near and far associations
132
+ # # Keep associations in order by near association names by mixing Symbols and Hash{Symbol => Object}
133
+ # search_associations :apple,
134
+ # {
135
+ # banana: :peel
136
+ # },
137
+ # :cucumber
138
+ #
139
+ #
140
+ # @param associations [Array<Array, Hash, Symbol>, Hash, Symbol]
141
+ # @return [void]
142
+ # @see search_association
143
+ def search_associations(*associations)
144
+ expanded_associations = Metasploit::Model::Association::Tree.expand(associations)
148
145
 
149
- @search_association_tree = Metasploit::Model::Association::Tree.merge(
150
- search_association_tree,
151
- expanded_associations
152
- )
153
- end
146
+ @search_association_tree = Metasploit::Model::Association::Tree.merge(
147
+ search_association_tree,
148
+ expanded_associations
149
+ )
150
+ end
154
151
 
155
- # The association operators for the searchable associations declared with {#search_association} and
156
- # {#search_associations}.
157
- #
158
- # @return (see Metasploit::Model::Association::Tree.operators)
159
- def search_association_operators
160
- @search_association_operators ||= Metasploit::Model::Association::Tree.operators(
161
- search_association_tree,
162
- class: self
163
- )
164
- end
152
+ # The association operators for the searchable associations declared with {#search_association} and
153
+ # {#search_associations}.
154
+ #
155
+ # @return (see Metasploit::Model::Association::Tree.operators)
156
+ def search_association_operators
157
+ @search_association_operators ||= Metasploit::Model::Association::Tree.operators(
158
+ search_association_tree,
159
+ class: self
160
+ )
161
+ end
165
162
 
166
- # Tree of associations that are searchable.
167
- #
168
- # @return [Hash{Symbol => Hash,nil}]
169
- def search_association_tree
170
- @search_association_tree ||= {}
171
- end
172
- end
173
- end
163
+ # Tree of associations that are searchable.
164
+ #
165
+ # @return [Hash{Symbol => Hash,nil}]
166
+ def search_association_tree
167
+ @search_association_tree ||= {}
174
168
  end
175
169
  end
176
- end
170
+ end
@@ -1,143 +1,135 @@
1
- require 'metasploit/model/search/with'
1
+ # Registers attributes that can be searched. Attributes must be declared to be searchable as a type from
2
+ # {Metasploit::Model::Search::Operator::Attribute::TYPES}. The type of the attribute is used to select a
3
+ # type-specific {Metasploit::Model::Search::Operation}, which will validate the
4
+ # {Metasploit::Model::Search::Operation::Base#value} is of the valid type.
5
+ #
6
+ # # Set attributes
7
+ #
8
+ # Search attributes declared as having an integer set or string set type integer or string set require a
9
+ # `<attribute>_set` method to be defined on the `Class`, which returns the set of allowed values for the search
10
+ # attribute's operation. This method will be called, indirectly by
11
+ # {Metasploit::Model::Search::Operation::Set::Integer}'s and {Metasploit::Model::Search::Operation::Set::String}'s
12
+ # validations.
13
+ #
14
+ # # Help
15
+ #
16
+ # The help for each operator is uses the `I18n` system, so the help for an attribute operator on a given class can
17
+ # added to `config/locales/<lang>.yml`. The scope of the lookup, under the language key is the `Class`'s
18
+ # `i18n_scope`, which is `metasploit.model` if the `Class` includes {Metasploit::Model::Translation} or
19
+ # `active_record` for `ActiveRecord::Base` subclasses. Under the `i18n_scope`, any `Module#ancestor`'s
20
+ # `model_name.i18n_key` can be used to look up the help for an attribute's operator. This allows for super
21
+ # classes or mixins to define the search operator help for subclasses.
22
+ #
23
+ # # config/locales/<lang>.yml
24
+ # <lang>:
25
+ # <Class#i18n_scope>:
26
+ # ancestors:
27
+ # <ancestor.model_name.i18n_key>:
28
+ # search:
29
+ # operator:
30
+ # names:
31
+ # <attribute>:
32
+ # help: "The attribute on the class"
33
+ #
34
+ # # Testing
35
+ #
36
+ # {ClassMethods#search_attribute} calls can be tested with the 'search_attribute' shared example. First, ensure
37
+ # the shared examples from `metasploit-model` are required in your `spec_helper.rb`:
38
+ #
39
+ # # spec/spec_helper.rb
40
+ # support_glob = Metasploit::Model::Engine.root.join('spec', 'support', '**', '*.rb')
41
+ #
42
+ # Dir.glob(support_glob) do |path|
43
+ # require path
44
+ # end
45
+ #
46
+ # In the spec for the `Class` that called `search_attribute`, use the 'search_attribute' shared example by
47
+ # passing that arguments passed to {ClassMethods#search_attribute}.
48
+ #
49
+ # # spec/app/models/my_class_spec.rb
50
+ # require 'spec_helper'
51
+ #
52
+ # describe MyClass do
53
+ # context 'search' do
54
+ # context 'attributes' do
55
+ # it_should_behave_like 'search_attribute',
56
+ # type: {
57
+ # set: :string
58
+ # }
59
+ # end
60
+ # end
61
+ # end
62
+ #
63
+ # @example search an attribute for `true` or `false`
64
+ # search_attribute :flag,
65
+ # type: :boolean
66
+ #
67
+ # @example search an attribute for an integer
68
+ # search_attribute :age,
69
+ # type: :integer
70
+ #
71
+ # @example search an attribute for a restricted set of integers
72
+ # #
73
+ # # Search
74
+ # #
75
+ #
76
+ # search_attribute :bits,
77
+ # set: :integer
78
+ #
79
+ # #
80
+ # # Class Methods
81
+ # #
82
+ #
83
+ # # Return set of allowed values for {#bits} search.
84
+ # #
85
+ # # @return [Set<Integer>]
86
+ # def self.bits_set
87
+ # @bits_set ||= Set.new([32, 64])
88
+ # end
89
+ #
90
+ # @example search an attribute for a restricted set of strings
91
+ # #
92
+ # # Search
93
+ # #
94
+ #
95
+ # search_attribute :endianness,
96
+ # set: :string
97
+ #
98
+ # #
99
+ # # Class Methods
100
+ # #
101
+ #
102
+ # # Return set of allowed values for {#endianness} search.
103
+ # #
104
+ # # @return [Set<String>]
105
+ # def self.endianness_set
106
+ # @endianness_set ||= Set.new(['big', 'litte'])
107
+ # end
108
+ #
109
+ # @example search an attribute by substring (case-insensitve LIKE)
110
+ # search_attribute :description,
111
+ # type: :string
112
+ module Metasploit::Model::Search::Attribute
113
+ extend ActiveSupport::Concern
2
114
 
3
- module Metasploit
4
- module Model
5
- module Search
6
- # Registers attributes that can be searched. Attributes must be declared to be searchable as a type from
7
- # {Metasploit::Model::Search::Operator::Attribute::TYPES}. The type of the attribute is used to select a
8
- # type-specific {Metasploit::Model::Search::Operation}, which will validate the
9
- # {Metasploit::Model::Search::Operation::Base#value} is of the valid type.
10
- #
11
- # # Set attributes
12
- #
13
- # Search attributes declared as having an integer set or string set type integer or string set require a
14
- # `<attribute>_set` method to be defined on the `Class`, which returns the set of allowed values for the search
15
- # attribute's operation. This method will be called, indirectly by
16
- # {Metasploit::Model::Search::Operation::Set::Integer}'s and {Metasploit::Model::Search::Operation::Set::String}'s
17
- # validations.
18
- #
19
- # # Help
20
- #
21
- # The help for each operator is uses the `I18n` system, so the help for an attribute operator on a given class can
22
- # added to `config/locales/<lang>.yml`. The scope of the lookup, under the language key is the `Class`'s
23
- # `i18n_scope`, which is `metasploit.model` if the `Class` includes {Metasploit::Model::Translation} or
24
- # `active_record` for `ActiveRecord::Base` subclasses. Under the `i18n_scope`, any `Module#ancestor`'s
25
- # `model_name.i18n_key` can be used to look up the help for an attribute's operator. This allows for super
26
- # classes or mixins to define the search operator help for subclasses.
27
- #
28
- # # config/locales/<lang>.yml
29
- # <lang>:
30
- # <Class#i18n_scope>:
31
- # ancestors:
32
- # <ancestor.model_name.i18n_key>:
33
- # search:
34
- # operator:
35
- # names:
36
- # <attribute>:
37
- # help: "The attribute on the class"
38
- #
39
- # # Testing
40
- #
41
- # {ClassMethods#search_attribute} calls can be tested with the 'search_attribute' shared example. First, ensure
42
- # the shared examples from `metasploit-model` are required in your `spec_helper.rb`:
43
- #
44
- # # spec/spec_helper.rb
45
- # support_glob = Metasploit::Model::Engine.root.join('spec', 'support', '**', '*.rb')
46
- #
47
- # Dir.glob(support_glob) do |path|
48
- # require path
49
- # end
50
- #
51
- # In the spec for the `Class` that called `search_attribute`, use the 'search_attribute' shared example by
52
- # passing that arguments passed to {ClassMethods#search_attribute}.
53
- #
54
- # # spec/app/models/my_class_spec.rb
55
- # require 'spec_helper'
56
- #
57
- # describe MyClass do
58
- # context 'search' do
59
- # context 'attributes' do
60
- # it_should_behave_like 'search_attribute',
61
- # type: {
62
- # set: :string
63
- # }
64
- # end
65
- # end
66
- # end
67
- #
68
- # @example search an attribute for `true` or `false`
69
- # search_attribute :flag,
70
- # type: :boolean
71
- #
72
- # @example search an attribute for an integer
73
- # search_attribute :age,
74
- # type: :integer
75
- #
76
- # @example search an attribute for a restricted set of integers
77
- # #
78
- # # Search
79
- # #
80
- #
81
- # search_attribute :bits,
82
- # set: :integer
83
- #
84
- # #
85
- # # Class Methods
86
- # #
87
- #
88
- # # Return set of allowed values for {#bits} search.
89
- # #
90
- # # @return [Set<Integer>]
91
- # def self.bits_set
92
- # @bits_set ||= Set.new([32, 64])
93
- # end
94
- #
95
- # @example search an attribute for a restricted set of strings
96
- # #
97
- # # Search
98
- # #
99
- #
100
- # search_attribute :endianness,
101
- # set: :string
102
- #
103
- # #
104
- # # Class Methods
105
- # #
106
- #
107
- # # Return set of allowed values for {#endianness} search.
108
- # #
109
- # # @return [Set<String>]
110
- # def self.endianness_set
111
- # @endianness_set ||= Set.new(['big', 'litte'])
112
- # end
113
- #
114
- # @example search an attribute by substring (case-insensitve LIKE)
115
- # search_attribute :description,
116
- # type: :string
117
- module Attribute
118
- extend ActiveSupport::Concern
115
+ include Metasploit::Model::Search::With
119
116
 
120
- include Metasploit::Model::Search::With
121
-
122
- # Adds {#search_attribute} DSL to make {Metasploit::Model::Search::Operator::Attribute attribute search
123
- # operators}.
124
- module ClassMethods
125
- # {include:Metasploit::Model::Search::Attribute}
126
- #
127
- # @param attribute [#to_sym] name of attribute to search.
128
- # @param options [Hash{Symbol => String}]
129
- # @option options [Symbol] :type The type of the attribute. Used to determine how to parse the search values
130
- # and which modifiers are supported.
131
- # @return (see Metasploit::Model::Search::With::ClassMethods#search_with)
132
- # @raise [Metasploit::Model::Invalid] unless attribute is present
133
- # @raise [Metasploit::Model::Invalid] unless :type is present
134
- def search_attribute(attribute, options={})
135
- search_with Metasploit::Model::Search::Operator::Attribute,
136
- :attribute => attribute,
137
- :type => options[:type]
138
- end
139
- end
140
- end
117
+ # Adds {#search_attribute} DSL to make {Metasploit::Model::Search::Operator::Attribute attribute search
118
+ # operators}.
119
+ module ClassMethods
120
+ # {include:Metasploit::Model::Search::Attribute}
121
+ #
122
+ # @param attribute [#to_sym] name of attribute to search.
123
+ # @param options [Hash{Symbol => String}]
124
+ # @option options [Symbol] :type The type of the attribute. Used to determine how to parse the search values
125
+ # and which modifiers are supported.
126
+ # @return (see Metasploit::Model::Search::With::ClassMethods#search_with)
127
+ # @raise [Metasploit::Model::Invalid] unless attribute is present
128
+ # @raise [Metasploit::Model::Invalid] unless :type is present
129
+ def search_attribute(attribute, options={})
130
+ search_with Metasploit::Model::Search::Operator::Attribute,
131
+ :attribute => attribute,
132
+ :type => options[:type]
141
133
  end
142
134
  end
143
- end
135
+ end