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,6 +1,9 @@
1
- require 'metasploit/model/search'
2
-
3
1
  # Namespace for search groups, such as {Metasploit::Model::Search::Group::Intersection intersections} or
4
2
  # {Metasploit::Model::Search::Group::Union unions}.
5
3
  module Metasploit::Model::Search::Group
4
+ extend ActiveSupport::Autoload
5
+
6
+ autoload :Base
7
+ autoload :Intersection
8
+ autoload :Union
6
9
  end
@@ -1,35 +1,38 @@
1
- module Metasploit
2
- module Model
3
- module Search
4
- # Namespace for search operations. {parse} acts as a factory to parse a `String` and return a type-specific
5
- # operation.
6
- module Operation
7
- extend ActiveSupport::Autoload
1
+ # Namespace for search operations. {parse} acts as a factory to parse a `String` and return a type-specific
2
+ # operation.
3
+ module Metasploit::Model::Search::Operation
4
+ extend ActiveSupport::Autoload
8
5
 
9
- autoload :Group
6
+ autoload :Association
7
+ autoload :Base
8
+ autoload :Boolean
9
+ autoload :Date
10
+ autoload :Group
11
+ autoload :Integer
12
+ autoload :Null
13
+ autoload :Set
14
+ autoload :String
15
+ autoload :Value
10
16
 
11
- # @param options [Hash{Symbol => Object}]
12
- # @option options [Metasploit::Module::Search::Query] :query The query that the parsed operation is a part.
13
- # @option options [String] :formatted_operation A '<operator>:<value>' string.
14
- # @return [Metasploit::Model::Search::Operation::Base, Array<Metasploit::Model::Search::Operation::Base>]
15
- # operation(s) parsed from the formatted operation.
16
- # @raise [KeyError] unless :formatted_operation is given.
17
- # @raise [KeyError] unless :query is given.
18
- def self.parse(options={})
19
- formatted_operation = options.fetch(:formatted_operation)
20
- query = options.fetch(:query)
17
+ # @param options [Hash{Symbol => Object}]
18
+ # @option options [Metasploit::Module::Search::Query] :query The query that the parsed operation is a part.
19
+ # @option options [String] :formatted_operation A '<operator>:<value>' string.
20
+ # @return [Metasploit::Model::Search::Operation::Base, Array<Metasploit::Model::Search::Operation::Base>]
21
+ # operation(s) parsed from the formatted operation.
22
+ # @raise [KeyError] unless :formatted_operation is given.
23
+ # @raise [KeyError] unless :query is given.
24
+ def self.parse(options={})
25
+ formatted_operation = options.fetch(:formatted_operation)
26
+ query = options.fetch(:query)
21
27
 
22
- formatted_operator, formatted_value = formatted_operation.split(':', 2)
23
- operator = query.parse_operator(formatted_operator)
28
+ formatted_operator, formatted_value = formatted_operation.split(':', 2)
29
+ operator = query.parse_operator(formatted_operator)
24
30
 
25
- # formatted_value will be nil if formatted_operation did not contain a ':', it should be treated the same
26
- # as nothing after the ':'.
27
- formatted_value ||= ''
28
- operation_or_operations = operator.operate_on(formatted_value)
31
+ # formatted_value will be nil if formatted_operation did not contain a ':', it should be treated the same
32
+ # as nothing after the ':'.
33
+ formatted_value ||= ''
34
+ operation_or_operations = operator.operate_on(formatted_value)
29
35
 
30
- operation_or_operations
31
- end
32
- end
33
- end
36
+ operation_or_operations
34
37
  end
35
- end
38
+ end
@@ -1,5 +1,8 @@
1
- require 'metasploit/model/search/operation'
2
-
3
1
  # Namespace for operations that form groups directly from single operator.
4
2
  module Metasploit::Model::Search::Operation::Group
3
+ extend ActiveSupport::Autoload
4
+
5
+ autoload :Base
6
+ autoload :Intersection
7
+ autoload :Union
5
8
  end
@@ -0,0 +1,7 @@
1
+ # Namespace for `Module`s that define operation `#value` methods.
2
+ module Metasploit::Model::Search::Operation::Value
3
+ extend ActiveSupport::Autoload
4
+
5
+ autoload :Integer
6
+ autoload :String
7
+ end
@@ -1,5 +1,5 @@
1
1
  # Concerns type casting of a raw value to an `Integer`.
2
- module Metasploit::Model::Search::Operation::Integer::Value
2
+ module Metasploit::Model::Search::Operation::Value::Integer
3
3
  #
4
4
  # Attributes
5
5
  #
