metasploit-concern 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +114 -0
- data/Rakefile +7 -0
- data/app/models/metasploit/concern/loader.rb +1 -1
- data/lib/metasploit/concern.rb +40 -3
- data/lib/metasploit/concern/version.rb +1 -1
- data/spec/support/shared/examples/metasploit/concern/run.rb +34 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzYzMTU5MmEzNWYwZjI0MWM1NDVlNTJmYThhYWU5ZjVmMmYxMmU5Yw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjdjZDdlYzRlN2JjNTJmOWQyMTJiNTI2YTZlYzA3YTAzNDFiNDZlMw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTIwZDRmNmZiNmNhODA4NDExYmRlNWQ4MDJjZTFhOWE1MDQ2NjRiYzUxYTIz
|
10
|
+
ZWRkZGU2ZDgxMzhhNDZjZGFiYzI5NWRkNTgyNzhkNGYwYWMxY2NlNGU5YmJh
|
11
|
+
OWQ1YjdhYjRiNzQyMGU0NWM2ODU1NWE0ZjdiMmRkZDBjYjIyNzk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjUzY2U3YjkwNWNmMmJmNWE0MGI2NDkwZWUwMmIxNDk0ZDVmZTkwOGM3ODVk
|
14
|
+
ODJhMDk4YzZmZmIxZTEzMWU2Y2M3MjA4MjU1YTkzOTg4NGE3NTE4MDZhNDAz
|
15
|
+
NDIwM2FmYjQ3NDdiNTRiZmVmYjZhODJiM2VjNjI0MDE3YjVlNzQ=
|
data/README.md
CHANGED
@@ -1,7 +1,121 @@
|
|
1
1
|
# Metasploit::Concern [![Build Status](https://travis-ci.org/rapid7/metasploit-concern.png)](https://travis-ci.org/rapid7/metasploit-concern)[![Code Climate](https://codeclimate.com/github/rapid7/metasploit-concern.png)](https://codeclimate.com/github/rapid7/metasploit-concern)[![Coverage Status](https://coveralls.io/repos/rapid7/metasploit-concern/badge.png)](https://coveralls.io/r/rapid7/metasploit-concern)[![Dependency Status](https://gemnasium.com/rapid7/metasploit-concern.png)](https://gemnasium.com/rapid7/metasploit-concern)[![Gem Version](https://badge.fury.io/rb/metasploit-concern.png)](http://badge.fury.io/rb/metasploit-concern)
|
2
2
|
|
3
|
+
`Metasploit::Concern` allows you to define concerns in `app/concerns` that will automatically be included in matching
|
4
|
+
classes. It can be used to automate adding new associations to `ActiveRecord::Base` models from gems and
|
5
|
+
`Rails::Engine`s.
|
6
|
+
|
3
7
|
## Versioning
|
4
8
|
|
5
9
|
`Metasploit::Concern` is versioned using [semantic versioning 2.0](http://semver.org/spec/v2.0.0.html). Each branch
|
6
10
|
should set `Metasploit::Concern::Version::PRERELEASE` to the branch name, while master should have no `PRERELEASE`
|
7
11
|
and the `PRERELEASE` section of `Metasploit::Concern::VERSION` does not exist.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's `Gemfile`:
|
16
|
+
|
17
|
+
gem 'metasploit-concern'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install metasploit-concern
|
26
|
+
|
27
|
+
## Supporting concerns
|
28
|
+
|
29
|
+
`Metasploit::Concern` support is a cooperative effort that involves the classes from the gem being setup
|
30
|
+
to allow downstream dependents to inject concerns.
|
31
|
+
|
32
|
+
In order for `Metasploit::Concern` to load concerns for `app/concerns`, the class on which `Module#include` will be
|
33
|
+
called must support `ActiveSupport` load hooks with a specific name format. You can run the appropriate load hooks
|
34
|
+
at the bottom of the class body:
|
35
|
+
|
36
|
+
class GemNamespace::GemClass < ActiveRecord::Base
|
37
|
+
# class body
|
38
|
+
|
39
|
+
Metasploit::Concern.run(self)
|
40
|
+
end
|
41
|
+
|
42
|
+
### Testing
|
43
|
+
|
44
|
+
Include the shared examples from `Metasploit::Concern` in your `spec_helper.rb`:
|
45
|
+
|
46
|
+
|
47
|
+
Dir[Metasploit::Concern.root.join("spec/support/**/*.rb")].each do |f|
|
48
|
+
require f
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
To verify that your classes call `Metasploit::Concern.run` correctly, you can use the `'Metasploit::Concern.run'` shared
|
53
|
+
example:
|
54
|
+
|
55
|
+
# spec/app/models/gem_namespace/gem_class_spec.rb
|
56
|
+
describe GemNamespace::GemClass do
|
57
|
+
it_should_behave_like 'Metasploit::Concern.run'
|
58
|
+
end
|
59
|
+
|
60
|
+
## Using concerns
|
61
|
+
|
62
|
+
Concerns are added in downstream dependents of gems that support concerns. These dependents can be a `Rails::Engines`
|
63
|
+
or full `Rails::Application`.
|
64
|
+
|
65
|
+
### app/concerns
|
66
|
+
|
67
|
+
#### Rails::Application
|
68
|
+
|
69
|
+
Add this line to your application's `config/application.rb`:
|
70
|
+
|
71
|
+
config.paths.add 'app/concerns', autoload: true
|
72
|
+
|
73
|
+
Or if you're already using `config.autoload_paths +=`:
|
74
|
+
|
75
|
+
config.autoload_paths += config.root.join('app', 'concerns')
|
76
|
+
|
77
|
+
#### Rails::Engine
|
78
|
+
|
79
|
+
Add this line to your engine's class body:
|
80
|
+
|
81
|
+
module EngineNamespace
|
82
|
+
class Engine < ::Rails::Engine
|
83
|
+
config.paths.add 'app/concerns', autoload: true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
### Concerns
|
88
|
+
|
89
|
+
Define concerns for class under `app/concerns` by creating files under directories named after the namespaced class
|
90
|
+
names:
|
91
|
+
|
92
|
+
$ mkdir -p app/concerns/gem_namespace/gem_class
|
93
|
+
$ edit app/concerns/gem_namespace/gem_class/my_concern.rb
|
94
|
+
|
95
|
+
Inside each concern, make sure the `module` name matches file name:
|
96
|
+
|
97
|
+
module GemNamespace::GemClass::MyConcern
|
98
|
+
...
|
99
|
+
end
|
100
|
+
|
101
|
+
Each concern is included using `Module#include` which means that the `included` method on each concern will be called.
|
102
|
+
Using `ActiveSupport::Concern` allow you to add new associations and or validations to `ActiveRecord::Base` subclass:
|
103
|
+
|
104
|
+
module GemNamespace::GemClass::MyConcern
|
105
|
+
extend ActiveSupport::Concern
|
106
|
+
|
107
|
+
included do
|
108
|
+
#
|
109
|
+
# Associations
|
110
|
+
#
|
111
|
+
|
112
|
+
# @!attribute widgets
|
113
|
+
# Widgets for this gem_class.
|
114
|
+
#
|
115
|
+
# @return [ActiveRecord::Relation<Widget>]
|
116
|
+
has_many :widgets,
|
117
|
+
class_name: 'Widget',
|
118
|
+
dependent: :destroy,
|
119
|
+
inverse_of :gem_namespace_gem_class
|
120
|
+
end
|
121
|
+
end
|
data/Rakefile
CHANGED
@@ -30,6 +30,13 @@ Dir.glob(rakefile_glob) do |rakefile|
|
|
30
30
|
load rakefile
|
31
31
|
end
|
32
32
|
|
33
|
+
require 'cucumber'
|
34
|
+
require 'cucumber/rake/task'
|
35
|
+
|
36
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
37
|
+
t.cucumber_opts = 'features --format pretty'
|
38
|
+
end
|
39
|
+
|
33
40
|
begin
|
34
41
|
require 'rspec/core'
|
35
42
|
rescue LoadError
|
data/lib/metasploit/concern.rb
CHANGED
@@ -1,8 +1,23 @@
|
|
1
|
+
#
|
2
|
+
# Gems
|
3
|
+
#
|
4
|
+
|
5
|
+
# `String#underscore``
|
6
|
+
require 'active_support/core_ext/string/inflections'
|
7
|
+
# `ActiveSupport.run_load_hooks`
|
8
|
+
require 'active_support/lazy_load_hooks'
|
9
|
+
|
10
|
+
#
|
11
|
+
# Project
|
12
|
+
#
|
13
|
+
|
1
14
|
# Only include the Rails engine when using Rails. This is for compatibility with metasploit-framework.
|
2
15
|
if defined? Rails
|
3
16
|
require 'metasploit/concern/engine'
|
4
17
|
end
|
5
18
|
|
19
|
+
require 'metasploit/concern/version'
|
20
|
+
|
6
21
|
# Shared namespace for metasploit gems; used in {https://github.com/rapid7/metasploit-concern metasploit-concern},
|
7
22
|
# {https://github.com/rapid7/metasploit-framework metasploit-framework}, and
|
8
23
|
# {https://github.com/rapid7/metasploit-model metasploit-model}
|
@@ -10,13 +25,12 @@ module Metasploit
|
|
10
25
|
# Automates the inclusion of concerns into classes and models from other `Rail::Engine`s by use of an app/concerns
|
11
26
|
# directory in the `Rails::Engine` that declares the concerns.
|
12
27
|
#
|
13
|
-
# The `Class` or `Module` must support the use of concerns by calling
|
14
|
-
# to the underscore of its name with any '/' replaced with underscores also.
|
28
|
+
# The `Class` or `Module` must support the use of concerns by calling {run}.
|
15
29
|
#
|
16
30
|
# @example engine_that_supports_concerns/app/models/model_that_supports_concerns.rb
|
17
31
|
# class EngineThatSupportsConcerns::ModelThatSupportsConcerns
|
18
32
|
# # declared as last statement in body so that concerns can redefine everything in class
|
19
|
-
#
|
33
|
+
# Metasploit::Concern.run(self)
|
20
34
|
# end
|
21
35
|
#
|
22
36
|
# To include concerns from a Rails::Application add 'app/concerns' to paths and then declare concerns under
|
@@ -68,6 +82,29 @@ module Metasploit
|
|
68
82
|
# end
|
69
83
|
# end
|
70
84
|
module Concern
|
85
|
+
# @note If `Rails` is loaded and {Metasploit::Concern::Engine} is defined, just use
|
86
|
+
# `Metasploit::Concern::Engine.root`.
|
87
|
+
#
|
88
|
+
# The root of the `metasploit-concern` gem's file tree.
|
89
|
+
#
|
90
|
+
# @return [Pathname]
|
91
|
+
def self.root
|
92
|
+
@root ||= Pathname.new(__FILE__).parent.parent.parent
|
93
|
+
end
|
71
94
|
|
95
|
+
# @note As `ActiveSupport.run_load_hooks` is used, it is safe to call {run} prior to {Metasploit::Concern}'s
|
96
|
+
# initializer {Metasploit::Concern::Loader#register registering} all the load hooks as any late load hooks will run
|
97
|
+
# as they are registered.
|
98
|
+
#
|
99
|
+
# @note `klass` must have a `Module#name` so that the load hook symbol can be derived.
|
100
|
+
#
|
101
|
+
# Runs the load hooks setup to include app/concerns concerns this `klass`.
|
102
|
+
#
|
103
|
+
# @param klass [Class] A class that should support loading concerns from app/concerns.
|
104
|
+
# @return [void]
|
105
|
+
def self.run(klass)
|
106
|
+
load_hook_name = klass.name.underscore.gsub('/', '_').to_sym
|
107
|
+
ActiveSupport.run_load_hooks(load_hook_name, klass)
|
108
|
+
end
|
72
109
|
end
|
73
110
|
end
|
@@ -7,7 +7,7 @@ module Metasploit
|
|
7
7
|
# The minor version number, scoped to the {MAJOR} version number.
|
8
8
|
MINOR = 0
|
9
9
|
# The patch number, scoped to the {MINOR} version number.
|
10
|
-
PATCH =
|
10
|
+
PATCH = 4
|
11
11
|
|
12
12
|
# The full version string, including the {MAJOR}, {MINOR}, {PATCH}, and optionally, the `PRERELEASE` in the
|
13
13
|
# {http://semver.org/spec/v2.0.0.html semantic versioning v2.0.0} format.
|
@@ -0,0 +1,34 @@
|
|
1
|
+
shared_examples_for 'Metasploit::Concern.run' do
|
2
|
+
let(:load_hook_name) {
|
3
|
+
described_class.name.underscore.gsub('/', '_').to_sym
|
4
|
+
}
|
5
|
+
|
6
|
+
let(:loaded_bases_by_name) {
|
7
|
+
ActiveSupport.module_eval { @loaded }
|
8
|
+
}
|
9
|
+
|
10
|
+
context 'with correct base' do
|
11
|
+
it 'calls ActiveSupport.run_load_hooks with correct load hook name' do
|
12
|
+
actual_names = []
|
13
|
+
|
14
|
+
loaded_bases_by_name.each do |name, bases|
|
15
|
+
bases.each do |base|
|
16
|
+
if base == described_class
|
17
|
+
actual_names << name
|
18
|
+
break
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
expect(actual_names).to include(load_hook_name)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with correct load hook name' do
|
28
|
+
it 'calls ActiveSupport.run_load_hooks with correct base' do
|
29
|
+
actual_bases = loaded_bases_by_name[load_hook_name]
|
30
|
+
|
31
|
+
expect(actual_bases).to include(described_class)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metasploit-concern
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Imhoff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- lib/metasploit/concern/engine.rb
|
49
49
|
- lib/metasploit/concern/version.rb
|
50
50
|
- lib/tasks/yard.rake
|
51
|
+
- spec/support/shared/examples/metasploit/concern/run.rb
|
51
52
|
homepage: https://github.com/rapid7/metasploit-concern
|
52
53
|
licenses:
|
53
54
|
- BSD-3-clause
|