madmin 0.1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +50 -63
  4. data/Rakefile +5 -6
  5. data/app/assets/config/manifest.js +2 -0
  6. data/app/assets/stylesheets/actiontext.scss +36 -0
  7. data/app/assets/stylesheets/{madmin/application.css → application.css} +2 -9
  8. data/app/controllers/madmin/base_controller.rb +5 -9
  9. data/app/controllers/madmin/dashboard_controller.rb +1 -3
  10. data/app/controllers/madmin/resource_controller.rb +81 -0
  11. data/app/helpers/madmin/application_helper.rb +10 -8
  12. data/app/views/layouts/madmin/application.html.erb +23 -25
  13. data/app/views/madmin/application/_form.html.erb +25 -0
  14. data/app/views/madmin/application/_javascript.html.erb +24 -0
  15. data/app/views/madmin/application/_navigation.html.erb +6 -0
  16. data/app/views/madmin/application/edit.html.erb +3 -0
  17. data/app/views/madmin/application/index.html.erb +47 -0
  18. data/app/views/madmin/application/new.html.erb +3 -0
  19. data/app/views/madmin/application/show.html.erb +24 -0
  20. data/app/views/madmin/dashboard/show.html.erb +1 -0
  21. data/app/views/madmin/fields/attachment/_form.html.erb +2 -0
  22. data/app/views/madmin/fields/attachment/_index.html.erb +3 -0
  23. data/app/views/madmin/fields/attachment/_show.html.erb +3 -0
  24. data/app/views/madmin/fields/attachments/_form.html.erb +2 -0
  25. data/app/views/madmin/fields/attachments/_index.html.erb +1 -0
  26. data/app/views/madmin/fields/attachments/_show.html.erb +7 -0
  27. data/app/views/madmin/fields/belongs_to/_form.html.erb +2 -14
  28. data/app/views/madmin/fields/belongs_to/_index.html.erb +3 -7
  29. data/app/views/madmin/fields/belongs_to/_show.html.erb +3 -8
  30. data/app/views/madmin/fields/boolean/_form.html.erb +2 -0
  31. data/app/views/madmin/fields/boolean/_index.html.erb +1 -0
  32. data/app/views/madmin/fields/boolean/_show.html.erb +1 -0
  33. data/app/views/madmin/fields/date/_form.html.erb +2 -0
  34. data/app/views/madmin/fields/date/_index.html.erb +1 -0
  35. data/app/views/madmin/fields/date/_show.html.erb +1 -0
  36. data/app/views/madmin/fields/date_time/_form.html.erb +2 -0
  37. data/app/views/madmin/fields/date_time/_index.html.erb +1 -0
  38. data/app/views/madmin/fields/date_time/_show.html.erb +1 -0
  39. data/app/views/madmin/fields/decimal/_form.html.erb +2 -0
  40. data/app/views/madmin/fields/decimal/_index.html.erb +1 -0
  41. data/app/views/madmin/fields/decimal/_show.html.erb +1 -0
  42. data/app/views/madmin/fields/enum/_form.html.erb +2 -0
  43. data/app/views/madmin/fields/enum/_index.html.erb +1 -0
  44. data/app/views/madmin/fields/enum/_show.html.erb +1 -0
  45. data/app/views/madmin/fields/float/_form.html.erb +2 -0
  46. data/app/views/madmin/fields/float/_index.html.erb +1 -0
  47. data/app/views/madmin/fields/float/_show.html.erb +1 -0
  48. data/app/views/madmin/fields/has_many/_form.html.erb +2 -0
  49. data/app/views/madmin/fields/has_many/_index.html.erb +1 -0
  50. data/app/views/madmin/fields/has_many/_show.html.erb +4 -14
  51. data/app/views/madmin/fields/has_one/_form.html.erb +3 -0
  52. data/app/views/madmin/fields/has_one/_index.html.erb +3 -0
  53. data/app/views/madmin/fields/has_one/_show.html.erb +3 -12
  54. data/app/views/madmin/fields/integer/_form.html.erb +2 -0
  55. data/app/views/madmin/fields/integer/_index.html.erb +1 -0
  56. data/app/views/madmin/fields/integer/_show.html.erb +1 -0
  57. data/app/views/madmin/fields/json/_form.html.erb +2 -0
  58. data/app/views/madmin/fields/json/_index.html.erb +1 -0
  59. data/app/views/madmin/fields/json/_show.html.erb +1 -0
  60. data/app/views/madmin/fields/polymorphic/_form.html.erb +5 -32
  61. data/app/views/madmin/fields/polymorphic/_index.html.erb +3 -1
  62. data/app/views/madmin/fields/polymorphic/_show.html.erb +3 -14
  63. data/app/views/madmin/fields/rich_text/_form.html.erb +4 -0
  64. data/app/views/madmin/fields/rich_text/_index.html.erb +1 -0
  65. data/app/views/madmin/fields/rich_text/_show.html.erb +3 -0
  66. data/app/views/madmin/fields/string/_form.html.erb +2 -0
  67. data/app/views/madmin/fields/string/_index.html.erb +1 -0
  68. data/app/views/madmin/fields/string/_show.html.erb +1 -0
  69. data/app/views/madmin/fields/text/_form.html.erb +2 -4
  70. data/app/views/madmin/fields/text/_index.html.erb +1 -1
  71. data/app/views/madmin/fields/text/_show.html.erb +1 -8
  72. data/app/views/madmin/fields/time/_form.html.erb +2 -0
  73. data/app/views/madmin/fields/time/_index.html.erb +1 -0
  74. data/app/views/madmin/fields/time/_show.html.erb +1 -0
  75. data/lib/generators/madmin/install/install_generator.rb +31 -12
  76. data/lib/generators/madmin/install/templates/controller.rb.tt +22 -0
  77. data/lib/generators/madmin/resource/resource_generator.rb +83 -47
  78. data/lib/generators/madmin/resource/templates/controller.rb.tt +4 -0
  79. data/lib/generators/madmin/resource/templates/resource.rb.tt +11 -0
  80. data/lib/generators/madmin/views/edit_generator.rb +16 -0
  81. data/lib/generators/madmin/views/form_generator.rb +15 -0
  82. data/lib/generators/madmin/views/index_generator.rb +15 -0
  83. data/lib/generators/madmin/views/layout_generator.rb +21 -0
  84. data/lib/generators/madmin/views/navigation_generator.rb +15 -0
  85. data/lib/generators/madmin/views/new_generator.rb +16 -0
  86. data/lib/generators/madmin/views/show_generator.rb +15 -0
  87. data/lib/generators/madmin/views/views_generator.rb +8 -8
  88. data/lib/madmin.rb +34 -23
  89. data/lib/madmin/engine.rb +5 -2
  90. data/lib/madmin/field.rb +22 -46
  91. data/lib/madmin/fields/attachment.rb +6 -0
  92. data/lib/madmin/fields/attachments.rb +9 -0
  93. data/lib/madmin/fields/belongs_to.rb +18 -0
  94. data/lib/madmin/fields/boolean.rb +6 -0
  95. data/lib/madmin/fields/date.rb +6 -0
  96. data/lib/madmin/fields/date_time.rb +6 -0
  97. data/lib/madmin/fields/decimal.rb +6 -0
  98. data/lib/madmin/fields/enum.rb +9 -0
  99. data/lib/madmin/fields/float.rb +6 -0
  100. data/lib/madmin/fields/has_many.rb +18 -0
  101. data/lib/madmin/fields/has_one.rb +6 -0
  102. data/lib/madmin/fields/integer.rb +6 -0
  103. data/lib/madmin/fields/json.rb +6 -0
  104. data/lib/madmin/fields/polymorphic.rb +17 -0
  105. data/lib/madmin/fields/rich_text.rb +6 -0
  106. data/lib/madmin/fields/string.rb +6 -0
  107. data/lib/madmin/fields/text.rb +6 -0
  108. data/lib/madmin/fields/time.rb +6 -0
  109. data/lib/madmin/generator_helpers.rb +24 -0
  110. data/lib/madmin/namespace.rb +35 -0
  111. data/lib/madmin/resource.rb +176 -0
  112. data/lib/madmin/version.rb +1 -1
  113. data/lib/madmin/view_generator.rb +42 -0
  114. data/lib/tasks/madmin_tasks.rake +7 -0
  115. metadata +106 -111
  116. data/app/assets/config/madmin_manifest.js +0 -2
  117. data/app/assets/javascripts/madmin/application.js +0 -15
  118. data/app/assets/javascripts/madmin/dashboard.js +0 -2
  119. data/app/assets/javascripts/madmin/resources.js +0 -36
  120. data/app/assets/stylesheets/madmin/dashboard.css +0 -4
  121. data/app/assets/stylesheets/madmin/resources.css +0 -4
  122. data/app/controllers/madmin/application_controller.rb +0 -16
  123. data/app/controllers/madmin/resources_controller.rb +0 -97
  124. data/app/decorators/madmin/resource_decorator.rb +0 -16
  125. data/app/helpers/madmin/fields/polymorphic_helper.rb +0 -25
  126. data/app/jobs/madmin/application_job.rb +0 -4
  127. data/app/mailers/madmin/application_mailer.rb +0 -6
  128. data/app/models/madmin/application_record.rb +0 -5
  129. data/app/views/application/_navigation.html.erb +0 -17
  130. data/app/views/madmin/dashboard/index.html.erb +0 -6
  131. data/app/views/madmin/fields/check_box/_form.html.erb +0 -4
  132. data/app/views/madmin/fields/check_box/_index.html.erb +0 -1
  133. data/app/views/madmin/fields/check_box/_show.html.erb +0 -8
  134. data/app/views/madmin/fields/email/_form.html.erb +0 -4
  135. data/app/views/madmin/fields/email/_index.html.erb +0 -1
  136. data/app/views/madmin/fields/email/_show.html.erb +0 -8
  137. data/app/views/madmin/fields/number/_form.html.erb +0 -4
  138. data/app/views/madmin/fields/number/_index.html.erb +0 -1
  139. data/app/views/madmin/fields/number/_show.html.erb +0 -8
  140. data/app/views/madmin/fields/password/_form.html.erb +0 -4
  141. data/app/views/madmin/fields/password/_index.html.erb +0 -1
  142. data/app/views/madmin/fields/password/_show.html.erb +0 -8
  143. data/app/views/madmin/fields/select/_form.html.erb +0 -4
  144. data/app/views/madmin/fields/select/_index.html.erb +0 -1
  145. data/app/views/madmin/fields/select/_show.html.erb +0 -8
  146. data/app/views/madmin/fields/text_area/_form.html.erb +0 -4
  147. data/app/views/madmin/fields/text_area/_index.html.erb +0 -1
  148. data/app/views/madmin/fields/text_area/_show.html.erb +0 -8
  149. data/app/views/madmin/resources/_form.html.erb +0 -15
  150. data/app/views/madmin/resources/_scopes.html.erb +0 -10
  151. data/app/views/madmin/resources/edit.html.erb +0 -2
  152. data/app/views/madmin/resources/index.html.erb +0 -13
  153. data/app/views/madmin/resources/index/_content.html.erb +0 -33
  154. data/app/views/madmin/resources/new.html.erb +0 -2
  155. data/app/views/madmin/resources/show.html.erb +0 -10
  156. data/config/routes.rb +0 -11
  157. data/lib/generators/madmin/controller/USAGE +0 -8
  158. data/lib/generators/madmin/controller/controller_generator.rb +0 -10
  159. data/lib/generators/madmin/page/USAGE +0 -8
  160. data/lib/generators/madmin/page/page_generator.rb +0 -20
  161. data/lib/generators/madmin/page/templates/template.html.erb +0 -2
  162. data/lib/generators/madmin/page/templates/template.rb.erb +0 -10
  163. data/lib/generators/madmin/resource/templates/resource.rb.erb +0 -11
  164. data/lib/madmin/field/associatable.rb +0 -58
  165. data/lib/madmin/field/belongs_to.rb +0 -9
  166. data/lib/madmin/field/check_box.rb +0 -8
  167. data/lib/madmin/field/date_time.rb +0 -8
  168. data/lib/madmin/field/email.rb +0 -8
  169. data/lib/madmin/field/has_many.rb +0 -9
  170. data/lib/madmin/field/has_one.rb +0 -9
  171. data/lib/madmin/field/number.rb +0 -8
  172. data/lib/madmin/field/password.rb +0 -8
  173. data/lib/madmin/field/polymorphic.rb +0 -57
  174. data/lib/madmin/field/select.rb +0 -13
  175. data/lib/madmin/field/text.rb +0 -8
  176. data/lib/madmin/field/text_area.rb +0 -8
  177. data/lib/madmin/resourceable.rb +0 -72
  178. data/lib/madmin/resourceable/class_methods.rb +0 -152
  179. data/lib/madmin/resources.rb +0 -13