@@ -1,5 +1,5 @@
1
1
  # Concerns type casting of a raw value to a `String`.
2
- module Metasploit::Model::Search::Operation::String::Value
2
+ module Metasploit::Model::Search::Operation::Value::String
3
3
  #
4
4
  # Methods
5
5
  #
@@ -1,66 +1,66 @@
1
- module Metasploit
2
- module Model
3
- module Search
4
- # # Declaring operator classes
5
- #
6
- # ## Interface
7
- #
8
- # Operators do not need to subclass any specific superclass, but they are expected to define certain methods.
9
- #
10
- # class MyOperator
11
- # #
12
- # # Instance Methods
13
- # #
14
- #
15
- # # @param klass [Class] The klass on which `search_with` was called.
16
- # def initialize(attributes={})
17
- # # ...
18
- # end
19
- #
20
- # # Description of what this operator searches for.
21
- # #
22
- # # @return [String]
23
- # def help
24
- # # ...
25
- # end
26
- #
27
- # # Name of this operator. The name of the operator is matched to the string before the ':' in a formatted
28
- # # operation.
29
- # #
30
- # # @return [Symbol]
31
- # def name
32
- # # ...
33
- # end
34
- #
35
- # # Creates a one or more operations based on `formatted_value`.
36
- # #
37
- # # @return [#operator, Array<#operator>] Operation with this operator as the operation's `operator`.
38
- # def operate_on(formatted_value)
39
- # # ...
40
- # end
41
- # end
42
- #
43
- # ## Help
44
- #
45
- # Instead of having define your own `#help` method for your operator `Class`, you can `include`
46
- # {Metasploit::Model::Search::Operator::Help}.
47
- #
48
- # {include:Metasploit::Model::Search::Operator::Help}
49
- #
50
- # ## {Metasploit::Model::Search::Operator::Base}
51
- #
52
- # {include:Metasploit::Model::Search::Operator::Base}
53
- #
54
- # ## {Metasploit::Model::Search::Operator::Single}
55
- #
56
- # {include:Metasploit::Model::Search::Operator::Single}
57
- module Operator
58
- extend ActiveSupport::Autoload
1
+ # # Declaring operator classes
2
+ #
3
+ # ## Interface
4
+ #
5
+ # Operators do not need to subclass any specific superclass, but they are expected to define certain methods.
6
+ #
7
+ # class MyOperator
8
+ # #
9
+ # # Instance Methods
10
+ # #
11
+ #
12
+ # # @param klass [Class] The klass on which `search_with` was called.
13
+ # def initialize(attributes={})
14
+ # # ...
15
+ # end
16
+ #
17
+ # # Description of what this operator searches for.
18
+ # #
19
+ # # @return [String]
20
+ # def help
21
+ # # ...
22
+ # end
23
+ #
24
+ # # Name of this operator. The name of the operator is matched to the string before the ':' in a formatted
25
+ # # operation.
26
+ # #
27
+ # # @return [Symbol]
28
+ # def name
29
+ # # ...
30
+ # end
31
+ #
32
+ # # Creates a one or more operations based on `formatted_value`.
33
+ # #
34
+ # # @return [#operator, Array<#operator>] Operation with this operator as the operation's `operator`.
35
+ # def operate_on(formatted_value)
36
+ # # ...
37
+ # end
38
+ # end
39
+ #
40
+ # ## Help
41
+ #
42
+ # Instead of having define your own `#help` method for your operator `Class`, you can `include`
43
+ # {Metasploit::Model::Search::Operator::Help}.
44
+ #
45
+ # {include:Metasploit::Model::Search::Operator::Help}
46
+ #
47
+ # ## {Metasploit::Model::Search::Operator::Base}
48
+ #
49
+ # {include:Metasploit::Model::Search::Operator::Base}
50
+ #
51
+ # ## {Metasploit::Model::Search::Operator::Single}
52
+ #
53
+ # {include:Metasploit::Model::Search::Operator::Single}
54
+ module Metasploit::Model::Search::Operator
55
+ extend ActiveSupport::Autoload
59
56
 
60
- autoload :Deprecated
61
- autoload :Group
62
- autoload :Help
63
- end
64
- end
65
- end
66
- end
57
+ autoload :Association
58
+ autoload :Attribute
59
+ autoload :Base
60
+ autoload :Delegation
61
+ autoload :Deprecated
62
+ autoload :Group
63
+ autoload :Help
64
+ autoload :Null
65
+ autoload :Single
66
+ end
@@ -1,6 +1,12 @@
1
- require 'metasploit/model/search/operator'
2
-
3
1
  # Namespace for search operators that mimic behavior of the msfconsole search operators prior to the search operator
