api_maker_table 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cb01aa0fdd8e6efecfb54d3b783dd45a386375fb084ee6ff5561684ec1393187
4
+ data.tar.gz: 27e66e0459a42371339902e94150bd941a912e73299933a887a451b923411237
5
+ SHA512:
6
+ metadata.gz: 71e5ebb258e2b5c46bb8189c957b62207cc924fe060c94d2ed299102459c6565c15d572b7d691b477504369f30e48f5d03e208dce42da9ca9fcbf8d0b396b3fd
7
+ data.tar.gz: 2723674cce83676d32961c8cb722a45548cbbdca01a1c71da415f7871982d3b5c74e9e2fee1707faf8201e609fa1cd150aaa42de9dc78a30de5a639b1d1deb04
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2022 kaspernj
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # ApiMakerTable
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "api_maker_table"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install api_maker_table
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
8
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ class Resources::TableSettingColumnResource < ApiMaker::BaseResource
2
+ self.model_class_name = "ApiMakerTable::TableSettingColumn"
3
+
4
+ attributes :attribute_name, :id, :identifier, :path, :position, :sort_key, :visible
5
+ relationships :table_setting
6
+
7
+ def abilities
8
+ can CRUD, ApiMakerTable::TableSettingColumn, table_setting: {user_id: current_user.id, user_type: current_user.class.name} if current_user
9
+ end
10
+ end
@@ -0,0 +1,21 @@
1
+ class Resources::TableSettingResource < ApiMaker::BaseResource
2
+ self.model_class_name = "ApiMakerTable::TableSetting"
3
+
4
+ attributes :id, :identifier
5
+ relationships :columns
6
+
7
+ def abilities
8
+ puts "Allow creating table for: #{{user_id: current_user.id, user_type: current_user.class.name}}"
9
+
10
+ can CRUD, ApiMakerTable::TableSetting, user_id: current_user.id, user_type: current_user.class.name if current_user
11
+ end
12
+
13
+ def permitted_params(arg)
14
+ arg.params.require(:table_setting).permit(
15
+ :identifier,
16
+ :user_id,
17
+ :user_type,
18
+ columns_attributes: [:attribute_name, :id, :identifier, :path, :position, :sort_key, :visible]
19
+ )
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module ApiMakerTable
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ class ApiMakerTable::TableSetting < ApiMakerTable::ApplicationRecord
2
+ self.table_name = "table_settings"
3
+
4
+ has_many :columns, class_name: "ApiMakerTable::TableSettingColumn", dependent: :destroy
5
+
6
+ accepts_nested_attributes_for :columns, allow_destroy: true
7
+ end
@@ -0,0 +1,7 @@
1
+ class ApiMakerTable::TableSettingColumn < ApiMakerTable::ApplicationRecord
2
+ self.table_name = "table_setting_columns"
3
+
4
+ belongs_to :table_setting
5
+
6
+ validates :identifier, presence: true, uniqueness: {scope: :table_setting}
7
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ ApiMakerTable::Engine.routes.draw do
2
+ end
@@ -0,0 +1,11 @@
1
+ class CreateTableSettings < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :table_settings do |t|
4
+ t.references :user, limit: 36, null: false, polymorphic: true, type: :string
5
+ t.string :identifier, index: true, null: false
6
+ t.timestamps
7
+ end
8
+
9
+ add_index :table_settings, [:user_id, :user_type, :identifier], unique: true
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ class CreateTableSettingColumns < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :table_setting_columns do |t|
4
+ t.references :table_setting, foreign_key: true, null: false
5
+ t.string :identifier, index: true, null: false
6
+ t.string :attribute_name
7
+ t.text :path
8
+ t.string :sort_key
9
+ t.integer :position, null: false
10
+ t.boolean :visible, default: true, null: false
11
+ t.timestamps
12
+ end
13
+
14
+ add_index :table_setting_columns, [:table_setting_id, :identifier], unique: true
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module ApiMakerTable
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace ApiMakerTable
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module ApiMakerTable
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "api_maker_table/version"
2
+ require "api_maker_table/engine"
3
+
4
+ module ApiMakerTable
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :api_maker_table do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: api_maker_table
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kaspernj
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-06-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 7.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 7.0.0
27
+ description: A Rails gem for generating a JavaScript API automatically based on your
28
+ ActiveRecord models.
29
+ email:
30
+ - k@spernj.org
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - MIT-LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - app/api_maker/resources/table_setting_column_resource.rb
39
+ - app/api_maker/resources/table_setting_resource.rb
40
+ - app/models/api_maker_table/application_record.rb
41
+ - app/models/api_maker_table/table_setting.rb
42
+ - app/models/api_maker_table/table_setting_column.rb
43
+ - config/routes.rb
44
+ - db/migrate/20220526073326_create_table_settings.rb
45
+ - db/migrate/20220526073350_create_table_setting_columns.rb
46
+ - lib/api_maker_table.rb
47
+ - lib/api_maker_table/engine.rb
48
+ - lib/api_maker_table/version.rb
49
+ - lib/tasks/api_maker_table_tasks.rake
50
+ homepage: https://github.com/kaspernj/api_maker
51
+ licenses:
52
+ - MIT
53
+ metadata: {}
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.2.32
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: A Rails gem for generating a JavaScript API automatically based on your ActiveRecord
73
+ models.
74
+ test_files: []