eac_tools 0.11.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +21 -21
- data/lib/eac_tools/version.rb +1 -1
- data/sub/avm/avm.gemspec +2 -2
- data/sub/avm/lib/avm/application_stereotypes/base.rb +11 -1
- data/sub/avm/lib/avm/instances/base/auto_values/install.rb +48 -0
- data/sub/avm/lib/avm/instances/base/auto_values.rb +1 -1
- data/sub/avm/lib/avm/instances/base.rb +4 -4
- data/sub/avm/lib/avm/instances/entry_keys.rb +7 -6
- data/sub/avm/lib/avm/instances.rb +3 -2
- data/sub/avm/lib/avm/registry/application_stereotypes/build_available.rb +9 -6
- data/sub/avm/lib/avm/registry/application_stereotypes/stereotype_builder.rb +8 -5
- data/sub/avm/lib/avm/registry/source_generators.rb +16 -0
- data/sub/avm/lib/avm/registry.rb +2 -1
- data/sub/avm/lib/avm/scms/base.rb +2 -2
- data/sub/avm/lib/avm/source_generators/base.rb +29 -0
- data/sub/avm/lib/avm/source_generators.rb +9 -0
- data/sub/avm/lib/avm/sources/base.rb +4 -4
- data/sub/avm/lib/avm/version.rb +1 -1
- data/sub/avm/lib/avm/with/application_stereotype.rb +35 -0
- data/sub/avm/lib/avm/with/extra_subcommands.rb +44 -0
- data/sub/avm/spec/lib/avm/instances/base_spec.rb +3 -3
- data/sub/avm/spec/lib/avm/instances/base_spec_configs_storage.yml +1 -1
- data/sub/avm-eac_rails_base0/avm-eac_rails_base0.gemspec +3 -3
- data/sub/avm-eac_rails_base0/lib/avm/eac_rails_base0/source_generators/base.rb +13 -0
- data/sub/avm-eac_rails_base0/lib/avm/eac_rails_base0/version.rb +1 -1
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/Gemfile +11 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/Rakefile +8 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/app/assets/config/manifest.js +3 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/app/assets/javascripts/application.js +1 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/app/assets/stylesheets/application.scss +1 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/app/controllers/application_controller.rb +4 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/app/controllers/welcome_controller.rb +5 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/app/views/welcome/index.html.erb +1 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/bin/bundle +5 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/bin/rails +11 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/bin/rake +11 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/bin/yarn +11 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/config/application.rb +11 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/config/boot.rb +5 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/config/cable.yml +8 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/config/credentials.yml.enc +1 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/config/environment.rb +7 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/config/puma.rb +39 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/config/routes.rb +5 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/config/spring.rb +8 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/config.ru +7 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/db/schema.rb +1 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/lib/ability.rb +20 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/lib/ability_mapping.rb +10 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/public/favicon.ico +0 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/spec/code/rubocop_spec.rb +3 -0
- data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/spec/spec_helper.rb +8 -0
- data/sub/avm-eac_rails_base1/avm-eac_rails_base1.gemspec +3 -2
- data/sub/avm-eac_rails_base1/lib/avm/eac_rails_base1/systemd_unit.rb +1 -1
- data/sub/avm-eac_rails_base1/lib/avm/eac_rails_base1/version.rb +1 -1
- data/sub/avm-tools/README.textile +0 -11
- data/sub/avm-tools/avm-tools.gemspec +1 -2
- data/sub/avm-tools/lib/avm/tools/runner/source_generate.rb +45 -0
- data/sub/avm-tools/lib/avm/tools/version.rb +1 -1
- data/sub/eac_config/eac_config.gemspec +1 -1
- data/sub/eac_config/lib/eac_config/entry_path.rb +15 -4
- data/sub/eac_config/lib/eac_config/version.rb +1 -1
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/regexp_parser.rb +5 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb +67 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/sub_file.rb +68 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +2 -125
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/{require_sub_spec → require_sub/base_spec}/stubbed_module_a.rb +0 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/{require_sub_spec → require_sub/base_spec}/stubbed_not_module.rb +0 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/{require_sub_spec.rb → require_sub/base_spec.rb} +1 -1
- metadata +56 -16
- data/sub/avm/lib/avm/instances/base/auto_values/access.rb +0 -40
- data/sub/avm/lib/avm/with_application_stereotype.rb +0 -23
- data/sub/avm/lib/avm/with_dynamic_runners.rb +0 -42
@@ -0,0 +1 @@
|
|
1
|
+
<p>Bem-vindo!</p>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
begin
|
5
|
+
load File.expand_path('spring', __dir__)
|
6
|
+
rescue LoadError => e
|
7
|
+
raise unless e.message.include?('spring')
|
8
|
+
end
|
9
|
+
APP_PATH = File.expand_path('../config/application', __dir__)
|
10
|
+
require_relative '../config/boot'
|
11
|
+
require 'rails/commands'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
5
|
+
Dir.chdir(APP_ROOT) do
|
6
|
+
exec 'yarnpkg', *ARGV
|
7
|
+
rescue Errno::ENOENT
|
8
|
+
warn 'Yarn executable was not detected in the system.'
|
9
|
+
warn 'Download Yarn at https://yarnpkg.com/en/docs/install'
|
10
|
+
exit 1
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
APP_PATH = ::File.dirname(__dir__) unless defined?(APP_PATH)
|
4
|
+
require File.expand_path('boot', __dir__)
|
5
|
+
require 'eac_rails_base0/app_base/application.rb'
|
6
|
+
|
7
|
+
module EacRailsBase0App
|
8
|
+
class Application
|
9
|
+
config.load_defaults 5.2
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
XKDkD3DioFn69hXAhH88mw9ZFRjDdarYU+7htxgTJmBB/vg45Hsb7pBJQaySoc7VD0Vb838ShDeVbhDlSc3PMtIcV6fU/nkYqc+Nu8heKF5mhJmgJmf2Vlp2ZgqVA04PxvmZ/U2FRx40c9welNpABmDn0V33qUsjkrVMqKuyxD9aTpuAFd4SiH7SzA8Is1v7ltr3+Rx0lA/LI2u87uxYBawE7G3sNQA9siEnSPNm24uEK+4GcIuVG0qIvx36uYyBjB8dfn9FaMec/+22EFNKO0JWjIFXRl+TosE3VLFssaMQ2sl0rRkesLzb2DMFO/7kp0T3c1EcvRmy0AJ3UQmKZCtYBzy2a/9rx8sh1a+AUHObSeSeaP4eu+sMnMhSsDhveUiYMnV8viJXj0G0V6UIWP4j+Bv96H/AFgNi--OD4Iuvmt7P3BlyOR--nzDLthG3dBOX14A2J5s4CA==
|
data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/config/puma.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Puma can serve each request in a thread from an internal thread pool.
|
4
|
+
# The `threads` method setting takes two numbers: a minimum and maximum.
|
5
|
+
# Any libraries that use thread pools should be configured to match
|
6
|
+
# the maximum value specified for Puma. Default is set to 5 threads for minimum
|
7
|
+
# and maximum; this matches the default thread size of Active Record.
|
8
|
+
#
|
9
|
+
threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }
|
10
|
+
threads threads_count, threads_count
|
11
|
+
|
12
|
+
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
|
13
|
+
#
|
14
|
+
port ENV.fetch('PORT') { 3000 }
|
15
|
+
|
16
|
+
# Specifies the `environment` that Puma will run in.
|
17
|
+
#
|
18
|
+
environment ENV.fetch('RAILS_ENV') { 'development' }
|
19
|
+
|
20
|
+
# Specifies the `pidfile` that Puma will use.
|
21
|
+
pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' }
|
22
|
+
|
23
|
+
# Specifies the number of `workers` to boot in clustered mode.
|
24
|
+
# Workers are forked webserver processes. If using threads and workers together
|
25
|
+
# the concurrency of the application would be max `threads` * `workers`.
|
26
|
+
# Workers do not work on JRuby or Windows (both of which do not support
|
27
|
+
# processes).
|
28
|
+
#
|
29
|
+
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
|
30
|
+
|
31
|
+
# Use the `preload_app!` method when specifying a `workers` number.
|
32
|
+
# This directive tells Puma to first boot the application and load code
|
33
|
+
# before forking the application. This takes advantage of Copy On Write
|
34
|
+
# process behavior so workers use less memory.
|
35
|
+
#
|
36
|
+
# preload_app!
|
37
|
+
|
38
|
+
# Allow puma to be restarted by `rails restart` command.
|
39
|
+
plugin :tmp_restart
|
@@ -0,0 +1 @@
|
|
1
|
+
|
data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/lib/ability.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Ability < ::EacRailsBase0::AppBase::Ability
|
4
|
+
def initialize(user)
|
5
|
+
super(user)
|
6
|
+
user ||= ::EacUsersSupport::User.new
|
7
|
+
for_all_permissions(user)
|
8
|
+
logged_permissions(user) unless user.new_record?
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def for_all_permissions(_user)
|
14
|
+
can :read, :welcome
|
15
|
+
end
|
16
|
+
|
17
|
+
def logged_permissions(_user)
|
18
|
+
can :manage, :all
|
19
|
+
end
|
20
|
+
end
|
data/sub/avm-eac_rails_base0/template/avm/eac_rails_base0/source_generators/base/public/favicon.ico
ADDED
File without changes
|
@@ -12,9 +12,10 @@ Gem::Specification.new do |s|
|
|
12
12
|
|
13
13
|
s.files = Dir['{lib,template}/**/*']
|
14
14
|
|
15
|
-
s.add_dependency 'avm
|
15
|
+
s.add_dependency 'avm', '~> 0.31'
|
16
|
+
s.add_dependency 'avm-eac_ruby_base1', '~> 0.11'
|
16
17
|
s.add_dependency 'avm-eac_webapp_base0', '~> 0.3'
|
17
|
-
s.add_dependency 'eac_ruby_utils', '~> 0.
|
18
|
+
s.add_dependency 'eac_ruby_utils', '~> 0.97'
|
18
19
|
|
19
20
|
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
|
20
21
|
end
|
@@ -26,14 +26,3 @@ h2. Instance's entries suffixes
|
|
26
26
|
| system.username | Name of user that runs instance | @host_id->system.username or self->ssh.username@ |
|
27
27
|
| web.url | Root URL to web interface | @nil@ |
|
28
28
|
| web.hostname | Hostname of web interface | @web.url->hostname@ |
|
29
|
-
|
30
|
-
h2. Instances' types hierarchy
|
31
|
-
|
32
|
-
* base
|
33
|
-
** eac_ruby_base0
|
34
|
-
** eac_ubuntu_base0
|
35
|
-
** eac_webapp_base0
|
36
|
-
*** eac_rails_base1
|
37
|
-
**** eac_rails_base0
|
38
|
-
**** eac_redmine_base0
|
39
|
-
*** eac_wordpress_base0
|
@@ -15,9 +15,8 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
16
16
|
|
17
17
|
s.add_dependency 'aranha-parsers', '~> 0.4'
|
18
|
-
s.add_dependency 'avm', '~> 0.
|
18
|
+
s.add_dependency 'avm', '~> 0.30'
|
19
19
|
s.add_dependency 'avm-eac_asciidoctor_base0', '~> 0.3', '>= 0.3.4'
|
20
|
-
s.add_dependency 'avm-eac_rails_base0', '~> 0.3'
|
21
20
|
s.add_dependency 'avm-eac_ruby_base1', '~> 0.8'
|
22
21
|
s.add_dependency 'avm-eac_ubuntu_base0', '~> 0.3'
|
23
22
|
s.add_dependency 'avm-files', '~> 0.1'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/runners/base'
|
4
|
+
require 'eac_cli/core_ext'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Tools
|
8
|
+
class Runner
|
9
|
+
class SourceGenerate
|
10
|
+
runner_with :help do
|
11
|
+
pos_arg :stereotype_name
|
12
|
+
pos_arg :target_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
start_banner
|
17
|
+
generate
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate
|
21
|
+
infom 'Generating...'
|
22
|
+
generator.perform
|
23
|
+
success "Source generated in \"#{generator.target_path}\""
|
24
|
+
end
|
25
|
+
|
26
|
+
def start_banner
|
27
|
+
infov 'Stereotype', stereotype_name
|
28
|
+
infov 'Target path', target_path
|
29
|
+
infov 'Generator', generator.class
|
30
|
+
end
|
31
|
+
|
32
|
+
def generator_uncached
|
33
|
+
::Avm::Registry.source_generators.detect_optional(stereotype_name, target_path) ||
|
34
|
+
fatal_error("No generator found for stereotype \"#{stereotype_name}\"")
|
35
|
+
end
|
36
|
+
|
37
|
+
delegate :stereotype_name, to: :parsed
|
38
|
+
|
39
|
+
def target_path
|
40
|
+
parsed.target_path.to_pathname
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.files = Dir['{lib}/**/*']
|
14
14
|
|
15
15
|
s.add_dependency 'addressable'
|
16
|
-
s.add_dependency 'eac_ruby_utils', '~> 0.
|
16
|
+
s.add_dependency 'eac_ruby_utils', '~> 0.97'
|
17
17
|
|
18
18
|
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
|
19
19
|
end
|
@@ -28,17 +28,28 @@ module EacConfig
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
def initialize(parts)
|
34
|
-
@parts = parts.to_a.freeze
|
31
|
+
common_constructor :parts, default: [[]] do
|
32
|
+
self.parts = ::Array.new(parts).freeze
|
35
33
|
end
|
36
34
|
|
35
|
+
compare_by :parts
|
36
|
+
delegate :any?, :count, :each, :each_value, :each_with_index, :empty?, :fetch, :first, :index,
|
37
|
+
:inject, :last, :map, :size, to: :parts
|
38
|
+
|
37
39
|
# @return [EacConfig::EntryPath]
|
38
40
|
def +(other)
|
39
41
|
self.class.new(parts + self.class.assert(other).parts)
|
40
42
|
end
|
41
43
|
|
44
|
+
def [](*args)
|
45
|
+
slice(*args)
|
46
|
+
end
|
47
|
+
|
48
|
+
def slice(*args)
|
49
|
+
r = parts.slice(*args)
|
50
|
+
r.is_a?(::Enumerable) ? self.class.new(r) : r
|
51
|
+
end
|
52
|
+
|
42
53
|
def to_s
|
43
54
|
"#{self.class}[#{parts.join(PART_SEPARATOR)}]"
|
44
55
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/listable'
|
4
|
+
require 'eac_ruby_utils/require_sub/sub_file'
|
5
|
+
|
6
|
+
module EacRubyUtils
|
7
|
+
module RequireSub
|
8
|
+
class Base
|
9
|
+
INCLUDE_MODULES_MAP = {
|
10
|
+
nil => nil,
|
11
|
+
false => nil,
|
12
|
+
true => :include,
|
13
|
+
include: :include,
|
14
|
+
prepend: :prepend
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
include ::EacRubyUtils::Listable
|
18
|
+
lists.add_symbol :option, :base, :include_modules, :require_dependency
|
19
|
+
|
20
|
+
attr_reader :file, :options
|
21
|
+
|
22
|
+
def initialize(file, options = {})
|
23
|
+
@file = file
|
24
|
+
@options = self.class.lists.option.hash_keys_validate!(options)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Boolean]
|
28
|
+
def active_support_require?
|
29
|
+
options[OPTION_REQUIRE_DEPENDENCY] ? true : false
|
30
|
+
end
|
31
|
+
|
32
|
+
def apply
|
33
|
+
require_sub_files
|
34
|
+
include_modules
|
35
|
+
end
|
36
|
+
|
37
|
+
def base
|
38
|
+
options[OPTION_BASE] || raise('Option :base not setted')
|
39
|
+
end
|
40
|
+
|
41
|
+
def base?
|
42
|
+
options[OPTION_BASE] ? true : false
|
43
|
+
end
|
44
|
+
|
45
|
+
def include_modules
|
46
|
+
sub_files.each(&:include_module)
|
47
|
+
end
|
48
|
+
|
49
|
+
def include_or_prepend_method
|
50
|
+
return INCLUDE_MODULES_MAP.fetch(options[OPTION_INCLUDE_MODULES]) if
|
51
|
+
INCLUDE_MODULES_MAP.key?(options[OPTION_INCLUDE_MODULES])
|
52
|
+
|
53
|
+
raise ::ArgumentError, "Invalid value for 'options[OPTION_INCLUDE_MODULES]':" \
|
54
|
+
" \"#{options[OPTION_INCLUDE_MODULES]}\""
|
55
|
+
end
|
56
|
+
|
57
|
+
def require_sub_files
|
58
|
+
sub_files.each(&:require_file)
|
59
|
+
end
|
60
|
+
|
61
|
+
def sub_files
|
62
|
+
@sub_files ||= Dir["#{File.dirname(file)}/#{::File.basename(file, '.*')}/*.rb"].sort
|
63
|
+
.map { |path| ::EacRubyUtils::RequireSub::SubFile.new(self, path) }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/dependencies'
|
4
|
+
require 'active_support/inflector'
|
5
|
+
|
6
|
+
module EacRubyUtils
|
7
|
+
module RequireSub
|
8
|
+
class SubFile
|
9
|
+
attr_reader :owner, :path
|
10
|
+
|
11
|
+
def initialize(owner, path)
|
12
|
+
@owner = owner
|
13
|
+
@path = path
|
14
|
+
end
|
15
|
+
|
16
|
+
def base_constant
|
17
|
+
return nil unless owner.base?
|
18
|
+
|
19
|
+
owner.base.const_get(constant_name)
|
20
|
+
rescue ::NameError
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def constant_name
|
25
|
+
::ActiveSupport::Inflector.camelize(::File.basename(path, '.rb'))
|
26
|
+
end
|
27
|
+
|
28
|
+
def include_module
|
29
|
+
return unless module?
|
30
|
+
|
31
|
+
owner.include_or_prepend_method.if_present do |v|
|
32
|
+
owner.base.send(v, base_constant)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def module?
|
37
|
+
base_constant.is_a?(::Module) && !base_constant.is_a?(::Class)
|
38
|
+
end
|
39
|
+
|
40
|
+
def require_file
|
41
|
+
active_support_require || autoload_require || kernel_require
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def active_support_require
|
47
|
+
return false unless owner.active_support_require?
|
48
|
+
|
49
|
+
::Kernel.require_dependency(path)
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
53
|
+
def autoload_require
|
54
|
+
return false unless owner.base?
|
55
|
+
|
56
|
+
basename = ::File.basename(path, '.*')
|
57
|
+
return false if basename.start_with?('_')
|
58
|
+
|
59
|
+
owner.base.autoload ::ActiveSupport::Inflector.camelize(basename), path
|
60
|
+
true
|
61
|
+
end
|
62
|
+
|
63
|
+
def kernel_require
|
64
|
+
::Kernel.require(path)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,134 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'active_support/dependencies'
|
5
|
-
require 'eac_ruby_utils/listable'
|
3
|
+
require 'eac_ruby_utils/require_sub/base'
|
6
4
|
|
7
5
|
module EacRubyUtils
|
8
6
|
class << self
|
9
7
|
def require_sub(file, options = {})
|
10
|
-
::EacRubyUtils::RequireSub.new(file, options).apply
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class RequireSub
|
15
|
-
INCLUDE_MODULES_MAP = {
|
16
|
-
nil => nil,
|
17
|
-
false => nil,
|
18
|
-
true => :include,
|
19
|
-
include: :include,
|
20
|
-
prepend: :prepend
|
21
|
-
}.freeze
|
22
|
-
|
23
|
-
include ::EacRubyUtils::Listable
|
24
|
-
lists.add_symbol :option, :base, :include_modules, :require_dependency
|
25
|
-
|
26
|
-
attr_reader :file, :options
|
27
|
-
|
28
|
-
def initialize(file, options = {})
|
29
|
-
@file = file
|
30
|
-
@options = self.class.lists.option.hash_keys_validate!(options)
|
31
|
-
end
|
32
|
-
|
33
|
-
def apply
|
34
|
-
require_sub_files
|
35
|
-
include_modules
|
36
|
-
end
|
37
|
-
|
38
|
-
def base
|
39
|
-
options[OPTION_BASE] || raise('Option :base not setted')
|
40
|
-
end
|
41
|
-
|
42
|
-
def base?
|
43
|
-
options[OPTION_BASE] ? true : false
|
44
|
-
end
|
45
|
-
|
46
|
-
def include_modules
|
47
|
-
sub_files.each(&:include_module)
|
48
|
-
end
|
49
|
-
|
50
|
-
def include_or_prepend_method
|
51
|
-
return INCLUDE_MODULES_MAP.fetch(options[OPTION_INCLUDE_MODULES]) if
|
52
|
-
INCLUDE_MODULES_MAP.key?(options[OPTION_INCLUDE_MODULES])
|
53
|
-
|
54
|
-
raise ::ArgumentError, "Invalid value for 'options[OPTION_INCLUDE_MODULES]':" \
|
55
|
-
" \"#{options[OPTION_INCLUDE_MODULES]}\""
|
56
|
-
end
|
57
|
-
|
58
|
-
def require_sub_files
|
59
|
-
sub_files.each(&:require_file)
|
60
|
-
end
|
61
|
-
|
62
|
-
def sub_files
|
63
|
-
@sub_files ||= Dir["#{File.dirname(file)}/#{::File.basename(file, '.*')}/*.rb"].sort
|
64
|
-
.map { |path| SubFile.new(self, path) }
|
65
|
-
end
|
66
|
-
|
67
|
-
class SubFile
|
68
|
-
attr_reader :owner, :path
|
69
|
-
|
70
|
-
def initialize(owner, path)
|
71
|
-
@owner = owner
|
72
|
-
@path = path
|
73
|
-
end
|
74
|
-
|
75
|
-
def base_constant
|
76
|
-
return nil unless owner.base?
|
77
|
-
|
78
|
-
owner.base.const_get(constant_name)
|
79
|
-
rescue ::NameError
|
80
|
-
nil
|
81
|
-
end
|
82
|
-
|
83
|
-
def constant_name
|
84
|
-
::ActiveSupport::Inflector.camelize(::File.basename(path, '.rb'))
|
85
|
-
end
|
86
|
-
|
87
|
-
def include_module
|
88
|
-
return unless module?
|
89
|
-
|
90
|
-
owner.include_or_prepend_method.if_present do |v|
|
91
|
-
owner.base.send(v, base_constant)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def include_or_prepend_method
|
96
|
-
return :include if owner.options[OPTION_INCLUDE_MODULES]
|
97
|
-
return :prepend if owner.options[OPTION_PREPEND_MODULES]
|
98
|
-
|
99
|
-
nil
|
100
|
-
end
|
101
|
-
|
102
|
-
def module?
|
103
|
-
base_constant.is_a?(::Module) && !base_constant.is_a?(::Class)
|
104
|
-
end
|
105
|
-
|
106
|
-
def require_file
|
107
|
-
active_support_require || autoload_require || kernel_require
|
108
|
-
end
|
109
|
-
|
110
|
-
private
|
111
|
-
|
112
|
-
def active_support_require
|
113
|
-
return false unless owner.options[OPTION_REQUIRE_DEPENDENCY]
|
114
|
-
|
115
|
-
::Kernel.require_dependency(path)
|
116
|
-
true
|
117
|
-
end
|
118
|
-
|
119
|
-
def autoload_require
|
120
|
-
return false unless owner.base?
|
121
|
-
|
122
|
-
basename = ::File.basename(path, '.*')
|
123
|
-
return false if basename.start_with?('_')
|
124
|
-
|
125
|
-
owner.base.autoload ::ActiveSupport::Inflector.camelize(basename), path
|
126
|
-
true
|
127
|
-
end
|
128
|
-
|
129
|
-
def kernel_require
|
130
|
-
::Kernel.require(path)
|
131
|
-
end
|
8
|
+
::EacRubyUtils::RequireSub::Base.new(file, options).apply
|
132
9
|
end
|
133
10
|
end
|
134
11
|
end
|