4
2
  # generalization introduced by {Metasploit::Model::Search}.
5
3
  module Metasploit::Model::Search::Operator::Deprecated
4
+ extend ActiveSupport::Autoload
5
+
6
+ autoload :App
7
+ autoload :Author
8
+ autoload :Authority
9
+ autoload :Platform
10
+ autoload :Ref
11
+ autoload :Text
6
12
  end
@@ -1,5 +1,8 @@
1
- require 'metasploit/model/search/operator'
2
-
3
1
  # Namespace for operators that produce group operations.
4
2
  module Metasploit::Model::Search::Operator::Group
3
+ extend ActiveSupport::Autoload
4
+
5
+ autoload :Base
6
+ autoload :Intersection
7
+ autoload :Union
5
8
  end
@@ -1,85 +1,77 @@
1
- module Metasploit
2
- module Model
3
- module Search
4
- module Operator
5
- # This allows the help to be looked up using `I18n`, and for the
6
- # help to be customized based on the following criteria:
7
- #
8
- # `klass` on which the operator is declared, including any `Module#ancestors` and the operator `name`
9
- #
10
- # # config/locales/<lang>.yml
11
- # <lang>:
12
- # <klass.i18n_scope>:
13
- # ancestors:
14
- # <klass_ancestor.model_name.i18n_key>:
15
- # search:
16
- # operator:
17
- # names:
18
- # <name>:
19
- # help: "Help for searching <name> on <klass>"
20
- #
21
- # `class` of the operator, including any `Module#ancestors` and the operator `name`
22
- #
23
- # # config/locales/<lang>.yml
24
- # <lang>:
25
- # <operator.class.i18n_scope>:
26
- # search:
27
- # operator:
28
- # ancestors:
29
- # <operator_class_ancestor.model_name.i18n_key>:
30
- # <name>:
31
- # help: "Help for searching <name> using <operator.class>"
32
- #
33
- # `class` of the operator, including any `Module#ancestors` without the operator `name`
34
- #
35
- # # config/locales/<lang>.yml
36
- # <lang>:
37
- # <operator.class.i18n_scope>:
38
- # search:
39
- # operator:
40
- # ancestors:
41
- # <operator_class_ancestor.model_name.i18n_key>:
42
- # help: "Help for searching using <operator.class>"
43
- #
44
- module Help
45
- # @note This uses I18n.translate along with {Metasploit::Model::Translation#search_i18n_scope},
46
- # the value is not cached to support changing the I18n.locale and getting the correct help message for that
47
- # locale.
48
- #
49
- # The help for this operator.
50
- #
51
- # @see https://github.com/rails/rails/blob/6c2810b8ed692004dca43e554982cdfdb8517b80/activemodel/lib/active_model/errors.rb#L408-L435
52
- def help
53
- defaults = []
54
- klass_i18n_scope = klass.i18n_scope
1
+ # This allows the help to be looked up using `I18n`, and for the
2
+ # help to be customized based on the following criteria:
3
+ #
4
+ # `klass` on which the operator is declared, including any `Module#ancestors` and the operator `name`
5
+ #
6
+ # # config/locales/<lang>.yml
7
+ # <lang>:
8
+ # <klass.i18n_scope>:
9
+ # ancestors:
10
+ # <klass_ancestor.model_name.i18n_key>:
11
+ # search:
12
+ # operator:
13
+ # names:
14
+ # <name>:
15
+ # help: "Help for searching <name> on <klass>"
16
+ #
17
+ # `class` of the operator, including any `Module#ancestors` and the operator `name`
18
+ #
19
+ # # config/locales/<lang>.yml
20
+ # <lang>:
21
+ # <operator.class.i18n_scope>:
22
+ # search:
23
+ # operator:
24
+ # ancestors:
25
+ # <operator_class_ancestor.model_name.i18n_key>:
26
+ # <name>:
27
+ # help: "Help for searching <name> using <operator.class>"
28
+ #
29
+ # `class` of the operator, including any `Module#ancestors` without the operator `name`
30
+ #
31
+ # # config/locales/<lang>.yml
32
+ # <lang>:
33
+ # <operator.class.i18n_scope>:
34
+ # search:
35
+ # operator:
36
+ # ancestors:
37
+ # <operator_class_ancestor.model_name.i18n_key>:
38
+ # help: "Help for searching using <operator.class>"
39
+ #
40
+ module Metasploit::Model::Search::Operator::Help
41
+ # @note This uses I18n.translate along with {Metasploit::Model::Translation#search_i18n_scope},
42
+ # the value is not cached to support changing the I18n.locale and getting the correct help message for that
43
+ # locale.
44
+ #
45
+ # The help for this operator.
46
+ #
47
+ # @see https://github.com/rails/rails/blob/6c2810b8ed692004dca43e554982cdfdb8517b80/activemodel/lib/active_model/errors.rb#L408-L435
48
+ def help
49
+ defaults = []
50
+ klass_i18n_scope = klass.i18n_scope
55
51
 
