eco-rake 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +28 -0
  3. data/.gitlab-ci.yml +13 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +90 -0
  6. data/.yardopts +10 -0
  7. data/CHANGELOG.md +13 -0
  8. data/Gemfile +6 -0
  9. data/LICENSE +21 -0
  10. data/README.md +28 -0
  11. data/Rakefile +27 -0
  12. data/eco-rake.gemspec +34 -0
  13. data/lib/eco-rake/base/method_helpers.rb +55 -0
  14. data/lib/eco-rake/base/symbol_resolver.rb +82 -0
  15. data/lib/eco-rake/base.rb +25 -0
  16. data/lib/eco-rake/custom.rb +5 -0
  17. data/lib/eco-rake/default/const.rb +46 -0
  18. data/lib/eco-rake/default.rb +12 -0
  19. data/lib/eco-rake/lib/base_task.rb +9 -0
  20. data/lib/eco-rake/lib/concern/base.rb +21 -0
  21. data/lib/eco-rake/lib/concern/enviro.rb +23 -0
  22. data/lib/eco-rake/lib/concern/local_folder.rb +23 -0
  23. data/lib/eco-rake/lib/concern/person_schema.rb +24 -0
  24. data/lib/eco-rake/lib/concern.rb +11 -0
  25. data/lib/eco-rake/lib/export/payload.rb +78 -0
  26. data/lib/eco-rake/lib/export.rb +8 -0
  27. data/lib/eco-rake/lib/files/decrypt.rb +48 -0
  28. data/lib/eco-rake/lib/files/purge.rb +73 -0
  29. data/lib/eco-rake/lib/files/sftp.rb +49 -0
  30. data/lib/eco-rake/lib/files.rb +10 -0
  31. data/lib/eco-rake/lib/notify/mailer.rb +24 -0
  32. data/lib/eco-rake/lib/notify.rb +8 -0
  33. data/lib/eco-rake/lib/options.rb +8 -0
  34. data/lib/eco-rake/lib/people/base_task.rb +16 -0
  35. data/lib/eco-rake/lib/people/sync_launch.rb +131 -0
  36. data/lib/eco-rake/lib/people/sync_options.rb +15 -0
  37. data/lib/eco-rake/lib/people/sync_process.rb +48 -0
  38. data/lib/eco-rake/lib/people/sync_rely.rb +47 -0
  39. data/lib/eco-rake/lib/people.rb +12 -0
  40. data/lib/eco-rake/lib/task/runner_launch.rb +34 -0
  41. data/lib/eco-rake/lib/task/runner_options.rb +11 -0
  42. data/lib/eco-rake/lib/task/runner_rely.rb +40 -0
  43. data/lib/eco-rake/lib/task.rb +10 -0
  44. data/lib/eco-rake/lib.rb +15 -0
  45. data/lib/eco-rake/option/default_lookup.rb +39 -0
  46. data/lib/eco-rake/option/mirror.rb +34 -0
  47. data/lib/eco-rake/option/parented.rb +12 -0
  48. data/lib/eco-rake/option.rb +19 -0
  49. data/lib/eco-rake/options/default_lookup.rb +29 -0
  50. data/lib/eco-rake/options/forwarding/proxy.rb +125 -0
  51. data/lib/eco-rake/options/forwarding/rule.rb +82 -0
  52. data/lib/eco-rake/options/forwarding.rb +45 -0
  53. data/lib/eco-rake/options/library.rb +81 -0
  54. data/lib/eco-rake/options/parental.rb +37 -0
  55. data/lib/eco-rake/options/set.rb +21 -0
  56. data/lib/eco-rake/options.rb +25 -0
  57. data/lib/eco-rake/rake_task.rb +10 -0
  58. data/lib/eco-rake/shell/command.rb +59 -0
  59. data/lib/eco-rake/shell/eco_helpers.rb +10 -0
  60. data/lib/eco-rake/shell/files.rb +83 -0
  61. data/lib/eco-rake/shell/gpg.rb +54 -0
  62. data/lib/eco-rake/shell.rb +18 -0
  63. data/lib/eco-rake/tasks.rb +12 -0
  64. data/lib/eco-rake/utils/mailer.rb +91 -0
  65. data/lib/eco-rake/utils/mailing.rb +19 -0
  66. data/lib/eco-rake/utils/timing.rb +9 -0
  67. data/lib/eco-rake/utils.rb +19 -0
  68. data/lib/eco-rake/version.rb +5 -0
  69. data/lib/eco-rake.rb +16 -0
  70. metadata +271 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 06f88149753ab7424d569e1875bb0d0d5a914c3566b07a254fdcc6e71b101eb0
