administrate-base_controller 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eca080c0f857f4c489166accd82cefb2f493ab27aab1fbdd29bee92832304ecf
4
- data.tar.gz: f0592dea0fd246d7dd1c7566d63d992204f53874da4d364b3db62a1f6f9f4697
3
+ metadata.gz: 21f4165f46349b93a8dc74edf92e906db55833b900d32ec1a7e19e33e14dcc50
4
+ data.tar.gz: 36f6d49ffb71ae71268324341600f106db12f1cffc51a845105ca892742cf109
5
5
  SHA512:
6
- metadata.gz: 3834f08d5635719eca35adf9fbbfde49ac638f137d00700efb6f1d1cbe60ec3fec0e6ab397241183cf63ada77030b4ed5beb14002708ede4d4853564ef96949b
7
- data.tar.gz: '0299aca439ef265fb034c4afe637ffbff8b124c8c0158318465651e8696ebf7c4007a4f93b66d5447bb5e296c1696817cbe408b761b70b92e227ccd1a61c1a7f'
6
+ metadata.gz: f1dd8d6a755aeef649810168e200a1f44eddb407441044f58e8e57b9c55079df50ca7b5de45292dbf2c7303b2a5b521a8098cb1c3901aa6e1de2d24b0a70ff77
7
+ data.tar.gz: 2f9c350f7122e5a54a2f5e065ae9ddaa7d2c8f4dd45194c88a134547185d070c71c2c8e49e498f2697a0a9332b0cf5605e62f868cc800ef245db6639fd8c771d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0
4
+
5
+ Load on after_initialize hook
6
+
3
7
  ## 0.1.0
4
8
 
5
9
  :baby: Initial version
data/Gemfile.lock CHANGED
@@ -1,8 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- administrate-base_controller (0.1.0)
5
- activesupport
4
+ administrate-base_controller (0.2.0)
6
5
 
7
6
  GEM
8
7
  remote: https://rubygems.org/
@@ -34,10 +34,9 @@ Gem::Specification.new do |spec|
34
34
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
35
  spec.require_paths = ['lib']
36
36
 
37
- spec.add_dependency 'activesupport'
38
37
  spec.add_development_dependency 'administrate', '>= 0.11.0', '< 1'
39
38
  spec.add_development_dependency 'bundler', '~> 2.0'
39
+ spec.add_development_dependency 'minitest', '~> 5.0'
40
40
  spec.add_development_dependency 'rake', '~> 10.0'
41
41
  spec.add_development_dependency 'rails'
42
- spec.add_development_dependency 'minitest', '~> 5.0'
43
42
  end
@@ -1,96 +1,96 @@
1
- require 'active_support/concern'
2
- require 'active_support/lazy_load_hooks'
3
1
  require 'administrate/base_controller/version'
2
+ require 'administrate/engine'
4
3
 
5
4
  module Administrate
5
+ class Engine < Rails::Engine
6
+ config.after_initialize do
7
+ ::Administrate::ApplicationController.class_eval do
8
+ def index
9
+ resources = index_resources
10
+ resources = apply_resource_includes(resources)
11
+ resources = order.apply(resources)
12
+ resources = resources.page(params[:page]).per(records_per_page)
13
+ page = index_page
14
+
15
+ render locals: {
16
+ resources: resources,
17
+ search_term: search_term,
18
+ page: page,
19
+ show_search_bar: show_search_bar?,
20
+ }
21
+ end
6
22
 
7
- ActiveSupport.on_load(:action_controller) do
8
- ApplicationController.class_eval do
9
- def index
10
- resources = index_resources
11
- resources = apply_resource_includes(resources)
12
- resources = order.apply(resources)
13
- resources = resources.page(params[:page]).per(records_per_page)
14
- page = index_page
15
-
16
- render locals: {
17
- resources: resources,
18
- search_term: search_term,
19
- page: page,
20
- show_search_bar: show_search_bar?,
21
- }
22
- end
23
-
24
- def new
25
- resource = new_resource
26
- authorize_resource(resource)
27
- render locals: { page: new_page(resource) }
28
- end
23
+ def new
24
+ resource = new_resource
25
+ authorize_resource(resource)
26
+ render locals: { page: new_page(resource) }
27
+ end
29
28
 
30
- def edit
31
- render locals: { page: edit_page(requested_resource) }
32
- end
29
+ def edit
30
+ render locals: { page: edit_page(requested_resource) }
31
+ end
33
32
 
34
- def show
35
- render locals: { page: show_page }
36
- end
33
+ def show
34
+ render locals: { page: show_page }
35
+ end
37
36
 
38
- protected
37
+ protected
39
38
 
40
- def search_term
41
- @search_term ||= params[:search].to_s.strip
42
- end
39
+ def search_term
40
+ @search_term ||= params[:search].to_s.strip
41
+ end
43
42
 
44
- def index_scoped_resource
45
- scoped_resource
46
- end
43
+ def index_scoped_resource
44
+ scoped_resource
45
+ end
47
46
 