56
- klass.lookup_ancestors.each do |ancestor|
57
- # a specific operator for a given Class#ancestors member
58
- defaults << :"#{klass_i18n_scope}.ancestors.#{ancestor.model_name.i18n_key}.search.operator.names.#{name}.help"
59
- end
52
+ klass.lookup_ancestors.each do |ancestor|
53
+ # a specific operator for a given Class#ancestors member
54
+ defaults << :"#{klass_i18n_scope}.ancestors.#{ancestor.model_name.i18n_key}.search.operator.names.#{name}.help"
55
+ end
60
56
 
61
- operator_class = self.class
62
- operator_i18n_scope = operator_class.i18n_scope
57
+ operator_class = self.class
58
+ operator_i18n_scope = operator_class.i18n_scope
63
59
 
64
- operator_class.lookup_ancestors.each do |ancestor|
65
- # a specific name for a given operator
66
- defaults << :"#{operator_i18n_scope}.search.operator.ancestors.#{ancestor.model_name.i18n_key}.names.#{name}.help"
67
- # a specific operator class
68
- defaults << :"#{operator_i18n_scope}.search.operator.ancestors.#{ancestor.model_name.i18n_key}.help"
69
- end
60
+ operator_class.lookup_ancestors.each do |ancestor|
61
+ # a specific name for a given operator
62
+ defaults << :"#{operator_i18n_scope}.search.operator.ancestors.#{ancestor.model_name.i18n_key}.names.#{name}.help"
63
+ # a specific operator class
64
+ defaults << :"#{operator_i18n_scope}.search.operator.ancestors.#{ancestor.model_name.i18n_key}.help"
65
+ end
70
66
 
71
- # use first default as key because it is most specific default, that is closest to klass.
72
- key = defaults.shift
73
- options = {
74
- default: defaults,
75
- model: klass.model_name.human,
76
- name: name
77
- }
67
+ # use first default as key because it is most specific default, that is closest to klass.
68
+ key = defaults.shift
69
+ options = {
70
+ default: defaults,
71
+ model: klass.model_name.human,
72
+ name: name
73
+ }
78
74
 
79
- ::I18n.translate(key, options)
80
- end
81
- end
82
- end
83
- end
75
+ ::I18n.translate(key, options)
84
76
  end
85
- end
77
+ end
@@ -1,83 +1,77 @@
1
- module Metasploit
2
- module Model
3
- module Search
4
- # Generalizes {Metasploit::Model::Search::Attribute operators from attributes} to anything directly registered as
5
- # an operator on a class.
6
- #
7
- # {include:Metasploit::Model::Search::Operator}
8
- #
9
- # # Testing
10
- #
11
- # {ClassMethods#search_with} calls can be tested with the 'search_with' shared example. First, ensure
12
- # the shared examples from `metasploit-model` are required in your `spec_helper.rb`:
13
- #
14
- # # spec/spec_helper.rb
15
- # support_glob = Metasploit::Model::Engine.root.join('spec', 'support', '**', '*.rb')
16
- #
17
- # Dir.glob(support_glob) do |path|
18
- # require path
19
- # end
20
- #
21
- # In the spec fo the `Class` that called `search_with`, use the 'search_with' shared example by passing the
22
- # arguments passed to {ClassMethods#search_attribute}.
23
- #
24
- # # app/models/my_class.rb
25
- # class MyClass
26
- # include Metasploit::Model::Search
27
- #
28
- # #
29
- # # Search
30
- # #
31
- #
32
- # search_with MyOperatorClass,
33
- # foo: :bar
34
- # end
35
- #
36
- # # spec/app/models/my_class_spec.rb
37
- # require 'spec_helper'
38
- #
39
- # describe MyClass do
40
- # context 'search' do
41
- # context 'attributes' do
42
- # it_should_behave_like 'search_with',
43
- # MyOperatorClass,
44
- # foo: :bar
45
- # end
46
- # end
47
- # end
48
- module With
49
- extend ActiveSupport::Concern
1
+ # Generalizes {Metasploit::Model::Search::Attribute operators from attributes} to anything directly registered as
2
+ # an operator on a class.
3
+ #
4
+ # {include:Metasploit::Model::Search::Operator}
5
+ #
6
+ # # Testing
7
+ #
8
+ # {ClassMethods#search_with} calls can be tested with the 'search_with' shared example. First, ensure
9
+ # the shared examples from `metasploit-model` are required in your `spec_helper.rb`:
10
+ #
11
+ # # spec/spec_helper.rb
12
+ # support_glob = Metasploit::Model::Engine.root.join('spec', 'support', '**', '*.rb')
13
+ #
14
+ # Dir.glob(support_glob) do |path|
15
+ # require path
16
+ # end
17
+ #
18
+ # In the spec fo the `Class` that called `search_with`, use the 'search_with' shared example by passing the
19
+ # arguments passed to {ClassMethods#search_attribute}.
20
+ #
21
+ # # app/models/my_class.rb
22
+ # class MyClass
23
+ # include Metasploit::Model::Search
24
+ #
25
+ # #
26
+ # # Search
27
+ # #
28
+ #
29
+ # search_with MyOperatorClass,
30
+ # foo: :bar
31
+ # end
32
+ #
33
+ # # spec/app/models/my_class_spec.rb
34
+ # require 'spec_helper'
35
+ #
36
+ # describe MyClass do
37
+ # context 'search' do
38
+ # context 'attributes' do
39
+ # it_should_behave_like 'search_with',
40
+ # MyOperatorClass,
41
+ # foo: :bar
42
+ # end
43
+ # end
44
+ # end
45
+ module Metasploit::Model::Search::With
46
+ extend ActiveSupport::Concern
50
47
 
