Skip to content

Commit

Permalink
UDF #9 - Adding resource-api dependency; Adding /user_defined_fields …
Browse files Browse the repository at this point in the history
…API endpoint
  • Loading branch information
dleadbetter committed Sep 16, 2022
1 parent 317ee05 commit dadad2b
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 7 deletions.
11 changes: 5 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
source "https://rubygems.org"
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem "sqlite3"
gem 'resource_api', git: 'https://github.com/performant-software/resource-api.git', tag: 'v0.4.2'

gem "sprockets-rails"
gem 'sqlite3'

gem 'sprockets-rails'

# Specify your gem's dependencies in user_defined_fields.gemspec.
gemspec

# Start debugger with binding.b [https://github.com/ruby/debug]
# gem "debug", ">= 1.0.0"
13 changes: 13 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
GIT
remote: https://github.com/performant-software/resource-api.git
revision: f1de1653b67fc1d623d7418e92d3bb3134df800e
tag: v0.4.2
specs:
resource_api (0.1.0)
pagy (~> 5.10)
rails (>= 6.0.3.2, < 8)

PATH
remote: .
specs:
user_defined_fields (0.1.0)
rails (>= 6.0.3.2, < 8)
resource_api

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -107,6 +117,8 @@ GEM
nio4r (2.5.8)
nokogiri (1.13.8-x86_64-darwin)
racc (~> 1.4)
pagy (5.10.1)
activesupport
racc (1.6.0)
rack (2.2.4)
rack-test (2.0.2)
Expand Down Expand Up @@ -160,6 +172,7 @@ PLATFORMS
x86_64-darwin-19

DEPENDENCIES
resource_api!
sprockets-rails
sqlite3
user_defined_fields!
Expand Down
15 changes: 14 additions & 1 deletion app/controllers/user_defined_fields/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
module UserDefinedFields
class ApplicationController < ActionController::API
class ApplicationController < Api::ResourceController
def current_user
return super if defined?(super)

nil
end

def item_class
"UserDefinedFields::#{controller_name.singularize.classify}".constantize
end

def serializer_class
"UserDefinedFields::#{"#{controller_name}_serializer".classify}".constantize
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module UserDefinedFields
class UserDefinedFieldsController < ApplicationController
search_attributes :table_name, :column_name
end
end
3 changes: 3 additions & 0 deletions app/models/user_defined_fields/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module UserDefinedFields
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true

# Includes
include Resourceable
end
end
4 changes: 4 additions & 0 deletions app/models/user_defined_fields/user_defined_field.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module UserDefinedFields
class UserDefinedField < ApplicationRecord
# Relationships
belongs_to :defineable, polymorphic: true, optional: true

# Resourceable parameters
allow_params :table_name, :column_name, :data_type, :required, :allow_multiple, :options
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module UserDefinedFields
class UserDefinedFieldsSerializer < BaseSerializer
index_attributes :id, :table_name, :column_name, :required, :allow_multiple, :options
show_attributes :id, :table_name, :column_name, :required, :allow_multiple, :options
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
UserDefinedFields::Engine.routes.draw do
resources :user_defined_fields
end
1 change: 1 addition & 0 deletions user_defined_fields.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ Gem::Specification.new do |spec|
end

spec.add_dependency 'rails', '>= 6.0.3.2', '< 8'
spec.add_dependency 'resource_api'
end

0 comments on commit dadad2b

Please sign in to comment.