4
+ data.tar.gz: 06cac6560a9d130b858de701ac45a7015ffff6382d2a9418ba7e2f9fcbf37fbd
5
+ SHA512:
6
+ metadata.gz: cec87e0b5884b049d4a5ae70b92454050c9177b32bde8055a93240dd7138783be6ec65b9b80c2ff8e830c8832958c4714031bf54db03c336e3a5cdd599ef1a24
7
+ data.tar.gz: affe3d449e395b6c6b143f71cb2821a2bd08b30e8609cc7df27575ab65faf2d8feead5297e056ad96953c4379b5e16e1be18be1ae5df133073493b50a128225b
data/.gitignore ADDED
@@ -0,0 +1,28 @@
1
+ # env files
2
+ .env*
3
+
4
+ # core development-only executables
5
+ /bin/raked*
6
+
7
+ # it's a gem, ignore the lockfile
8
+ Gemfile.lock
9
+
10
+ # build artifacts
11
+ *.gem
12
+ /.bundle/
13
+ /vendor/bundle
14
+ /spec/reports/
15
+ /tmp/
16
+ /pkg/
17
+
18
+ # docs
19
+ /.yardoc
20
+ /_yardoc/
21
+ /coverage/
22
+ /doc/
23
+
24
+ # rspec failure tracking
25
+ .rspec_status
26
+ scratch.rb
27
+
28
+ /.byebug_history
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,13 @@
1
+ # You can override the included template(s) by including variable overrides
2
+ # SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
3
+ # Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
4
+ # Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
5
+ # Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
6
+ # Note that environment variables can be set in several places
7
+ # See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
8
+ stages:
9
+ - test
10
+ sast:
11
+ stage: test
12
+ include:
13
+ - template: Security/SAST.gitlab-ci.yml
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,90 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7.2
3
+ Exclude:
4
+ - 'config/routes.rb'
5
+
6
+ Naming/VariableNumber:
7
+ EnforcedStyle: snake_case
8
+ Naming/FileName:
9
+ Enabled: false
10
+
11
+ Metrics/LineLength:
12
+ Enabled: false
13
+ Metrics/BlockLength:
14
+ ExcludedMethods: [context, describe]
15
+ Max: 50
16
+ Metrics/MethodLength:
17
+ Max: 50
18
+ Metrics/ClassLength:
19
+ Max: 200
20
+ Metrics/ModuleLength:
21
+ Max: 200
22
+ Metrics/AbcSize:
23
+ Max: 50
24
+ Exclude:
25
+ - 'lib/eco-rake/base/method_helpers.rb'
26
+ Metrics/CyclomaticComplexity:
27
+ Max: 10
28
+ Exclude:
29
+ - 'lib/eco-rake/base/method_helpers.rb'
30
+ Metrics/PerceivedComplexity:
31
+ Max: 10
32
+ Exclude:
33
+ - 'lib/eco-rake/base/method_helpers.rb'
34
+
35
+ ParameterLists:
36
+ Max: 5
37
+ CountKeywordArgs: false
38
+
39
+ Style/Alias:
40
+ EnforcedStyle: prefer_alias_method
41
+ Style/StringLiterals:
42
+ Enabled: false
43
+ Style/FrozenStringLiteralComment:
44
+ Enabled: false
45
+ Style/CommentedKeyword:
46
+ Enabled: false
47
+ Style/MultilineBlockChain:
48
+ Enabled: false
49
+ Style/Documentation:
50
+ Enabled: false
51
+ Style/StringLiteralsInInterpolation:
52
+ Enabled: false
53
+ Style/AndOr:
54
+ Enabled: false
55
+ Style/SlicingWithRange:
56
+ Enabled: false
57
+ Style/ClassAndModuleChildren:
58
+ Enabled: false
59
+ Style/OptionalBooleanParameter:
60
+ Enabled: false
61
+
62
+ Layout/HashAlignment:
63
+ EnforcedColonStyle: table
64
+ Layout/ArgumentAlignment:
65
+ EnforcedStyle: with_fixed_indentation
66
+ Layout/ExtraSpacing:
67
+ AllowForAlignment: true
68
+ Layout/AccessModifierIndentation:
69
+ EnforcedStyle: indent
70
+ Layout/DotPosition:
71
+ EnforcedStyle: trailing
72
+ Layout/MultilineMethodCallIndentation:
73
+ EnforcedStyle: indented
74
+ Layout/SpaceInsideHashLiteralBraces:
75
+ Enabled: false
76
+ Layout/SpaceInsideBlockBraces:
77
+ Enabled: false
78
+ Layout/SpaceAroundOperators:
79
+ Enabled: false
80
+ Layout/FirstHashElementIndentation:
81
+ Enabled: false
82
+ Layout/EmptyLineAfterGuardClause:
83
+ Enabled: false
84
+ Layout/LeadingCommentSpace:
85
+ Enabled: false
86
+
87
+ Lint/AssignmentInCondition:
88
+ Enabled: false
89
+ Lint/UnderscorePrefixedVariableName:
90
+ Enabled: false
data/.yardopts ADDED
@@ -0,0 +1,10 @@
1
+ --readme README.md
2
+ --charset utf-8
3
+ --markup-provider=redcarpet
4
+ --markup=markdown
5
+ --no-private
6
+ --output-dir ./doc
7
+ 'lib/**/*.rb'
8
+ -
9
+ CHANGELOG.md
10
+ LICENSE
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ ## [0.1.1] - 2023-06-xx
5
+
6
+ ### Added
7
+ ### Fixed
8
+ ### Changed
9
+
10
+ ## [0.1.1] - 2023-06-06
11
+
12
+ ### Added
13
+ - Very first version, with support to migrate all the rake integrations.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in eco-rake.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 ecoPortal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # EcoRake
2
+
3
+ A set of helpers to build re-usable `rake` integration helpers.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'eco-rake', require: %w[eco-rake]
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install eco-rake
20
+
21
+ ## Usage
22
+
23
+
24
+ ## Development
25
+
26
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
27
+
28
+ For more info on available `Rake` tasks: `rake -T`
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "yard"
4
+ require "redcarpet"
5
+
6
+ desc "run the specs"
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ desc "run rspec showing backtrace"
10
+ RSpec::Core::RakeTask.new(:spec_trace) do |task|
11
+ task.rspec_opts = ['--backtrace']
12
+ end
13
+
14
+ desc "run rspec stopping on first fail, and show backtrace"
15
+ RSpec::Core::RakeTask.new(:spec_fast) do |task|
16
+ task.rspec_opts = ['--fail-fast', '--backtrace']
17
+ end
18
+
19
+ # default task name is yard
20
+ desc "Yard: generate all the documentation"
21
+ YARD::Rake::YardocTask.new(:doc) do |t|
22
+ #t.files = ['lib/**/*.rb']
23
+ end
24
+
25
+ task default: [:spec]
26
+ task rspec_trace: :spec_trace
27
+ task rspec_fast: :spec_fast
data/eco-rake.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "eco-rake/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "eco-rake"
7
+ spec.version = EcoRake::VERSION
8
+ spec.authors = ["Oscar Segura Samper"]
9
+ spec.email = ["oscar@ecoportal.co.nz"]
10
+
11
+ spec.summary = 'A set of helpers to build re-usable `rake` integration helpers.'
12
+ spec.homepage = "https://www.ecoportal.com"
13
+ spec.licenses = %w[MIT]
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.required_ruby_version = '>= 2.7.2'
23
+
24
+ spec.add_development_dependency "bundler", ">= 2.4.9", "< 3"
25
+ spec.add_development_dependency "rake", ">= 13.0.6", "< 14"
26
+ spec.add_development_dependency "redcarpet", ">= 3.6.0", "< 4"
27
+ spec.add_development_dependency "rspec", ">= 3.10.0", "< 4"
28
+ spec.add_development_dependency "yard", ">= 0.9.34", "< 1"
29
+
30
+ #spec.add_dependency 'aws-sdk-s3', '>= 1.83.0', '< 2'
31
+ spec.add_dependency 'aws-sdk-ses', '>= 1.36.0', '< 2'
32
+ spec.add_dependency 'dotenv', '>= 2.7.6', '< 3'
33
+ spec.add_dependency 'rake-commander', '>= 0.3.6', "< 0.4"
34
+ end
@@ -0,0 +1,55 @@
1
+ class EcoRake
2
+ module Base
3
+ module MethodHelpers
4
+ # Calls `method` with just the parameters it requires
5
+ # @note missing arguments required arguments will be passed as `nil` value.
6
+ # @return the result of the call.
7
+ def safe_call(meth, *args, **kargs, &block)
8
+ msg = "Expecting Method or Proc. Given: #{meth.class}"
9
+ raise ArgumentError, msg unless [Method, Proc].any? {|c| meth.is_a?(c)}
10
+ aux_curry(meth, :safe).call(*args, **kargs, &block)
11
+ end
12
+
13
+ # @param meth [Method, Proc, Lambda]
14
+ # @param on_missing [Symbol] what should do when there are missing parameters
15
+ # - `:curry` -> it does a curry with the parameters received (default)
16
+ # - `:call` -> it calls anyway (will error).
17
+ # - `:safe` -> it sets to `nil` the missing required arguments and does a call.
18
+ # - `:return` -> it returns `nil` but doesn't call.
19
+ # @return [Lambda, NilClass, Result]
20
+ def aux_curry(meth, on_missing = :curry)
21
+ lambda do |*args, **kargs, &block|
22
+ params = meth.parameters
23
+ kparams = params.select { |type, _| (type == :keyreq) || (type == :key) }
24
+ aparams = params.select { |type, _| (type == :req) || (type == :opt) }
25
+
26
+ kreq_miss = kparams.select { |type, _| type == :keyreq }.map(&:last) - kargs.keys
27
+ req_miss = aparams.select { |type, _| type == :req }.count - args.count
28
+ req_miss = req_miss >= 0 ? req_miss : 0
29
+ ready = kreq_miss.empty? && req_miss.zero?
30
+
31
+ if on_missing == :safe
32
+ argrest = params.find { |type, _| type == :rest }
33
+ keyrest = params.find { |type, _| type == :keyrest }
34
+ kextras = kargs.keys - kparams.map(&:last)
35
+ kextras.each { |name| kargs.delete(name) } unless keyrest
36
+ args = args[0..(aparams.count-1)] unless argrest || args.count <= aparams.count
37
+ unless ready
38
+ kreq_miss.each { |name| kargs[name] = nil }
39
+ ary_nil = Array.new(req_miss, nil)
40
+ args = args.dup.push(*ary_nil)
41
+ ready = true
42
+ end
43
+ end
44
+ return meth.call(*args, **kargs, &block) if ready || on_missing == :call
45
+ return nil if on_missing == :return
46
+ # (default) on_missing == :curry
47
+ lambda do |*oth, **koth, &blk|
48
+ curried = aux_curry(meth, on_missing)
49
+ curried[*args, *oth, **kargs, **koth, &(blk || block)]
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,82 @@
1
+ class EcoRake
2
+ module Base
3
+ module SymbolResolver
4
+ include EcoRake::Base::MethodHelpers
5
+
6
+ # i.e. value = `:default_value` -> `'DEFAULT_VALUE'`
7
+ def constant_name(value)
8
+ case value
9
+ when String
10
+ value.strip.upcase
11
+ when Symbol
12
+ constant_name(value.to_s)
13
+ end
14
+ end
15
+
16
+ # Wraps a symbol to be resolved lazyly.
17
+ # @note the resolution process goes in this order
18
+ # 1. First try on the `invoker` and its class.
19
+ # 2. Final on the `definer` and its class.
20
+ # @return [Proc] a callback that will resolve the symbol.
21
+ def symbol_resolver(sym, as: %i[method const])
22
+ definer = self
23
+ proc do |invoker|
24
+ resolution = invoker.instance_eval do
25
+ definer.resolve_symbol(sym, source: invoker, as: as)
26
+ end
27
+ resolution ||= definer.resolve_symbol(sym, source: definer, as: as)
28
+ resolution
29
+ end
30
+ end
31
+
32
+ # @param sym [Symbol, String] that we try to resolve to a value of a constant.
33
+ # @param as [Symbol, Array<Symbol>] the order in which it should try to look up.
34
+ # @return [Method, Value, NilClass] either the value of constant, a method or `nil`
35
+ # if not found.
36
+ def resolve_symbol(sym, source: self, as: %i[method const])
37
+ as = [as].flatten.compact
38
+ as.reduce(nil) do |value, type|
39
+ case type
40
+ when :const
41
+ value || resolve_const(sym, source: source)
42
+ when :method
43
+ value || resolve_method(sym, source: source)
44
+ end
45
+ end
46
+ end
47
+
48
+ # @param sym [Symbol, String] that we try to resolve to a value of a constant.
49
+ # @return [Value, NilClass] `nil` when unresolved, the value of the constant otherwise.
50
+ def resolve_const(sym, source: self)
51
+ return nil unless sym.is_a?(Symbol) || sym.is_a?(String)
52
+ sym = constant_name(sym)
53
+ value = nil
54
+ value ||= safe_const_get(sym, klass: source)
55
+ value ||= safe_const_get(sym, klass: Kernel)
56
+ value
57
+ rescue NameError
58
+ nil
59
+ end
60
+
61
+ # @note it does not raise ErrorName
62
+ # @return [Value, NilClass] returns `nil` if const not defined or the value of the constant.
63
+ def safe_const_get(name, klass: self)
64
+ klass = klass.class unless klass.is_a?(Class) || klass == Kernel
65
+ klass.const_get(name) if klass.const_defined?(name)
66
+ rescue NameError
67
+ nil
68
+ end
69
+
70
+ # @param sym [Symbol, String] that we try to resolve to a method.
71
+ # @return [Method, NilClass] `nil` when unresolved, the `method` otherwise.
72
+ def resolve_method(sym, source: self)
73
+ return nil unless sym.is_a?(Symbol) || sym.is_a?(String)
74
+ meth = source.method(sym) if source.respond_to?(sym, true)
75
+ return meth if meth
76
+ return nil if source.is_a?(Class)
77
+ return nil unless source.class.respond_to?(sym, true)
78
+ source.class.method(sym)
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'base/method_helpers'
2
+ require_relative 'base/symbol_resolver'
3
+ require_relative 'default'
4
+ require_relative 'utils'
5
+ require_relative 'shell'
6
+ require_relative 'rake_task'
7
+ require_relative 'option'
8
+ require_relative 'options'
9
+
10
+ class EcoRake
11
+ module Base
12
+ class << self
13
+ def included(base)
14
+ super(base)
15
+ base.autoloads_children_of RakeCommander
16
+ base.extend ClassMethods
17
+ base.send :include, RakeTask
18
+ base.send :include, Options
19
+ end
20
+ end
21
+
22
+ module ClassMethods
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ # Provides a namespace to declare task classes
2
+ class EcoRake
3
+ module Custom
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ class EcoRake
2
+ module Default
3
+ module Const
4
+ class << self
5
+ def included(base)
6
+ super(base)
7
+ base.extend EcoRake::Base::SymbolResolver
8
+ base.extend ClassMethods
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ # Creates (overridable) method(s) that link to an expected constant with same name (in capitals).
14
+ # @note this creates one method on the class and one on instances thereof.
15
+ # @param required [Boolean] whether an exception should be raised if the constant does not exist
16
+ # when the created method is called.
17
+ # @param override [Boolean] whether an exception should NOT be raised if the method exists.
18
+ # @param default [Variant] whether if this defaults to some value (won't raise NameError).
19
+ def attr_const(*attrs, required: false, override: false, default: :not_used)
20
+ attrs.each do |attr|
21
+ attr = attr.to_s.freeze
22
+
23
+ unless override
24
+ msg = "#{__method__} does not allow method override. Offending attr: #{attr}"
25
+ raise ArgumentError, "#{msg} (class method)" if methods.include?(attr)
26
+ raise ArgumentError, "#{msg} (instance method)" if instance_methods.include?(attr)
27
+ end
28
+
29
+ define_singleton_method attr do
30
+ msg = "Missing const '#{attr.to_s.upcase}' in #{self}"
31
+ value = resolve_const(attr)
32
+ value = default if value.nil? && default != :not_used
33
+ raise NameError, msg if value.nil? && required
34
+ yield(value) if block_given?
35
+ value
36
+ end
37
+
38
+ define_method attr do |&block|
39
+ self.class.send(attr, &block)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,12 @@
1
+ require_relative 'default/const'
2
+
3
+ class EcoRake
4
+ module Default
5
+ class << self
6
+ def included(base)
7
+ super(base)
8
+ base.send :include, Const
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ class EcoRake
2
+ module Lib
3
+ # Class with libs to ease task built
4
+ class BaseTask < EcoRake
5
+ include EcoRake::Utils
6
+ include EcoRake::Shell
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ class EcoRake
2
+ module Sample
3
+ module Concern
4
+ module Base
5
+ class << self
6
+ def included(base)
7
+ super(base)
8
+ base.extend ClassMethods
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ def included(base)
14
+ super(base)
15
+ base.extend self::ClassMethods if defined?(self::ClassMethods)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ class EcoRake
2
+ module Sample
3
+ module Concern
4
+ module Enviro
5
+ include EcoRake::Sample::Concern::Base
6
+
7
+ class << self
8
+ def included(base)
9
+ super(base)
10
+ base.option '-e', '--enviro ENVIRO', default_lookup: :default_enviro
11
+ end
12
+ end
13
+
14
+ module ClassMethods
15
+ def default_enviro
16
+ raise "Missing const 'DEFAULT_ENVIRO'" unless defined?(self::DEFAULT_ENVIRO)
17
+ self::DEFAULT_ENVIRO
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ class EcoRake
2
+ module Sample
3
+ module Concern
4
+ module LocalFolder
5
+ include EcoRake::Sample::Concern::Base
6
+
7
+ class << self
8
+ def included(base)
9
+ super(base)
10
+ base.option '-d', '--folder NAME', default_lookup: :default_local_folder, desc: 'Source local folder'
11
+ end
12
+ end
13
+
14
+ module ClassMethods
15
+ def default_local_folder
16
+ return '.' unless defined?(self::DEFAULT_LOCAL_FOLDER)
17
+ self::DEFAULT_LOCAL_FOLDER
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ class EcoRake
2
+ module Sample
3
+ module Concern
4
+ # It adds the configurable option person schema
5
+ module PersonSchema
6
+ include EcoRake::Sample::Concern::Base
7
+
8
+ class << self
9
+ def included(base)
10
+ super(base)
11
+ base.option '-c', '--schema NAME', default_lookup: :default_person_schema, desc: "Target person schema."
12
+ end
13
+ end
14
+
15
+ module ClassMethods
16
+ def default_person_schema
17
+ raise "Missing const 'DEFAULT_PERSON_SCHEMA'" unless defined?(self::DEFAULT_PERSON_SCHEMA)
18
+ self::DEFAULT_PERSON_SCHEMA
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'concern/base'
2
+ require_relative 'concern/enviro'
3
+ require_relative 'concern/person_schema'
4
+ require_relative 'concern/local_folder'
5
+
6
+ class EcoRake
7
+ module Sample
8
+ module Concern
9
+ end
10
+ end
11
+ end