48
- def index_resources
49
- Administrate::Search.new(index_scoped_resource, dashboard_class, search_term).run
50
- end
47
+ def index_resources
48
+ Administrate::Search.new(index_scoped_resource, dashboard_class, search_term).run
49
+ end
51
50
 
52
- def index_page
53
- Administrate::Page::Collection.new(dashboard, order: order)
54
- end
51
+ def index_page
52
+ Administrate::Page::Collection.new(dashboard, order: order)
53
+ end
55
54
 
56
- def show_page
57
- Administrate::Page::Show.new(dashboard, requested_resource)
58
- end
55
+ def show_page
56
+ Administrate::Page::Show.new(dashboard, requested_resource)
57
+ end
59
58
 
60
- def new_page(resource)
61
- Administrate::Page::Form.new(dashboard, resource)
62
- end
59
+ def new_page(resource)
60
+ Administrate::Page::Form.new(dashboard, resource)
61
+ end
63
62
 
64
- def edit_page(resource)
65
- new_page(resource)
66
- end
63
+ def edit_page(resource)
64
+ new_page(resource)
65
+ end
67
66
 
68
- def authorize_resource(resource)
69
- return if show_action?(action_name.to_sym, resource)
70
- raise "That's not a valid action."
71
- end
67
+ def authorize_resource(resource)
68
+ return if show_action?(action_name.to_sym, resource)
69
+ raise "That's not a valid action."
70
+ end
72
71
 
73
- def resource_params
74
- permitted = params.require(resource_class.model_name.param_key)
75
- .permit(dashboard.permitted_attributes)
76
- .to_h
72
+ def resource_params
73
+ permitted = params.require(resource_class.model_name.param_key)
74
+ .permit(dashboard.permitted_attributes)
75
+ .to_h
77
76
 
78
- permitted.each_with_object(permitted) do |(k, v), result|
79
- result[k] = read_param(k, v)
77
+ permitted.each_with_object(permitted) do |(k, v), result|
78
+ result[k] = read_param(k, v)
79
+ end
80
80
  end
81
- end
82
81
 
83
- def read_param(_, data)
84
- if data.is_a?(ActionController::Parameters) && data[:type]
85
- return read_param_value(data)
86
- end
82
+ def read_param(_, data)
83
+ if data.is_a?(ActionController::Parameters) && data[:type]
84
+ return read_param_value(data)
85
+ end
87
86
 
88
- data
89
- end
87
+ data
88
+ end
90
89
 
91
- private
90
+ private
92
91
 
93
- attr_writer :search_term
92
+ attr_writer :search_term
93
+ end
94
94
  end
95
95
  end
96
96
  end
@@ -1,5 +1,5 @@
1
1
  module Administrate
2
2
  module BaseController
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate-base_controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derk-Jan Karrenbeld
@@ -10,20 +10,6 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2019-03-15 00:00:00.000000000 Z
12
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: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: administrate
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -59,47 +45,47 @@ dependencies:
59
45
  - !ruby/object:Gem::Version
60
46
  version: '2.0'
61
47
  - !ruby/object:Gem::Dependency
62
- name: rake
48
+ name: minitest
63
49
  requirement: !ruby/object:Gem::Requirement
64
50
  requirements:
65
51
  - - "~>"
66
52
  - !ruby/object:Gem::Version
67
- version: '10.0'
53
+ version: '5.0'
68
54
  type: :development
69
55
  prerelease: false
70
56
  version_requirements: !ruby/object:Gem::Requirement
71
57
  requirements:
72
58
  - - "~>"
73
59
  - !ruby/object:Gem::Version
74
- version: '10.0'
60
+ version: '5.0'
75
61
  - !ruby/object:Gem::Dependency
76
- name: rails
62
+ name: rake
77
63
  requirement: !ruby/object:Gem::Requirement
78
64
  requirements:
79
- - - ">="
65
+ - - "~>"
80
66
  - !ruby/object:Gem::Version
81
- version: '0'
67
+ version: '10.0'
82
68
  type: :development
83
69
  prerelease: false
84
70
  version_requirements: !ruby/object:Gem::Requirement
85
71
  requirements:
86
- - - ">="
72
+ - - "~>"
87
73
  - !ruby/object:Gem::Version
88
- version: '0'
74
+ version: '10.0'
89
75
  - !ruby/object:Gem::Dependency
90
- name: minitest
76
+ name: rails
91
77
  requirement: !ruby/object:Gem::Requirement
92
78
  requirements:
93
- - - "~>"
79
+ - - ">="
94
80
  - !ruby/object:Gem::Version
95
- version: '5.0'
81
+ version: '0'
96
82
  type: :development
97
83
  prerelease: false
98
84
  version_requirements: !ruby/object:Gem::Requirement
99
85
  requirements:
100
- - - "~>"
86
+ - - ">="
101
87
  - !ruby/object:Gem::Version
102
- version: '5.0'
88
+ version: '0'
103
89
  description:
104
90
  email:
105
91
  - derk-jan@xpbytes.com