admin_script 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45a05e2bb2442cfcb8f079507a2e57f34ac4d3d9
4
- data.tar.gz: 7053298a2a820ea581ec750924f2676b2e6445c5
3
+ metadata.gz: 869e5f1cf2ecbdada5116840bdabb72b6ce8aadc
4
+ data.tar.gz: 3ad84752ea0ec91af8dd95683081d4ab15434fae
5
5
  SHA512:
6
- metadata.gz: 42975dd1ee0b39c165cf68cb7412b717d7b72a88ce0b142179f6f4fc298662cd6e7be1c56fe99536e1f9578b33bb8c4a97b248c178de1e712668b40cbac2ad3e
7
- data.tar.gz: aca914a2f6fcec289192acf67dd8b6497018dcb5ca017af5185fb3b538b106cb2bf812bc3feecafb742241f1f8122b2350c68eaaaa78cd6715d6117627d7dee9
6
+ metadata.gz: 5fd0be08d51e57412302273c025afa201b23611e8dae995f6de804f17be0c0e388e8428b5146179ee091969e0b4bb2031a9f1e2e274ac12d900755025f63d54f
7
+ data.tar.gz: ff52b57576aedb19e3d08f8997abbd764497cbf0b98f48715d3208da1f0bdfc6b79f65145915009d348f82f27d93cc99b31ef9f86675c7c50f2ebb06a9f3e416
data/lib/admin_script.rb CHANGED
@@ -6,6 +6,7 @@ module AdminScript
6
6
  autoload :TypeAttributes, 'admin_script/type_attributes'
7
7
  autoload :Controller, 'admin_script/controller'
8
8
  autoload :Configuration, 'admin_script/configuration'
9
+ autoload :Reloader, 'admin_script/reloader'
9
10
 
10
11
  def self.configure
11
12
  yield(configuration)
@@ -22,9 +22,6 @@ module AdminScript
22
22
  @configurations = self.class.default_configurations.clone
23
23
  end
24
24
 
25
- define_configuration(:admin_script_paths, default: [
26
- (Rails.root.join('app', 'models', 'admin_script').to_s if defined?(Rails))
27
- ])
28
25
  define_configuration(:parent_controller, default: 'ActionController::Base')
29
26
  define_configuration(:default_url_options, default: {})
30
27
  define_configuration(:controller_path, default: 'admin_scripts')
@@ -9,13 +9,23 @@ module AdminScript
9
9
  AdminScript::Bootstrap.new.load!
10
10
 
11
11
  initializer 'admin_script.i18n' do |app|
12
- array = Array.wrap(app.config.i18n.available_locales)
13
- available_locales = array.blank? ? '*' : "{#{array.join ','}}"
12
+ app.config.i18n.load_path += gem_locale_files(app)
13
+ end
14
14
 
15
- locale_pattern = File.expand_path("../../../config/locales/admin_script/#{available_locales}.yml", __FILE__)
16
- locale_files = Dir[locale_pattern]
15
+ initializer 'admin_script.load_subclasses', before: :set_clear_dependencies_hook do |app|
16
+ path = app.paths['app/models'].first
17
17
 
18
- app.config.i18n.load_path += locale_files
18
+ reloader = AdminScript::Reloader.file_watcher.new([], { "#{path}/admin_script" => [:rb] }) do
19
+ Dir["#{path}/admin_script/**/*.rb"].each do |full_path|
20
+ load(full_path)
21
+ end
22
+ end
23
+
24
+ config.to_prepare do
25
+ reloader.execute_if_updated
26
+ end
27
+
28
+ app.reloaders << reloader
19
29
  end
20
30
 
21
31
  config.assets.paths += %w(stylesheets javascripts fonts).map do |path|
@@ -23,18 +33,18 @@ module AdminScript
23
33
  end
24
34
 
25
35
  config.after_initialize do
26
- AdminScript::Engine.routes.default_url_options = AdminScript.configuration.default_url_options.presence ||
27
- Rails.application.routes.default_url_options
36
+ AdminScript::Engine.routes.default_url_options =
37
+ AdminScript.configuration.default_url_options.presence || Rails.application.routes.default_url_options
28
38
  end
29
39
 
30
- config.to_prepare do
31
- AdminScript.configuration.admin_script_paths.each do |path|
32
- finder = Pathname.new(path).join('**', '*.rb')
40
+ private
33
41
 
34
- Dir[finder].each do |path|
35
- require_dependency(path)
36
- end
37
- end
42
+ def gem_locale_files(app)
43
+ array = Array.wrap(app.config.i18n.available_locales)
44
+ available_locales = array.blank? ? '*' : "{#{array.join ','}}"
45
+
46
+ locale_pattern = File.expand_path("../../../config/locales/admin_script/#{available_locales}.yml", __FILE__)
47
+ Dir[locale_pattern]
38
48
  end
39
49
  end
40
50
  end
@@ -0,0 +1,14 @@
1
+ module AdminScript
2
+ module Reloader
3
+ def self.file_watcher
4
+ case Rails.version[0]
5
+ when '4'
6
+ ActiveSupport::FileUpdateChecker
7
+ when '5'
8
+ Rails.application.config.file_watcher || ActiveSupport::FileUpdateChecker
9
+ else
10
+ raise 'Unsupported rails version!'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module AdminScript
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -2,9 +2,6 @@ AdminScript.configure do |config|
2
2
  # Configure the parent class responsible to render views.
3
3
  # config.parent_controller = 'ActionController::Base'
4
4
 
5
- # Configure the path to admin script classes.
6
- # config.admin_script_paths = [Rails.root.join('app', 'models', 'admin_script').to_s]
7
-
8
5
  # Custom controller. Default controller is AdminScript::AdminScriptsController
9
6
  # config.controller_path = 'admin_scripts'
10
7
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: admin_script
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - alpaca-tc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-07 00:00:00.000000000 Z
11
+ date: 2017-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -257,6 +257,7 @@ files:
257
257
  - lib/admin_script/bootstrap.rb
258
258
  - lib/admin_script/configuration.rb
259
259
  - lib/admin_script/engine.rb
260
+ - lib/admin_script/reloader.rb
260
261
  - lib/admin_script/type_attributes.rb
261
262
  - lib/admin_script/version.rb
262
263
  - lib/generators/admin_script/controller/controller_generator.rb