kadmin 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +44 -44
  3. data/Rakefile +146 -146
  4. data/app/assets/javascripts/modular/app.js +1388 -1388
  5. data/app/assets/javascripts/modular/application.js +3 -3
  6. data/app/assets/javascripts/modular/vendor.js +57671 -57671
  7. data/app/assets/stylesheets/kadmin/typeahead-select.scss +2 -0
  8. data/app/assets/stylesheets/modular/app-blue.css +2795 -2795
  9. data/app/assets/stylesheets/modular/app-custom.css +2795 -2795
  10. data/app/assets/stylesheets/modular/app-green.css +2795 -2795
  11. data/app/assets/stylesheets/modular/app-orange.css +2795 -2795
  12. data/app/assets/stylesheets/modular/app-purple.css +2795 -2795
  13. data/app/assets/stylesheets/modular/app-red.css +2795 -2795
  14. data/app/assets/stylesheets/modular/app-seagreen.css +2795 -2795
  15. data/app/assets/stylesheets/modular/app.css +2795 -2795
  16. data/app/assets/stylesheets/modular/custom.css +51 -19
  17. data/app/assets/stylesheets/modular/vendor.css +12999 -12999
  18. data/app/controllers/kadmin/application_controller.rb +64 -64
  19. data/app/controllers/kadmin/auth_controller.rb +98 -98
  20. data/app/controllers/kadmin/concerns/authorized_user.rb +67 -67
  21. data/app/controllers/kadmin/dash_controller.rb +19 -19
  22. data/app/decorators/kadmin/finder_decorator.rb +50 -50
  23. data/app/decorators/kadmin/pager_decorator.rb +33 -33
  24. data/app/helpers/kadmin/alert_helper.rb +59 -59
  25. data/app/helpers/kadmin/application_helper.rb +4 -4
  26. data/app/helpers/kadmin/bootstrap_helper.rb +23 -23
  27. data/app/helpers/kadmin/form_builder.rb +9 -9
  28. data/app/helpers/kadmin/forms/inverted_check_box.rb +10 -10
  29. data/app/helpers/kadmin/navigation_helper.rb +28 -28
  30. data/app/helpers/kadmin/pagination_helper.rb +95 -95
  31. data/app/views/kadmin/auth/login.html.erb +4 -4
  32. data/app/views/kadmin/components/_finder.html.erb +14 -18
  33. data/app/views/kadmin/components/finder/_empty.html.erb +3 -3
  34. data/app/views/kadmin/components/finder/_form.erb +10 -10
  35. data/app/views/kadmin/components/finder/_header.html.erb +14 -11
  36. data/app/views/kadmin/dash/index.html.erb +5 -5
  37. data/app/views/kadmin/error.html.erb +5 -5
  38. data/app/views/kadmin/helpers/_alerts.html.erb +4 -4
  39. data/app/views/kadmin/helpers/_form_errors.html.erb +10 -10
  40. data/app/views/layouts/modular/application.html.erb +134 -132
  41. data/config/initializers/action_view.rb +2 -2
  42. data/config/initializers/assets.rb +5 -5
  43. data/config/locales/de.yml +25 -25
  44. data/config/locales/en.yml +24 -24
  45. data/config/routes.rb +12 -12
  46. data/lib/kadmin.rb +22 -22
  47. data/lib/kadmin/auth.rb +31 -31
  48. data/lib/kadmin/auth/configuration.rb +66 -66
  49. data/lib/kadmin/auth/unauthorized_error.rb +14 -14
  50. data/lib/kadmin/auth/user.rb +15 -15
  51. data/lib/kadmin/auth/user_store.rb +21 -21
  52. data/lib/kadmin/configuration.rb +18 -18
  53. data/lib/kadmin/engine.rb +15 -15
  54. data/lib/kadmin/error.rb +7 -7
  55. data/lib/kadmin/errors/authorization.rb +15 -15
  56. data/lib/kadmin/finder.rb +66 -66
  57. data/lib/kadmin/form.rb +179 -179
  58. data/lib/kadmin/pager.rb +93 -93
  59. data/lib/kadmin/version.rb +3 -3
  60. data/test/dummy/README.rdoc +28 -28
  61. data/test/dummy/Rakefile +6 -6
  62. data/test/dummy/app/assets/javascripts/application.js +13 -13
  63. data/test/dummy/app/assets/stylesheets/application.css +15 -15
  64. data/test/dummy/app/controllers/admin/application_controller.rb +11 -11
  65. data/test/dummy/app/controllers/admin/people_controller.rb +89 -89
  66. data/test/dummy/app/controllers/admin_controller.rb +4 -4
  67. data/test/dummy/app/controllers/application_controller.rb +5 -5
  68. data/test/dummy/app/controllers/authorized_controller.rb +8 -8
  69. data/test/dummy/app/helpers/application_helper.rb +2 -2
  70. data/test/dummy/app/models/group.rb +8 -8
  71. data/test/dummy/app/models/group_person.rb +6 -6
  72. data/test/dummy/app/models/person.rb +20 -20
  73. data/test/dummy/app/views/admin/index.html.erb +1 -1
  74. data/test/dummy/app/views/admin/people/_form.html.erb +34 -34
  75. data/test/dummy/app/views/admin/people/_table.html.erb +33 -33
  76. data/test/dummy/app/views/admin/people/edit.html.erb +4 -4
  77. data/test/dummy/app/views/admin/people/index.html.erb +3 -3
  78. data/test/dummy/app/views/admin/people/new.html.erb +5 -5
  79. data/test/dummy/app/views/admin/people/show.html.erb +3 -3
  80. data/test/dummy/app/views/authorized/index.html.erb +1 -1
  81. data/test/dummy/app/views/layouts/application.html.erb +14 -14
  82. data/test/dummy/bin/bundle +3 -3
  83. data/test/dummy/bin/rails +4 -4
  84. data/test/dummy/bin/rake +4 -4
  85. data/test/dummy/bin/setup +29 -29
  86. data/test/dummy/config.ru +4 -4
  87. data/test/dummy/config/application.rb +39 -39
  88. data/test/dummy/config/boot.rb +5 -5
  89. data/test/dummy/config/database.yml +22 -22
  90. data/test/dummy/config/environment.rb +5 -5
  91. data/test/dummy/config/environments/development.rb +41 -41
  92. data/test/dummy/config/environments/production.rb +79 -79
  93. data/test/dummy/config/environments/test.rb +42 -42
  94. data/test/dummy/config/initializers/assets.rb +10 -10
  95. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -7
  96. data/test/dummy/config/initializers/cookies_serializer.rb +3 -3
  97. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -4
  98. data/test/dummy/config/initializers/inflections.rb +16 -16
  99. data/test/dummy/config/initializers/kadmin.rb +24 -24
  100. data/test/dummy/config/initializers/mime_types.rb +4 -4
  101. data/test/dummy/config/initializers/session_store.rb +3 -3
  102. data/test/dummy/config/initializers/wrap_parameters.rb +14 -14
  103. data/test/dummy/config/locales/en.yml +17 -17
  104. data/test/dummy/config/routes.rb +13 -13
  105. data/test/dummy/config/secrets.yml +22 -22
  106. data/test/dummy/db/migrate/20161006114509_create_people.rb +11 -11
  107. data/test/dummy/db/migrate/20161006134459_create_groups.rb +11 -11
  108. data/test/dummy/db/migrate/20161006134746_create_group_people.rb +11 -11
  109. data/test/dummy/db/schema.rb +43 -43
  110. data/test/dummy/lib/forms/group_form.rb +16 -16
  111. data/test/dummy/lib/forms/person_form.rb +19 -19
  112. data/test/dummy/public/404.html +67 -67
  113. data/test/dummy/public/422.html +67 -67
  114. data/test/dummy/public/500.html +66 -66
  115. data/test/dummy/test/fixtures/children.yml +11 -11
  116. data/test/dummy/test/fixtures/group_people.yml +11 -11
  117. data/test/dummy/test/fixtures/groups.yml +11 -11
  118. data/test/dummy/test/fixtures/people.yml +11 -11
  119. data/test/dummy/test/models/group_person_test.rb +7 -7
  120. data/test/dummy/test/models/group_test.rb +7 -7
  121. data/test/kadmin/form_test.rb +6 -6
  122. data/test/test_helper.rb +32 -32
  123. metadata +54 -53
@@ -1,16 +1,16 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Add new inflection rules using the following format. Inflections
4
- # are locale specific, and you may define rules for as many different
5
- # locales as you wish. All of these examples are active by default:
6
- # ActiveSupport::Inflector.inflections(:en) do |inflect|
7
- # inflect.plural /^(ox)$/i, '\1en'
8
- # inflect.singular /^(ox)en/i, '\1'
9
- # inflect.irregular 'person', 'people'
10
- # inflect.uncountable %w( fish sheep )
11
- # end
12
-
13
- # These inflection rules are supported but not enabled by default:
14
- # ActiveSupport::Inflector.inflections(:en) do |inflect|
15
- # inflect.acronym 'RESTful'
16
- # end
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format. Inflections
4
+ # are locale specific, and you may define rules for as many different
5
+ # locales as you wish. All of these examples are active by default:
6
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
7
+ # inflect.plural /^(ox)$/i, '\1en'
8
+ # inflect.singular /^(ox)en/i, '\1'
9
+ # inflect.irregular 'person', 'people'
10
+ # inflect.uncountable %w( fish sheep )
11
+ # end
12
+
13
+ # These inflection rules are supported but not enabled by default:
14
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
15
+ # inflect.acronym 'RESTful'
16
+ # end
@@ -1,24 +1,24 @@
1
- module Dummy
2
- class User < Kadmin::Auth::User
3
- def authorized?(_request)
4
- return true
5
- end
6
- end
7
-
8
- class UserStore < Kadmin::Auth::UserStore
9
- def get(email)
10
- set(email, Dummy::User.new(email)) unless exists?(email)
11
- return @store[email.downcase]
12
- end
13
- end
14
- end
15
-
16
- Kadmin.config.logger = Rails.logger
17
- Kadmin.config.mount_path = '/admin'
18
-
19
- Kadmin::Auth.config.user_class = Dummy::User
20
- Kadmin::Auth.config.user_store_class = Dummy::UserStore
21
-
22
- Kadmin::Auth.config.enable!
23
-
24
- Kadmin.config.navbar_links << { title: 'Test', path: '/admin/test' }
1
+ module Dummy
2
+ class User < Kadmin::Auth::User
3
+ def authorized?(_request)
4
+ return true
5
+ end
6
+ end
7
+
8
+ class UserStore < Kadmin::Auth::UserStore
9
+ def get(email)
10
+ set(email, Dummy::User.new(email)) unless exists?(email)
11
+ return @store[email.downcase]
12
+ end
13
+ end
14
+ end
15
+
16
+ Kadmin.config.logger = Rails.logger
17
+ Kadmin.config.mount_path = '/admin'
18
+
19
+ Kadmin::Auth.config.user_class = Dummy::User
20
+ Kadmin::Auth.config.user_store_class = Dummy::UserStore
21
+
22
+ Kadmin::Auth.config.enable!
23
+
24
+ Kadmin.config.navbar_links << { title: 'Test', path: '/admin/test' }
@@ -1,4 +1,4 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Add new mime types for use in respond_to blocks:
4
- # Mime::Type.register "text/richtext", :rtf
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
@@ -1,3 +1,3 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- Rails.application.config.session_store :cookie_store, key: '_dummy_session'
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Rails.application.config.session_store :cookie_store, key: '_dummy_session'
@@ -1,14 +1,14 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # This file contains settings for ActionController::ParamsWrapper which
4
- # is enabled by default.
5
-
6
- # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
- ActiveSupport.on_load(:action_controller) do
8
- wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9
- end
10
-
11
- # To enable root element in JSON for ActiveRecord objects.
12
- # ActiveSupport.on_load(:active_record) do
13
- # self.include_root_in_json = true
14
- # end
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9
+ end
10
+
11
+ # To enable root element in JSON for ActiveRecord objects.
12
+ # ActiveSupport.on_load(:active_record) do
13
+ # self.include_root_in_json = true
14
+ # end
@@ -1,17 +1,17 @@
1
- en:
2
- activerecord:
3
- attributes:
4
- person:
5
- date_of_birth: "Date of birth"
6
- first_name: "First name"
7
- last_name: "Last name"
8
- gender: Gender
9
- models:
10
- person:
11
- one: Person
12
- other: People
13
- person:
14
- genders:
15
- m: Male
16
- f: Female
17
- o: Other
1
+ en:
2
+ activerecord:
3
+ attributes:
4
+ person:
5
+ date_of_birth: "Date of birth"
6
+ first_name: "First name"
7
+ last_name: "Last name"
8
+ gender: Gender
9
+ models:
10
+ person:
11
+ one: Person
12
+ other: People
13
+ person:
14
+ genders:
15
+ m: Male
16
+ f: Female
17
+ o: Other
@@ -1,13 +1,13 @@
1
- Rails.application.routes.draw do
2
- get '/', to: -> (_env) do # rubocop: disable Style/Lambda
3
- [200, { 'Content-Type' => 'text/plain' }, ['Howdy']]
4
- end
5
-
6
- namespace :admin do
7
- resources :people
8
- resources :groups
9
- end
10
- mount Kadmin::Engine => Kadmin.config.mount_path, as: :kadmin
11
-
12
- get '/authorized', controller: :authorized, action: :index
13
- end
1
+ Rails.application.routes.draw do
2
+ get '/', to: -> (_env) do # rubocop: disable Style/Lambda
3
+ [200, { 'Content-Type' => 'text/plain' }, ['Howdy']]
4
+ end
5
+
6
+ namespace :admin do
7
+ resources :people
8
+ resources :groups
9
+ end
10
+ mount Kadmin::Engine => Kadmin.config.mount_path, as: :kadmin
11
+
12
+ get '/authorized', controller: :authorized, action: :index
13
+ end
@@ -1,22 +1,22 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Your secret key is used for verifying the integrity of signed cookies.
4
- # If you change this key, all old signed cookies will become invalid!
5
-
6
- # Make sure the secret is at least 30 characters and all random,
7
- # no regular words or you'll be exposed to dictionary attacks.
8
- # You can use `rake secret` to generate a secure secret key.
9
-
10
- # Make sure the secrets in this file are kept private
11
- # if you're sharing your code publicly.
12
-
13
- development:
14
- secret_key_base: 3bd8495239f6cd20f6e61ec4413fff9d672a872970e32e1defa8b211c13f9cbe4aff7a6462ff7c478b9503d203b2aa9f255fe44500d62d54dc9dfb5b3033dda2
15
-
16
- test:
17
- secret_key_base: 9d9a8398194c352425877555e6c8448ccf25ae19582112351150797bcbe5cb7e115de9d9f9e50e06ceace31945ebaeb848a374c6ce32024856fa52b52c2075c1
18
-
19
- # Do not keep production secrets in the repository,
20
- # instead read values from the environment.
21
- production:
22
- secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rake secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ development:
14
+ secret_key_base: 3bd8495239f6cd20f6e61ec4413fff9d672a872970e32e1defa8b211c13f9cbe4aff7a6462ff7c478b9503d203b2aa9f255fe44500d62d54dc9dfb5b3033dda2
15
+
16
+ test:
17
+ secret_key_base: 9d9a8398194c352425877555e6c8448ccf25ae19582112351150797bcbe5cb7e115de9d9f9e50e06ceace31945ebaeb848a374c6ce32024856fa52b52c2075c1
18
+
19
+ # Do not keep production secrets in the repository,
20
+ # instead read values from the environment.
21
+ production:
22
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@@ -1,11 +1,11 @@
1
- class CreatePeople < ActiveRecord::Migration
2
- def change
3
- create_table :people do |t|
4
- t.string :first_name
5
- t.string :last_name
6
- t.string :gender, limit: 1 # enum: m, f, o (other)
7
- t.date :date_of_birth
8
- t.timestamps null: false
9
- end
10
- end
11
- end
1
+ class CreatePeople < ActiveRecord::Migration
2
+ def change
3
+ create_table :people do |t|
4
+ t.string :first_name
5
+ t.string :last_name
6
+ t.string :gender, limit: 1 # enum: m, f, o (other)
7
+ t.date :date_of_birth
8
+ t.timestamps null: false
9
+ end
10
+ end
11
+ end
@@ -1,11 +1,11 @@
1
- class CreateGroups < ActiveRecord::Migration
2
- def change
3
- create_table :groups do |t|
4
- t.string :name
5
- t.integer :owner_id
6
- t.timestamps null: false
7
-
8
- t.index [:owner_id], name: 'groups_owner_lookup'
9
- end
10
- end
11
- end
1
+ class CreateGroups < ActiveRecord::Migration
2
+ def change
3
+ create_table :groups do |t|
4
+ t.string :name
5
+ t.integer :owner_id
6
+ t.timestamps null: false
7
+
8
+ t.index [:owner_id], name: 'groups_owner_lookup'
9
+ end
10
+ end
11
+ end
@@ -1,11 +1,11 @@
1
- class CreateGroupPeople < ActiveRecord::Migration
2
- def change
3
- create_table :group_people do |t|
4
- t.references :group
5
- t.references :person
6
- t.timestamps null: false
7
-
8
- t.index [:group_id, :person_id], unique: true, name: 'group_people_lookup'
9
- end
10
- end
11
- end
1
+ class CreateGroupPeople < ActiveRecord::Migration
2
+ def change
3
+ create_table :group_people do |t|
4
+ t.references :group
5
+ t.references :person
6
+ t.timestamps null: false
7
+
8
+ t.index [:group_id, :person_id], unique: true, name: 'group_people_lookup'
9
+ end
10
+ end
11
+ end
@@ -1,43 +1,43 @@
1
- # encoding: UTF-8
2
- # This file is auto-generated from the current state of the database. Instead
3
- # of editing this file, please use the migrations feature of Active Record to
4
- # incrementally modify your database, and then regenerate this schema definition.
5
- #
6
- # Note that this schema.rb definition is the authoritative source for your
7
- # database schema. If you need to create the application database on another
8
- # system, you should be using db:schema:load, not running all the migrations
9
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
- # you'll amass, the slower it'll run and the greater likelihood for issues).
11
- #
12
- # It's strongly recommended that you check this file into your version control system.
13
-
14
- ActiveRecord::Schema.define(version: 20161006134746) do
15
-
16
- create_table "group_people", force: :cascade do |t|
17
- t.integer "group_id"
18
- t.integer "person_id"
19
- t.datetime "created_at", null: false
20
- t.datetime "updated_at", null: false
21
- end
22
-
23
- add_index "group_people", ["group_id", "person_id"], name: "group_people_lookup", unique: true
24
-
25
- create_table "groups", force: :cascade do |t|
26
- t.string "name"
27
- t.integer "owner_id"
28
- t.datetime "created_at", null: false
29
- t.datetime "updated_at", null: false
30
- end
31
-
32
- add_index "groups", ["owner_id"], name: "groups_owner_lookup"
33
-
34
- create_table "people", force: :cascade do |t|
35
- t.string "first_name"
36
- t.string "last_name"
37
- t.string "gender", limit: 1
38
- t.date "date_of_birth"
39
- t.datetime "created_at", null: false
40
- t.datetime "updated_at", null: false
41
- end
42
-
43
- end
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended that you check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(version: 20161006134746) do
15
+
16
+ create_table "group_people", force: :cascade do |t|
17
+ t.integer "group_id"
18
+ t.integer "person_id"
19
+ t.datetime "created_at", null: false
20
+ t.datetime "updated_at", null: false
21
+ end
22
+
23
+ add_index "group_people", ["group_id", "person_id"], name: "group_people_lookup", unique: true
24
+
25
+ create_table "groups", force: :cascade do |t|
26
+ t.string "name"
27
+ t.integer "owner_id"
28
+ t.datetime "created_at", null: false
29
+ t.datetime "updated_at", null: false
30
+ end
31
+
32
+ add_index "groups", ["owner_id"], name: "groups_owner_lookup"
33
+
34
+ create_table "people", force: :cascade do |t|
35
+ t.string "first_name"
36
+ t.string "last_name"
37
+ t.string "gender", limit: 1
38
+ t.date "date_of_birth"
39
+ t.datetime "created_at", null: false
40
+ t.datetime "updated_at", null: false
41
+ end
42
+
43
+ end
@@ -1,16 +1,16 @@
1
- module Forms
2
- class GroupForm < Kadmin::Form
3
- delegate_attributes :name, :owner_id
4
- delegate_association :owner, to: 'Forms::PersonForm'
5
-
6
- def initialize(*args)
7
- super
8
- raise(ArgumentError, 'Model given should be a group') unless @model.is_a?(Group)
9
- end
10
-
11
- def owner_attributes=(attributes)
12
- form = owner
13
- form.assign_attributes(attributes)
14
- end
15
- end
16
- end
1
+ module Forms
2
+ class GroupForm < Kadmin::Form
3
+ delegate_attributes :name, :owner_id
4
+ delegate_association :owner, to: 'Forms::PersonForm'
5
+
6
+ def initialize(*args)
7
+ super
8
+ raise(ArgumentError, 'Model given should be a group') unless @model.is_a?(Group)
9
+ end
10
+
11
+ def owner_attributes=(attributes)
12
+ form = owner
13
+ form.assign_attributes(attributes)
14
+ end
15
+ end
16
+ end
@@ -1,19 +1,19 @@
1
- module Forms
2
- class PersonForm < Kadmin::Form
3
- delegate_attributes :gender, :first_name, :last_name, :date_of_birth, :groups
4
-
5
- def initialize(*args)
6
- super
7
- raise(ArgumentError, 'Model given should be a person') unless @model.is_a?(Person)
8
- end
9
-
10
- validate :adult?
11
- def adult?
12
- cutoff_date = 18.years.ago.beginning_of_day
13
- if @model.date_of_birth >= cutoff_date
14
- @errors.add(:date_of_birth, :invalid, message: 'must be 18 years old')
15
- end
16
- end
17
- private :adult?
18
- end
19
- end
1
+ module Forms
2
+ class PersonForm < Kadmin::Form
3
+ delegate_attributes :gender, :first_name, :last_name, :date_of_birth, :groups
4
+
5
+ def initialize(*args)
6
+ super
7
+ raise(ArgumentError, 'Model given should be a person') unless @model.is_a?(Person)
8
+ end
9
+
10
+ validate :adult?
11
+ def adult?
12
+ cutoff_date = 18.years.ago.beginning_of_day
13
+ if @model.date_of_birth >= cutoff_date
14
+ @errors.add(:date_of_birth, :invalid, message: 'must be 18 years old')
15
+ end
16
+ end
17
+ private :adult?
18
+ end
19
+ end