metasploit-concern 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDM5ZDczNDk1NzkwNTYzMTMzZGZlMTNlMmY3NzJjNDExMDMyNDg1Zg==
5
+ data.tar.gz: !binary |-
6
+ ODI3MTBjNzAxNDdhNWY3ZTliYjVmMjFjN2NmNWU0MTM5NTY5Mjc2OA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MDBiMzliNWFlYzk5OWZjOGExMjc4MDYxZjQyMzJlNjRlYzIxNjJiNWFkM2Y3
10
+ N2ViNjYxY2MyZmM3MzUxMGY5YTg2NmE5YmJmNTkxZTU3MGY5Mzk3YmNhMjZk
11
+ NTk4YmMyODYwYTI1YTk0MWI2MDRmNjc4NTVkMTRlMjE3ZWI0NTQ=
12
+ data.tar.gz: !binary |-
13
+ ODM0MGY3YTZiMTNkOTYwYTg5NWRjMDIxN2JlZDA2ZDllYTVmN2E2Y2ZkZDEy
14
+ OGU3MDQyZWEyZmY5ZWFlZDcxM2ZlODg0Zjg4MGVkNmU2YjM4ZjUwYjc3YWY4
15
+ YThlYzE0Mjg5MGYyMmE4ZjlmYTZjNDAyMGJkMWI5ZTIxYWU4NmY=
data/LICENSE ADDED
@@ -0,0 +1,30 @@
1
+ ```
2
+ Copyright (c) 2013 Rapid7, Inc.
3
+
4
+ License: BSD-3-clause
5
+
6
+ Redistribution and use in source and binary forms, with or without modification,
7
+ are permitted provided that the following conditions are met:
8
+ .
9
+ * Redistributions of source code must retain the above copyright notice,
10
+ this list of conditions and the following disclaimer.
11
+ .
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+ .
16
+ * Neither the name of Rapid7 LLC nor the names of its contributors
17
+ may be used to endorse or promote products derived from this software
18
+ without specific prior written permission.
19
+ .
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ ```
data/README.md ADDED
@@ -0,0 +1,7 @@
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
+
3
+ ## Versioning
4
+
5
+ `Metasploit::Concern` is versioned using [semantic versioning 2.0](http://semver.org/spec/v2.0.0.html). Each branch
6
+ should set `Metasploit::Concern::Version::PRERELEASE` to the branch name, while master should have no `PRERELEASE`
7
+ and the `PRERELEASE` section of `Metasploit::Concern::VERSION` does not exist.
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ print_without = false
9
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
10
+
11
+ begin
12
+ load 'rails/tasks/engine.rake'
13
+ rescue LoadError
14
+ puts "railties not in bundle, so can't load engine tasks."
15
+ print_without = true
16
+ end
17
+
18
+ Bundler::GemHelper.install_tasks
19
+
20
+ #
21
+ # load rake files like a normal rails app
22
+ # @see http://viget.com/extend/rails-engine-testing-with-rspec-capybara-and-factorygirl
23
+ #
24
+
25
+ pathname = Pathname.new(__FILE__)
26
+ root = pathname.parent
27
+ rakefile_glob = root.join('lib', 'tasks', '**', '*.rake').to_path
28
+
29
+ Dir.glob(rakefile_glob) do |rakefile|
30
+ load rakefile
31
+ end
32
+
33
+ begin
34
+ require 'rspec/core'
35
+ rescue LoadError
36
+ puts "rspec not in bundle, so can't set up spec tasks. " \
37
+ "To run specs ensure to install the development and test groups."
38
+ print_without = true
39
+ else
40
+ require 'rspec/core/rake_task'
41
+
42
+ # @see http://viget.com/extend/rails-engine-testing-with-rspec-capybara-and-factorygirl
43
+ RSpec::Core::RakeTask.new(:spec)
44
+
45
+ task :default => :spec
46
+ end
47
+
48
+ if print_without
49
+ puts "Bundle currently installed '--without #{Bundler.settings.without.join(' ')}'."
50
+ puts "To clear the without option do `bundle install --without ''` (the --without flag with an empty string) or " \
51
+ "`rm -rf .bundle` to remove the .bundle/config manually and then `bundle install`"
52
+ end
@@ -0,0 +1,129 @@
1
+ # Loads ActiveSupport::Concerns (or anything that can be passed to `include` really) under {#root}
2
+ class Metasploit::Concern::Loader
3
+ include ActiveModel::Validations
4
+
5
+ #
6
+ # Attributes
7
+ #
8
+
9
+ # @!attributes [rw] root
10
+ # Pathname under which to find concerns.
11
+ #
12
+ # @return [Pathname]
13
+ attr_accessor :root
14
+
15
+ #
16
+ # Validations
17
+ #
18
+
19
+ validates :root,
20
+ presence: true
21
+
22
+ #
23
+ # Methods
24
+ #
25
+
26
+ # Yields each constant under `parent_pathname`.
27
+ #
28
+ # @param parent_pathname [Pathname]
29
+ # @yield [constant]
30
+ # @yieldparam constant [Module] constant declared under `parent_pathname`.
31
+ # @yieldreturn [void]
32
+ # @return [void]
33
+ def each_pathname_constant(parent_pathname)
34
+ parent_pathname.each_child do |child_pathname|
35
+ constant = constantize_pathname(child_pathname)
36
+
37
+ if constant
38
+ yield constant
39
+ end
40
+ end
41
+ end
42
+
43
+ # Glob pattern for concerns.
44
+ #
45
+ # @return [Pathname]
46
+ def glob
47
+ root.join('**', '*.rb')
48
+ end
49
+
50
+ # @param attributes [Hash{Symbol => String,nil}]
51
+ def initialize(attributes={})
52
+ attributes.each do |attribute, value|
53
+ public_send("#{attribute}=", value)
54
+ end
55
+ end
56
+
57
+ # Set of Pathnames for `Module`s that will have concerns included.
58
+ #
59
+ # @return [Set<Pathname>]
60
+ def module_pathname_set
61
+ concern_paths = Dir.glob(glob)
62
+
63
+ concern_paths.each_with_object(Set.new) { |concern_path, module_pathname_set|
64
+ concern_pathname = Pathname.new(concern_path)
65
+ module_pathname = concern_pathname.parent
66
+
67
+ module_pathname_set.add module_pathname
68
+ }
69
+ end
70
+
71
+ # Registers load hooks with `ActiveSupport.on_load`.
72
+ #
73
+ # @return [void]
74
+ def register
75
+ module_pathname_set.each do |module_pathname|
76
+ relative_module_pathname = module_pathname.relative_path_from(root)
77
+ relative_module_path = relative_module_pathname.to_path
78
+ underscored_module_name = relative_module_path.gsub(File::SEPARATOR, '_')
79
+ on_load_name = underscored_module_name.to_sym
80
+
81
+ # on_load block is instance_evaled, so need to capture self
82
+ loader = self
83
+
84
+ ActiveSupport.on_load(on_load_name) do
85
+ loader.each_pathname_constant(module_pathname) do |concern|
86
+ include concern
87
+ end
88
+
89
+ if defined?(Rails) && Rails.env.development?
90
+ unloadable
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ private
97
+
98
+ # Converts `descendant_pathname`, which should be under {#root}, into a constant.
99
+ #
100
+ # @param descendant_pathname [Pathname] a Pathname under {#root}.
101
+ # @return [Object] if {#pathname_to_constant_name} returns a constant name
102
+ # @return [nil] otherwise
103
+ def constantize_pathname(descendant_pathname)
104
+ constant_name = pathname_to_constant_name(descendant_pathname)
105
+
106
+ constant = nil
107
+
108
+ if constant_name
109
+ constant = constant_name.constantize
110
+ end
111
+
112
+ constant
113
+ end
114
+
115
+ # Converts `descendant_pathname`, which should be under {#root}, into a constant name.
116
+ #
117
+ # @param descendant_pathname [Pathname] a Pathname under {#root}.
118
+ def pathname_to_constant_name(descendant_pathname)
119
+ extension_name = descendant_pathname.extname
120
+ constant_name = nil
121
+
122
+ if extension_name == '.rb'
123
+ constant_pathname = descendant_pathname.relative_path_from(root)
124
+ constant_name = constant_pathname.to_s.gsub(/.rb$/, '').camelize
125
+ end
126
+
127
+ constant_name
128
+ end
129
+ end
@@ -0,0 +1,23 @@
1
+ application = Rails.application
2
+ engines = application.railties.engines
3
+
4
+ # application is an engine
5
+ engines = [application, *engines]
6
+
7
+ engines.each do |engine|
8
+ concerns_path = engine.paths['app/concerns']
9
+
10
+ if concerns_path
11
+ concerns_directories = concerns_path.existent_directories
12
+ else
13
+ # app/concerns is not set, so just derive it from root. Cannot derive from app because it will glob app/models too
14
+ concerns_directories = [engine.root.join('app', 'concerns').to_path]
15
+ end
16
+
17
+ concerns_directories.each do |concerns_directory|
18
+ concerns_pathname = Pathname.new(concerns_directory)
19
+ loader = Metasploit::Concern::Loader.new(root: concerns_pathname)
20
+ loader.register
21
+ end
22
+ end
23
+
@@ -0,0 +1,73 @@
1
+ # Only include the Rails engine when using Rails. This is for compatibility with metasploit-framework.
2
+ if defined? Rails
3
+ require 'metasploit/concern/engine'
4
+ end
5
+
6
+ # Shared namespace for metasploit gems; used in {https://github.com/rapid7/metasploit-concern metasploit-concern},
7
+ # {https://github.com/rapid7/metasploit-framework metasploit-framework}, and
8
+ # {https://github.com/rapid7/metasploit-model metasploit-model}
9
+ module Metasploit
10
+ # Automates the inclusion of concerns into classes and models from other `Rail::Engine`s by use of an app/concerns
11
+ # directory in the `Rails::Engine` that declares the concerns.
12
+ #
13
+ # The `Class` or `Module` must support the use of concerns by calling ActiveSupport.run_load_hooks with a symbol equal
14
+ # to the underscore of its name with any '/' replaced with underscores also.
15
+ #
16
+ # @example engine_that_supports_concerns/app/models/model_that_supports_concerns.rb
17
+ # class EngineThatSupportsConcerns::ModelThatSupportsConcerns
18
+ # # declared as last statement in body so that concerns can redefine everything in class
19
+ # ActiveSupport.run_load_hooks(:engine_that_supports_concerns_model_that_supports_concerns, self)
20
+ # end
21
+ #
22
+ # To include concerns from a Rails::Application add 'app/concerns' to paths and then declare concerns under
23
+ # app/concerns.
24
+ #
25
+ # @example config/application.rb
26
+ # config.paths.add 'app/concerns', autoload: true
27
+ #
28
+ # @example Concern declared in application
29
+ # # app/concerns/engine_that_supports_concerns/model_that_supports_concerns/concern_from_application.rb
30
+ # module EngineThatSupportsConcerns::ModelThatSupportsConcerns::ConcernFromApplication
31
+ # extend ActiveSupport::Concern
32
+ #
33
+ # included do
34
+ # # run with self equal to EngineThatSupportsConcerns::ModelThatSupportsConcerns, but at the end of the class
35
+ # # definition, instead of at the beginning as would be the case with
36
+ # # class EngineThatSupportsConcerns::ModelThatSupportsConcerns
37
+ # # include EngineThatSupportsConcerns::ModelThatSupportsConcerns::ModelThatSupportsConcerns
38
+ # #
39
+ # # # body
40
+ # # end
41
+ # end
42
+ # end
43
+ #
44
+ # To include concerns from a Rails::Engine add 'app/concerns' to the paths and then declare concerns under
45
+ # app/concerns.
46
+ #
47
+ # @example Rails::Engine configuration for app/concerns
48
+ # # engine_defining_concerns/lib/engine_defining_concerns/engine.rb
49
+ # module EngineDefiningConcerns
50
+ # class Engine < Rails::Engine
51
+ # config.paths.add 'app/concerns', autoload: true
52
+ # end
53
+ # end
54
+ #
55
+ # @example Concern declared in Rails::Engine
56
+ # # engine_defining_concerns/app/concerns
57
+ # module EngineThatSupportsConcerns::ModelThatSupportsConcerns::ConcernFromEngine
58
+ # extend ActiveSupport::Concern
59
+ #
60
+ # included do
61
+ # # run with self equal to EngineThatSupportsConcerns::ModelThatSupportsConcerns, but at the end of the class
62
+ # # definition, instead of at the beginning as would be the case with
63
+ # # class EngineThatSupportsConcerns::ModelThatSupportsConcerns
64
+ # # include EngineThatSupportsConcerns::ModelThatSupportsConcerns::ModelThatSupportsConcerns
65
+ # #
66
+ # # # body
67
+ # # end
68
+ # end
69
+ # end
70
+ module Concern
71
+
72
+ end
73
+ end
@@ -0,0 +1,20 @@
1
+ begin
2
+ require 'rails'
3
+ rescue LoadError => error
4
+ warn "rails could not be loaded, so Metasploit::Concern::Engine will not be defined: #{error}"
5
+ else
6
+ module Metasploit
7
+ module Concern
8
+ class Engine < ::Rails::Engine
9
+ # @see http://viget.com/extend/rails-engine-testing-with-rspec-capybara-and-factorygirl
10
+ config.generators do |g|
11
+ g.assets false
12
+ g.helper false
13
+ g.test_framework :rspec, fixture: false
14
+ end
15
+
16
+ isolate_namespace Metasploit::Concern
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ module Metasploit
2
+ module Concern
3
+ # Holds components of {VERSION} as defined by {http://semver.org/spec/v2.0.0.html semantic versioning v2.0.0}.
4
+ module Version
5
+ # The major version number.
6
+ MAJOR = 0
7
+ # The minor version number, scoped to the {MAJOR} version number.
8
+ MINOR = 0
9
+ # The patch number, scoped to the {MINOR} version number.
10
+ PATCH = 2
11
+
12
+ # The full version string, including the {MAJOR}, {MINOR}, {PATCH}, and optionally, the `PRERELEASE` in the
13
+ # {http://semver.org/spec/v2.0.0.html semantic versioning v2.0.0} format.
14
+ #
15
+ # @return [String] '{MAJOR}.{MINOR}.{PATCH}' on master. '{MAJOR}.{MINOR}.{PATCH}-<PRERELEASE>' on any branch
16
+ # other than master.
17
+ def self.full
18
+ version = "#{MAJOR}.#{MINOR}.#{PATCH}"
19
+
20
+ if defined? PRERELEASE
21
+ version = "#{version}-#{PRERELEASE}"
22
+ end
23
+
24
+ version
25
+ end
26
+ end
27
+
28
+ # @see Version.full
29
+ VERSION = Version.full
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ # @note All options not specific to any given rake task should go in the .yardopts file so they are available to both
2
+ # the below rake tasks and when invoking `yard` from the command line
3
+
4
+ if defined? YARD
5
+ namespace :yard do
6
+ YARD::Rake::YardocTask.new(:doc) do |t|
7
+ # --no-stats here as 'stats' task called after will print fuller stats
8
+ t.options = ['--no-stats']
9
+
10
+ t.after = Proc.new {
11
+ Rake::Task['yard:stats'].execute
12
+ }
13
+ end
14
+
15
+ desc "Shows stats for YARD Documentation including listing undocumented modules, classes, constants, and methods"
16
+ task :stats => :environment do
17
+ stats = YARD::CLI::Stats.new
18
+ stats.run('--compact', '--list-undoc')
19
+ end
20
+ end
21
+
22
+ # @todo Figure out how to just clone description from yard:doc
23
+ desc "Generate YARD documentation"
24
+ # allow calling namespace to as a task that goes to default task for namespace
25
+ task :yard => ['yard:doc']
26
+
27
+ task :default => :yard
28
+ else
29
+ puts 'YARD not defined, so yard tasks cannot be setup.'
30
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metasploit-concern
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Luke Imhoff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ description: Automatically includes Modules from app/concerns/<module_with_concerns>/<concern>.rb
34
+ into <module_with_concerns> to ease monkey-patching associations and validations
35
+ on ActiveRecord::Base descendents from other gems when layering schemas.
36
+ email:
37
+ - luke_imhoff@rapid7.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - LICENSE
43
+ - README.md
44
+ - Rakefile
45
+ - app/models/metasploit/concern/loader.rb
46
+ - config/initializers/load_concerns.rb
47
+ - lib/metasploit/concern.rb
48
+ - lib/metasploit/concern/engine.rb
49
+ - lib/metasploit/concern/version.rb
50
+ - lib/tasks/yard.rake
51
+ homepage: https://github.com/rapid7/metasploit-concern
52
+ licenses:
53
+ - BSD-3-clause
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.2.2
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Automatically include Modules from app/concerns
75
+ test_files: []
76
+ has_rdoc: