model_info 0.0.7 → 0.0.9
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 +5 -5
- data/README.rdoc +15 -0
- data/app/assets/config/model_info/manifest.js +3 -0
- data/app/assets/javascripts/model_info/application.js +0 -2
- data/app/controllers/model_info/api/v1/associations_controller.rb +10 -0
- data/app/controllers/model_info/api/v1/base_controller.rb +18 -0
- data/app/controllers/model_info/api/v1/models_controller.rb +57 -0
- data/app/controllers/model_info/application_controller.rb +9 -9
- data/app/controllers/model_info/models_controller.rb +8 -9
- data/config/routes.rb +30 -16
- data/lib/model_info/engine.rb +1 -0
- data/lib/model_info/version.rb +3 -1
- metadata +15 -16
- data/app/assets/javascripts/model_info/associations.js +0 -2
- data/app/assets/javascripts/model_info/fetch_model_infos.js +0 -2
- data/app/assets/stylesheets/model_info/associations.css +0 -4
- data/app/assets/stylesheets/model_info/fetch_model_infos.css +0 -4
- /data/app/views/model_info/models/{display.html.erb → index.html.erb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e20bfbae6791d932df14a9b96cab61967b47d4cbed0fa69dd69bcaf6e232d970
|
4
|
+
data.tar.gz: 6d80e18b10fc55e142bb7ad9ad5a786ab416b602f08c12f9b3d38026b0486263
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 151d3fa3ffa070a8515552aef0d74660ea78b4fa9a101fe154df072b9332795f9e5e1dc4f78ebb9cf7b61a974fd4ba4b423515fd10f5ff460e4ef5f40bef2acb
|
7
|
+
data.tar.gz: f185599bcbc84cd5cb54b374037fd65cd3df07a1bda73570b0a2da96d3132211e143268057f4313b0100966738c9d59e4f3bd1f1d90effb11a435d5a68d083b9
|
data/README.rdoc
CHANGED
@@ -2,6 +2,19 @@
|
|
2
2
|
|
3
3
|
ModelInfo provides the UI interface for the CRUD of all models (including engine's) and their associated models.
|
4
4
|
It also provides you the download link for CSV and JSON format of Model's data.
|
5
|
+
|
6
|
+
== API
|
7
|
+
|
8
|
+
It provides the API support for all models to fetch the model information suppose we have a model Article
|
9
|
+
|
10
|
+
Then the API's will be
|
11
|
+
- GET /model_info/api/v1/articles(.:format)
|
12
|
+
- POST /api/v1/articles(.:format)
|
13
|
+
- GET /api/v1/articles/:id(.:format)
|
14
|
+
- PUT /api/v1/articles/:id(.:format)
|
15
|
+
- DELETE /api/v1/articles/:id(.:format)
|
16
|
+
|
17
|
+
|
5
18
|
== Installation
|
6
19
|
|
7
20
|
Add this line to your application's Gemfile:
|
@@ -19,3 +32,5 @@ After successful installation of gem the UI interface will be available on
|
|
19
32
|
your_application_url */model_info/models*
|
20
33
|
|
21
34
|
example: localhost:3000/model_info
|
35
|
+
|
36
|
+
To use the API of model_info Please curl the request or use any API platform for using this.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ModelInfo
|
4
|
+
module Api
|
5
|
+
module V1
|
6
|
+
# :nodoc
|
7
|
+
class BaseController < ::ApplicationController
|
8
|
+
def models_array
|
9
|
+
Rails.application.eager_load!
|
10
|
+
model_names = ActiveRecord::Base.descendants.collect { |model| model.to_s if model.table_exists? }.compact
|
11
|
+
model_names.delete('ActiveStorage::Blob')
|
12
|
+
model_names.delete('ActiveStorage::Attachment')
|
13
|
+
@model_array = model_names.map(&:pluralize).map(&:downcase)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module ModelInfo
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
# :nodoc
|
5
|
+
class ModelsController < BaseController
|
6
|
+
before_action :find_model_object, only: %i[edit update show destroy]
|
7
|
+
|
8
|
+
# GET /models or /models.json
|
9
|
+
def index
|
10
|
+
render json: model.all
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /comapnies/new
|
14
|
+
def show
|
15
|
+
render json: @model_object
|
16
|
+
end
|
17
|
+
|
18
|
+
def create
|
19
|
+
model_object = model.new(permit_params)
|
20
|
+
if model_object.save
|
21
|
+
render json: { status: :created }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
@model_object.update(permit_params)
|
27
|
+
end
|
28
|
+
|
29
|
+
def destroy
|
30
|
+
@model_object.destroy
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def model
|
36
|
+
model = request.path.split('/').select { |element| models_array.include?(element) }.first
|
37
|
+
@model = model.classify.constantize
|
38
|
+
end
|
39
|
+
|
40
|
+
# Only allow a list of trusted parameters through.
|
41
|
+
def permit_params
|
42
|
+
params.require(:"#{model.to_s.downcase}").permit(model_attributes)
|
43
|
+
end
|
44
|
+
|
45
|
+
def model_attributes
|
46
|
+
except ||= %w[id created_at updated_at]
|
47
|
+
model.attribute_names.reject { |attr| except.include?(attr) }
|
48
|
+
end
|
49
|
+
|
50
|
+
# Use callbacks to share common setup or constraints between actions.
|
51
|
+
def find_model_object
|
52
|
+
@model_object = model.find(params[:id])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module ModelInfo
|
2
2
|
class ApplicationController < ::ApplicationController
|
3
3
|
#========================= Example =================================#
|
4
|
-
#class Employee < ApplicationRecord
|
4
|
+
# class Employee < ApplicationRecord
|
5
5
|
# has_many :projects
|
6
|
-
#end
|
6
|
+
# end
|
7
7
|
#============================ Naming Conventions ====================#
|
8
8
|
# model_class 'Employee'
|
9
9
|
# model_name 'employee'
|
10
10
|
# model_object_id '1'
|
11
|
-
# model_data '#<Employee id: 1, name: "
|
11
|
+
# model_data '#<Employee id: 1, name: "Alen", salary: 10000, month: "Jan",manager_id: 8, lock_version: 4>'
|
12
12
|
# associated_model_class 'Project'
|
13
13
|
# associated_model_name 'projects'
|
14
14
|
# associated_model_object_id '1'
|
@@ -17,15 +17,15 @@ module ModelInfo
|
|
17
17
|
before_action :models_tab
|
18
18
|
|
19
19
|
private
|
20
|
+
|
20
21
|
def models_tab
|
21
|
-
|
22
|
+
@model_array = []
|
22
23
|
Rails.application.eager_load!
|
23
|
-
|
24
|
-
|
25
|
-
if
|
26
|
-
@model_array.push(x)
|
27
|
-
end
|
24
|
+
model_names = ActiveRecord::Base.descendants.collect { |model| model.to_s if model.table_exists? }.compact
|
25
|
+
model_names.each do |model_name|
|
26
|
+
@model_array.push(model_name) if model_name.split('::').last.split('_').first != 'HABTM'
|
28
27
|
@model_array.delete('ActiveRecord::SchemaMigration')
|
28
|
+
$model_array = @model_array
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -3,10 +3,11 @@ require_dependency 'model_info/application_controller'
|
|
3
3
|
module ModelInfo
|
4
4
|
class ModelsController < ApplicationController
|
5
5
|
before_action :model_class_and_name
|
6
|
-
before_action :set_model_data, only: [
|
6
|
+
before_action :set_model_data, only: %i[show edit update]
|
7
7
|
|
8
|
-
def
|
9
|
-
@model_class
|
8
|
+
def index
|
9
|
+
@model_class = params[:model_class] || @model_array&.first
|
10
|
+
@page = params[:page] || 1
|
10
11
|
@model_pagination = @model_class.constantize.page(@page).per(10)
|
11
12
|
end
|
12
13
|
|
@@ -24,11 +25,9 @@ module ModelInfo
|
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
|
-
def edit
|
28
|
-
end
|
28
|
+
def edit; end
|
29
29
|
|
30
|
-
def show
|
31
|
-
end
|
30
|
+
def show; end
|
32
31
|
|
33
32
|
def update
|
34
33
|
if @model_data.update(permit_params)
|
@@ -56,7 +55,7 @@ module ModelInfo
|
|
56
55
|
end
|
57
56
|
|
58
57
|
def set_model_data
|
59
|
-
@model_data
|
58
|
+
@model_data = @model_class.find(params[:model_object_id])
|
60
59
|
end
|
61
60
|
end
|
62
|
-
end
|
61
|
+
end
|
data/config/routes.rb
CHANGED
@@ -1,23 +1,37 @@
|
|
1
1
|
ModelInfo::Engine.routes.draw do
|
2
|
+
root to: 'models#index'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
namespace :api do
|
5
|
+
namespace :v1 do
|
6
|
+
Rails.application.eager_load!
|
7
|
+
model_names = ActiveRecord::Base.descendants.collect { |model| model.to_s if model.table_exists? }.compact
|
8
|
+
model_names.delete('ActiveStorage::Blob')
|
9
|
+
model_names.delete('ActiveStorage::Attachment')
|
10
|
+
model_names = model_names.map(&:pluralize).map(&:downcase)
|
11
|
+
model_names.each do |model|
|
12
|
+
get model, to: 'models#index'
|
13
|
+
post model, to: 'models#create'
|
14
|
+
get "#{model}/:id", to: 'models#show'
|
15
|
+
put "#{model}/:id", to: 'models#update'
|
16
|
+
delete "#{model}/:id", to: 'models#destroy'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
get 'models', to: 'models#index'
|
21
|
+
get 'model_new', to: 'models#new'
|
22
|
+
post 'model_create', to: 'models#create'
|
23
|
+
get 'model_show', to: 'models#show'
|
24
|
+
get 'model_edit', to: 'models#edit'
|
25
|
+
patch 'model_update', to: 'models#update'
|
12
26
|
delete 'model_destroy', to: 'models#destroy'
|
13
27
|
|
14
|
-
get 'associations_index',
|
15
|
-
get 'association_new',to: 'associations#new'
|
16
|
-
post 'association_create',to: 'associations#create'
|
17
|
-
get 'association_show',to: 'associations#show'
|
18
|
-
get 'association_edit',to: 'associations#edit'
|
19
|
-
patch 'association_update',to: 'associations#update'
|
20
|
-
delete 'association_destroy',to: 'associations#destroy'
|
28
|
+
get 'associations_index', to: 'associations#index'
|
29
|
+
get 'association_new', to: 'associations#new'
|
30
|
+
post 'association_create', to: 'associations#create'
|
31
|
+
get 'association_show', to: 'associations#show'
|
32
|
+
get 'association_edit', to: 'associations#edit'
|
33
|
+
patch 'association_update', to: 'associations#update'
|
34
|
+
delete 'association_destroy', to: 'associations#destroy'
|
21
35
|
|
22
36
|
get 'download_csv', to: 'downloads#download_csv'
|
23
37
|
get 'download_json', to: 'downloads#download_json'
|
data/lib/model_info/engine.rb
CHANGED
@@ -5,6 +5,7 @@ module ModelInfo
|
|
5
5
|
isolate_namespace ModelInfo
|
6
6
|
|
7
7
|
initializer 'model_info', before: :load_config_initializers do |app|
|
8
|
+
app.config.assets.precompile += %w[model_info/application.js model_info/application.css)] if app.config.assets.present?
|
8
9
|
Rails.application.routes.append do
|
9
10
|
mount ModelInfo::Engine, at: '/model_info'
|
10
11
|
end
|
data/lib/model_info/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: model_info
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nitanshu verma
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bootstrap
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.2.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 5.2.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: kaminari
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.2.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.2.2
|
41
41
|
description: ModelInfo provides the UI interface for the CRUD of all models (including
|
42
42
|
engine's) and their associated models. It also enables the admin to download the
|
43
43
|
CSV and JSON format data of all the Models and their associated Models.
|
@@ -50,15 +50,15 @@ files:
|
|
50
50
|
- MIT-LICENSE
|
51
51
|
- README.rdoc
|
52
52
|
- Rakefile
|
53
|
+
- app/assets/config/model_info/manifest.js
|
53
54
|
- app/assets/javascripts/model_info/application.js
|
54
|
-
- app/assets/javascripts/model_info/associations.js
|
55
|
-
- app/assets/javascripts/model_info/fetch_model_infos.js
|
56
55
|
- app/assets/stylesheets/model_info/application.css
|
57
|
-
- app/assets/stylesheets/model_info/associations.css
|
58
56
|
- app/assets/stylesheets/model_info/bootstrap.css
|
59
57
|
- app/assets/stylesheets/model_info/bootstrap.min.css
|
60
|
-
- app/assets/stylesheets/model_info/fetch_model_infos.css
|
61
58
|
- app/assets/stylesheets/model_info/sytle.css.scss
|
59
|
+
- app/controllers/model_info/api/v1/associations_controller.rb
|
60
|
+
- app/controllers/model_info/api/v1/base_controller.rb
|
61
|
+
- app/controllers/model_info/api/v1/models_controller.rb
|
62
62
|
- app/controllers/model_info/application_controller.rb
|
63
63
|
- app/controllers/model_info/associations_controller.rb
|
64
64
|
- app/controllers/model_info/downloads_controller.rb
|
@@ -73,8 +73,8 @@ files:
|
|
73
73
|
- app/views/model_info/associations/index.html.erb
|
74
74
|
- app/views/model_info/associations/new.html.erb
|
75
75
|
- app/views/model_info/associations/show.html.erb
|
76
|
-
- app/views/model_info/models/display.html.erb
|
77
76
|
- app/views/model_info/models/edit.html.erb
|
77
|
+
- app/views/model_info/models/index.html.erb
|
78
78
|
- app/views/model_info/models/new.html.erb
|
79
79
|
- app/views/model_info/models/show.html.erb
|
80
80
|
- app/views/model_info/shared/_flash_messages.html.erb
|
@@ -89,7 +89,7 @@ homepage: https://github.com/nitanshu/model_info
|
|
89
89
|
licenses:
|
90
90
|
- MIT
|
91
91
|
metadata: {}
|
92
|
-
post_install_message:
|
92
|
+
post_install_message:
|
93
93
|
rdoc_options: []
|
94
94
|
require_paths:
|
95
95
|
- lib
|
@@ -104,9 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
|
-
|
108
|
-
|
109
|
-
signing_key:
|
107
|
+
rubygems_version: 3.2.32
|
108
|
+
signing_key:
|
110
109
|
specification_version: 4
|
111
110
|
summary: ModelInfo provides the UI interface for the CRUD of all models (including
|
112
111
|
engine's) and their associated models.
|
File without changes
|