@@ -1,8 +0,0 @@
1
- Description:
2
- Explain the generator
3
-
4
- Example:
5
- rails generate custom_controller Thing
6
-
7
- This will create:
8
- what/will/it/create
@@ -1,20 +0,0 @@
1
- class Madmin::PageGenerator < Rails::Generators::NamedBase
2
- source_root File.expand_path("templates", __dir__)
3
-
4
- def copy_template
5
- template(
6
- "template.rb.erb",
7
- Rails.root.join("app/controllers/madmin/#{file_name}_controller.rb"),
8
- )
9
-
10
- template(
11
- "template.html.erb",
12
- Rails.root.join("app/views/madmin/#{file_name}/index.html.erb"),
13
- )
14
-
15
- inject_into_file(
16
- Rails.root.join("config/routes.rb"),
17
- after: "namespace :madmin do\n"
18
- ) { " get \"#{file_name}\", to: \"#{file_name}#index\"\n" }
19
- end
20
- end
@@ -1,2 +0,0 @@
1
- <h1><%= name %></h1>
2
- <p>Find me in apps/views/madmin/<%= file_name %>/index.erb</p>
@@ -1,10 +0,0 @@
1
- class Madmin::<%= name %>Controller < Madmin::ApplicationController
2
- def index
3
- end
4
-
5
- private
6
-
7
- def in_menu?
8
- true
9
- end
10
- end
@@ -1,11 +0,0 @@
1
- module Madmin
2
- class Resources
3
- class <%= class_name %>
4
- include Madmin::Resourceable
5
-
6
- <% (attributes + associations ).each do |name, type| -%>
7
- field :<%= name %>, Madmin::<%= type %>
8
- <% end -%>
9
- end
10
- end
11
- end
@@ -1,58 +0,0 @@
1
- module Madmin
2
- class Field
3
- module Associatable
4
- class << self
5
- def included(_base)
6
- attr_reader :association_class
7
- attr_reader :association_display_value
8
- attr_reader :association_foreign_key
9
- attr_reader :association_scope
10
- end
11
- end
12
-
13
- def initialize(args)
14
- super(args)
15
- implement_association!
16
- end
17
-
18
- def association_collection
19
- association_class.send(association_scope)
20
- end
21
-
22
- def association_id_for(resource)
23
- value_for(resource).id
24
- end
25
-
26
- def association_id_or_blank_for(resource)
27
- value_for(resource).try(:id)
28
- end
29
-
30
- def association_param
31
- ActiveModel::Naming.param_key(association_class)
32
- end
33
-
34
- def association_slug
35
- Object.const_get("::Madmin::Resources::#{association_class}").new.slug
36
- end
37
-
38
- def association_value_for(resource)
39
- value_for(resource).send(association_display_value)
40
- end
41
-
42
- def strong_params_keys
43
- [association_foreign_key]
44
- end
45
-
46
- private
47
-
48
- def implement_association!
49
- association = model.reflect_on_all_associations.find { |assc| assc.name == key }
50
-
51
- @association_class = association.klass
52
- @association_display_value = option_or_default(:display_value, :name)
53
- @association_foreign_key = association.foreign_key
54
- @association_scope = :all
55
- end
56
- end
57
- end
58
- end
@@ -1,9 +0,0 @@
1
- module Madmin
2
- class Field
3
- ##
4
- # This field represents a :belongs_to relationship within a Rails model.
5
- class BelongsTo < Madmin::Field
6
- include Madmin::Field::Associatable
7
- end
8
- end
9
- end
@@ -1,8 +0,0 @@
1
- module Madmin
2
- class Field
3
- ##
4
- # This field represents a checkbox (boolean) value.
5
- class CheckBox < Madmin::Field
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Madmin
2
- class Field
3
- ##
4
- # This field represents a datetime value.
5
- class DateTime < Madmin::Field
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Madmin
2
- class Field
3
- ##
4
- # This field represents an email value.
5
- class Email < Madmin::Field
6
- end
7
- end
8
- end
@@ -1,9 +0,0 @@
1
- module Madmin
2
- class Field
3
- ##
4
- # This field represents a :has_many relationship within a Rails model.
5
- class HasMany < Madmin::Field
6
- include Madmin::Field::Associatable
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module Madmin
2
- class Field
3
- ##
4
- # This field represents a :has_one relationship within a Rails model.
5
- class HasOne < Madmin::Field
6
- include Madmin::Field::Associatable
7
- end
8
- end
9
- end
@@ -1,8 +0,0 @@
1
- module Madmin
2
- class Field
3
- ##
4
- # This field represents a number value.
5
- class Number < Madmin::Field
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Madmin
2
- class Field
3
- ##
4
- # This field represents a password value.
5
- class Password < Madmin::Field
6
- end
7
- end
8
- end
@@ -1,57 +0,0 @@
1
- module Madmin
2
- class Field
3
- ##
4
- # This field represents a polymorphic relationship.
5
- class Polymorphic < Madmin::Field
6
- attr_reader :polymorphic_display_value
7
- attr_reader :polymorphic_scope
8
-
9
- def initialize(args)
10
- super(args)
11
- @polymorphic_display_value = option_or_default(:display_value, :name)
12
- @polymorphic_scope = :all
13
- end
14
-
15
- ##
16
- # Returns the id for the associated polymorphic record.
17
- def polymorphic_id_for(resource)
18
- value_for(resource).id
19
- end
20
-
21
- ##
22
- # Returns the polymorphic ID param.
23
- def polymorphic_id_param
24
- "#{key}_id".to_sym
25
- end
26
-
27
- def polymorphic_relationship_exists?(resource)
28
- resource.send(polymorphic_type_param) && resource.send(polymorphic_id_param)
29
- end
30
-
31
- ##
32
- # Returns the slug for the polymorphic resource.
33
- def polymorphic_slug_for(resource)
34
- Object.const_get("::Madmin::Resources::#{resource.send("#{key}_type")}").new.slug
35
- end
36
-
37
- ##
38
- # Returns the polymorphic type param.
39
- def polymorphic_type_param
40
- "#{key}_type".to_sym
41
- end
42
-
43
- ##
44
- # Returns the value to show in the admin
45
- # for the polymorphic relationship.
46
- def polymorphic_value_for(resource)
47
- value_for(resource).send(polymorphic_display_value)
48
- end
49
-
50
- ##
51
- # Returns the polymorphic stront params keys.
52
- def strong_params_keys
53
- [polymorphic_id_param, polymorphic_type_param]
54
- end
55
- end
56
- end
57
- end
@@ -1,13 +0,0 @@
1
- module Madmin
2
- class Field
3
- ##
4
- # This field represents a select dropdown value.
5
- class Select < Madmin::Field
6
- attr_reader :select_options
7
-
8
- def initialize(args)
9
- @select_options = option_or_default(:collection, [])
10
- end
11
- end
12
- end
13
- end
@@ -1,8 +0,0 @@
1
- module Madmin
2
- class Field
3
- ##
4
- # This field represents a plain old text field.
5
- class Text < Madmin::Field
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Madmin
2
- class Field
3
- ##
4
- # This field represents a textarea value.
5
- class TextArea < Madmin::Field
6
- end
7
- end
8
- end
@@ -1,72 +0,0 @@
1
- require "madmin/resourceable/class_methods"
2
-
3
- ##
4
- # This module is the heart of a Madmin Resource.
5
- # When included into a resource class, the
6
- # resource is given a DSL for registering
7
- # fields, scopes, and more.
8
- module Madmin
9
- module Resourceable
10
- class << self
11
- def included(base)
12
- base.extend Madmin::Resourceable::ClassMethods
13
- end
14
- end
15
-
16
- ##
17
- # This method returns a list of fields where
18
- # the index option is truthy.
19
- def form_fields
20
- self.class.fields.values.select { |field| field.form }
21
- end
22
-
23
- ##
24
- # This methods exposes the underlying resource's name
25
- # in a way humans can enjoy and understand.
26
- def friendly_name
27
- self.class.model_name.split("::").join(" ")
28
- end
29
-
30
- ##
31
- # This method returns a list of fields where
32
- # the index option is truthy.
33
- def index_fields
34
- self.class.fields.values.select { |field| field.index }
35
- end
36
-
37
- ##
38
- # This method returns a list of labels for fields
39
- # where the index option is truthy.
40
- def index_headers
41
- index_fields.map { |field| field.label }
42
- end
43
-
44
- ##
45
- # This method affords us the ability to retrieve
46
- # a list of the scopes from the class variable.
47
- def scopes
48
- self.class.scopes
49
- end
50
-
51
- ##
52
- # This method exposes a way to control if the
53
- # resource should visible in the menu.
54
- def show_in_menu?
55
- true
56
- end
57
-
58
- ##
59
- # This method, when used in the resource, sets all fields
60
- # to be used when the show partial is rendered.
61
- def show_fields
62
- self.class.fields.values.select { |field| field.show }
63
- end
64
-
65
- ##
66
- # This method affords us the ability to have a
67
- # consistently rendered slug for a resource.
68
- def slug
69
- ActiveModel::Naming.route_key(self.class.model)
70
- end
71
- end
72
- end
@@ -1,152 +0,0 @@
1
- module Madmin
2
- module Resourceable
3
- ##
4
- # This module extends methods into class methods on the resource.
5
- module ClassMethods
6
- ##
7
- # This method is a wrapper for the class variable fields.
8
- # In the event there is no field defined yet, we rescue
9
- # NameError and return an empty hash to begin the
10
- # population of the fields class variable.
11
- def fields
12
- class_variable_get(:@@fields)
13
- rescue NameError
14
- {}
15
- end
16
-
17
- ##
18
- # This becomes a DSL for adding a field into the fields class variable.
19
- # It is responsible for validating and parsing the arguments before
20
- # placing them into the fields class variable.
21
- def field(*args)
22
- validate_arguments!(args)
23
-
24
- key = args[0].to_sym
25
- field_type = args[1]
26
-
27
- # We reassign the entire list of fields to prevent
28
- # duplication each time the class is evaluated.
29
- fresh_fields = fields
30
- fresh_fields[key] = field_type.new(args[2].merge(key: key, model: model, resource: self))
31
-
32
- class_variable_set(:@@fields, fresh_fields)
33
- end
34
-
35
- ##
36
- # This method is a wrapper for the class variable scopes.
37
- # In the event there is no scope defined yet, we rescue
38
- # NameError and return an empty array to begin the
39
- # population of the scopes class variable.
40
- def scopes
41
- class_variable_get(:@@scopes)
42
- rescue NameError
43
- []
44
- end
45
-
46
- ##
47
- # This becomes a DSL for adding a field into the scopes class variable.
48
- # It is responsible for validating and parsing the arguments before
49
- # placing them into the scopes class variable.
50
- def scope(*args)
51
- validate_scopes!(args)
52
-
53
- # We reassign the entire list of scopes to prevent
54
- # duplication each time the class is evaluated.
55
- fresh_scopes = scopes << args
56
-
57
- class_variable_set(:@@scopes, fresh_scopes.flatten.uniq)
58
- end
59
-
60
- ##
61
- # This method, when used in the resource, sets all fields
62
- # to be used when the form partial is rendered.
63
- def form_all_fields!
64
- class_variable_set(:@@form_all_fields, true)
65
- end
66
-
67
- ##
68
- # This method exposes a convenient way to see if all fields
69
- # for a resource should be available in a form partial.
70
- def form_all_fields?
71
- class_variable_get(:@@form_all_fields)
72
- rescue NameError
73
- false
74
- end
75
-
76
- ##
77
- # This method exposes the underlying model.
78
- def model
79
- model_name.constantize
80
- end
81
-
82
- ##
83
- # This method extracts the namespace to reveal
84
- # the underlying models name as a string.
85
- def model_name
86
- to_s.split("Madmin::Resources::").last.to_s
87
- end
88
-
89
- ##
90
- # This method exposes a convenient way to see if all fields
91
- # for a resource should be available in a show partial.
92
- def show_all_fields!
93
- class_variable_set(:@@show_all_fields, true)
94
- end
95
-
96
- ##
97
- # This method exposes a convenient way to see if all fields
98
- # for a resource should be available in a show partial.
99
- def show_all_fields?
100
- class_variable_get(:@@show_all_fields)
101
- rescue NameError
102
- false
103
- end
104
-
105
- private
106
-
107
- ##
108
- # This method validates that a given attribute for
109
- # a field is provided in the correct format of
110
- # either a symbol or a string.
111
- def attribute?(attribute)
112
- attribute.is_a?(Symbol) || attribute.is_a?(String)
113
- end
114
-
115
- ##
116
- # We want to make sure a provided type is
117
- # registered within our system.
118
- def valid_type?(type)
119
- type.to_s.deconstantize == Madmin::Field.to_s
120
- end
121
-
122
- ##
123
- # This method looks at the first two arguments (attribute, type)
124
- # and performs their prospective validations. If either
125
- # validation fails, a WrongArgumentError is raised.
126
- def validate_arguments!(args)
127
- if !attribute?(args.first)
128
- raise WrongArgumentError,
129
- "#{model_name} expected the attribute name as a symbol or string as the first argument."
130
- elsif !valid_type?(args.second)
131
- raise WrongArgumentError,
132
- "#{model_name} expected Madmin::Field type as the field type as the second argument."
133
- end
134
- end
135
-
136
- ##
137
- # This method looks at a given scope(s) and validates
138
- # the scope exists on the underlying model.
139
- #
140
- # Rails scopes are defined as class methods as the
141
- # class is evaluated, requiring this method
142
- # of performing the validation.
143
- def validate_scopes!(args)
144
- args.each do |arg|
145
- unless model.respond_to?(arg)
146
- raise UndefinedScopeError, ".#{arg} is not a valid scope on #{name}"
147
- end
148
- end
149
- end
150
- end
151
- end
152
- end