51
- # Defines `search_with` DSL, which is a lower-level way than search_attribute to add operators. `search_with`
52
- # allows instance of arbitrary operator_classes to be registered in {#search_with_operator_by_name}.
53
- module ClassMethods
54
- # Declares that this class should be search with an instance of the given `operator_class`.
55
- #
56
- # @param operator_class [Class<Metasploit::Model::Search::Operator::Base>] a class to initialize.
57
- # @param options [Hash] Options passed to `operator_class.new` along with `{:klass => self}`, so that the
58
- # `operator_class` instance knows it was registered as search this class.
59
- # @return [Metasploit::Model::Search::Operator::Base]
60
- # @raise (see Metasploit::Model::Base#invalid!)
61
- def search_with(operator_class, options={})
62
- merged_operations = options.merge(
63
- :klass => self
64
- )
65
- operator = operator_class.new(merged_operations)
66
- operator.valid!
48
+ # Defines `search_with` DSL, which is a lower-level way than search_attribute to add operators. `search_with`
49
+ # allows instance of arbitrary operator_classes to be registered in {#search_with_operator_by_name}.
50
+ module ClassMethods
51
+ # Declares that this class should be search with an instance of the given `operator_class`.
52
+ #
53
+ # @param operator_class [Class<Metasploit::Model::Search::Operator::Base>] a class to initialize.
54
+ # @param options [Hash] Options passed to `operator_class.new` along with `{:klass => self}`, so that the
55
+ # `operator_class` instance knows it was registered as search this class.
56
+ # @return [Metasploit::Model::Search::Operator::Base]
57
+ # @raise (see Metasploit::Model::Base#invalid!)
58
+ def search_with(operator_class, options={})
59
+ merged_operations = options.merge(
60
+ :klass => self
61
+ )
62
+ operator = operator_class.new(merged_operations)
63
+ operator.valid!
67
64
 
68
- search_with_operator_by_name[operator.name] = operator
69
- end
65
+ search_with_operator_by_name[operator.name] = operator
66
+ end
70
67
 
71
- # Operators registered with {#search_with}.
72
- #
73
- # @return [Hash{Symbol => Metasploit::Model::Search::Operator::Base}] Maps
74
- # {Metasploit::Model::Search::Operator::Base#name} keys to {Metasploit::Model::Search::Operator::Base#name}
75
- # values.
76
- def search_with_operator_by_name
77
- @search_with_operator_by_name ||= {}
78
- end
79
- end
80
- end
68
+ # Operators registered with {#search_with}.
69
+ #
70
+ # @return [Hash{Symbol => Metasploit::Model::Search::Operator::Base}] Maps
71
+ # {Metasploit::Model::Search::Operator::Base#name} keys to {Metasploit::Model::Search::Operator::Base#name}
72
+ # values.
73
+ def search_with_operator_by_name
74
+ @search_with_operator_by_name ||= {}
81
75
  end
82
76
  end
83
- end
77
+ end