model_info 0.0.8 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5246392322490ce9575c71a6c33bbf2892440d91a53a72855a796967fb7b9f31
4
- data.tar.gz: d96067439db1995a3d4e7c5f35307cb0b8ed750f314e528e4ad00c56ca56d35e
3
+ metadata.gz: e20bfbae6791d932df14a9b96cab61967b47d4cbed0fa69dd69bcaf6e232d970
4
+ data.tar.gz: 6d80e18b10fc55e142bb7ad9ad5a786ab416b602f08c12f9b3d38026b0486263
5
5
  SHA512:
6
- metadata.gz: e88f6e3e2eef8b8a06eb8afb3d4fef6643bbd0e057901274bc30a1350cf7166266a6cdabc6de72e07d05ee60d630ddea2d6cddf1240ffa62e2bd17425e77eef4
7
- data.tar.gz: b45c787971ab44fca264d54403c4738e030325c182ec96c63fccf86556b456132bdda5d6fb9f0f4147647949349f723e416bb30936002defad33de8f255e9d29
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,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ModelInfo
4
+ module Api
5
+ module V1
6
+ class AssociationsController < BaseController
7
+ end
8
+ end
9
+ end
10
+ end
@@ -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: "rooh", salary: 138001, month: "jan", created_at: "2018-08-29 07:47:43", updated_at: "2018-09-12 09:35:09", manager_id: 8, lock_version: 4>'
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
- array=[], @model_array=[]
22
+ @model_array = []
22
23
  Rails.application.eager_load!
23
- array=ActiveRecord::Base.descendants.collect { |x| x.to_s if x.table_exists? }.compact
24
- array.each do |x|
25
- if x.split('::').last.split('_').first != 'HABTM'
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: [:show, :edit, :update]
6
+ before_action :set_model_data, only: %i[show edit update]
7
7
 
8
- def display
9
- @model_class, @page = params[:model_class] || @model_array.try(:first), params[:page] || 1
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=@model_class.find(params[:model_object_id])
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
- root to: 'models#display'
4
-
5
- get 'model_display', to: 'models#display'
6
- get 'models',to: 'models#index'
7
- get 'model_new',to: 'models#new'
8
- post 'model_create',to: 'models#create'
9
- get 'model_show',to: 'models#show'
10
- get 'model_edit',to: 'models#edit'
11
- patch 'model_update',to: 'models#update'
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', to: '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'
@@ -4,9 +4,8 @@ module ModelInfo
4
4
  class Engine < ::Rails::Engine
5
5
  isolate_namespace ModelInfo
6
6
 
7
- initializer 'model_info', before: :load_config_initializers do |app|
8
- app.config.assets.precompile += %w( model_info/application.js model_info/application.css)
9
-
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?
10
9
  Rails.application.routes.append do
11
10
  mount ModelInfo::Engine, at: '/model_info'
12
11
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ModelInfo
2
- VERSION = '0.0.8'
4
+ VERSION = '0.0.9'
3
5
  end
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.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - nitanshu verma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-05 00:00:00.000000000 Z
11
+ date: 2024-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bootstrap
@@ -56,6 +56,9 @@ files:
56
56
  - app/assets/stylesheets/model_info/bootstrap.css
57
57
  - app/assets/stylesheets/model_info/bootstrap.min.css
58
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
59
62
  - app/controllers/model_info/application_controller.rb
60
63
  - app/controllers/model_info/associations_controller.rb
61
64
  - app/controllers/model_info/downloads_controller.rb
@@ -70,8 +73,8 @@ files:
70
73
  - app/views/model_info/associations/index.html.erb
71
74
  - app/views/model_info/associations/new.html.erb
72
75
  - app/views/model_info/associations/show.html.erb
73
- - app/views/model_info/models/display.html.erb
74
76
  - app/views/model_info/models/edit.html.erb
77
+ - app/views/model_info/models/index.html.erb
75
78
  - app/views/model_info/models/new.html.erb
76
79
  - app/views/model_info/models/show.html.erb
77
80
  - app/views/model_info/shared/_flash_messages.html.erb