meta_field_api 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e26ab3c5d220dccf1972335777c12912fe5c024863a9ae638e8df34241f62657
4
+ data.tar.gz: 5615ab1badb6c8d5d20b43a71813907ad6cea692374b7993e53d0891ad119620
5
+ SHA512:
6
+ metadata.gz: 5a5e63e21d64aa4610ec43dbec867dcc28db7817c90d841b9aa76a4a5ef4c29c5474acc8cbdf64a7e717d1090fc74c1ffbdcc392eaadd34be3420e1e1670cbcb
7
+ data.tar.gz: 7bf30741db00b061f8e32f711456ba617399834a2a317d64209a400eb71c18f7404e4d51a1357ee28eb6b3dea86f7e55f1fb68f9aeecfe7b0d8b69a36a5afdf6
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2023 RumanOnMove
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
+ # MetaFieldApi
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 "meta_field_api"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install meta_field_api
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("test/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 @@
1
+ //= link_directory ../stylesheets/meta_field_api .css
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module MetaFieldApi
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,69 @@
1
+ module MetaFieldApi
2
+ class MetafieldsController < ApplicationController
3
+ # List of all metafields
4
+ def index
5
+ # Get the filter parameters from the params hash
6
+ owner_type = params[:owner_type].presence
7
+ owner_id = params[:owner_id].presence
8
+ key = params[:key].presence
9
+ namespace = params[:namespace].presence
10
+
11
+ metafields = Metafield.filter_by(owner_type, owner_id, key, namespace)
12
+ render json: { metafields: metafields, message: 'Metafields retrieved successfully!' }, status: :ok
13
+ end
14
+
15
+ # Store metafields
16
+ def create
17
+ metafield = Metafield.new(metafield_params)
18
+
19
+ if metafield.save
20
+ render json: { metafield: metafield, message: 'Metafield created successfully!' }, status: :created
21
+ else
22
+ render json: { error: metafield.errors }, status: :unprocessable_entity
23
+ end
24
+ rescue StandardError => e
25
+ render json: { error: e.message }, status: :unprocessable_entity
26
+ end
27
+
28
+ # Show specific metafield
29
+ def show
30
+ metafield = Metafield.find_by(id: params[:id])
31
+
32
+ if metafield
33
+ render json: { metafield: metafield, message: 'Metafield retrieved successfully!' }, status: :ok
34
+ else
35
+ render json: { message: 'Metafield not found' }, status: :not_found
36
+ end
37
+ end
38
+
39
+ # Update specific metafield
40
+ def update
41
+ metafield = Metafield.find_by(id: params[:id])
42
+
43
+ if metafield.update(metafield_params)
44
+ render json: { metafield: metafield, message: 'Metafield updated successfully!' }, status: :ok
45
+ else
46
+ render json: { error: metafield.errors }, status: :unprocessable_entity
47
+ end
48
+ rescue StandardError => e
49
+ render json: { error: e.message }
50
+ end
51
+
52
+ def destroy
53
+ metafield = Metafield.find_by(id: params[:id])
54
+
55
+ if metafield&.destroy
56
+ render json: { message: 'Metafield deleted successfully!' }, status: :ok
57
+ else
58
+ render json: { error: 'Metafield not found or could not be deleted' }, status: :unprocessable_entity
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ # Metafield params
65
+ def metafield_params
66
+ params.permit(:namespace, :key, :value, :description, :my_type, :owner_type, :owner_id)
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,4 @@
1
+ module MetaFieldApi
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module MetaFieldApi
2
+ module MetaFieldsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module MetaFieldApi
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module MetaFieldApi
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: "from@example.com"
4
+ layout "mailer"
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module UserExtension
2
+ extend ActiveSupport::Concern
3
+ end
@@ -0,0 +1,38 @@
1
+ module MetaFieldApi
2
+ class Metafield < ApplicationRecord
3
+ # Associations
4
+ belongs_to :owner, polymorphic: true
5
+
6
+ # Validations
7
+ validates :namespace, presence: true, length: {maximum: 55}
8
+ validates :key, presence: true, length: {maximum: 55}
9
+ validates :value, presence: true
10
+ validates :description, presence: false, length: {maximum: 255}
11
+ validates :my_type, presence: true, length: {maximum: 55}
12
+ validates :owner_id, presence: true
13
+ validates :owner_type, presence: true
14
+
15
+ # Attributes
16
+ self.table_name = "meta_field_api_metafields"
17
+ self.inheritance_column = :my_type
18
+
19
+ # Alias for type column to avoid conflict with Rails' inheritance column
20
+ def my_type
21
+ read_attribute(:type)
22
+ end
23
+
24
+ def my_type=(value)
25
+ write_attribute(:type, value)
26
+ end
27
+
28
+ # Scope
29
+ scope :filter_by, -> (owner_type = nil, owner_id = nil, key = nil, namespace = nil) do
30
+ filter_params = {}
31
+ filter_params[:owner_type] = owner_type if owner_type.present?
32
+ filter_params[:owner_id] = owner_id if owner_id.present?
33
+ filter_params[:key] = key if key.present?
34
+ filter_params[:namespace] = namespace if namespace.present?
35
+ where(filter_params)
36
+ end
37
+ end
38
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ MetaFieldApi::Engine.routes.draw do
2
+ resources :metafields, only: [:index, :show, :create, :update, :destroy]
3
+ end
@@ -0,0 +1,14 @@
1
+ class CreateMetaFieldApiMetafields < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :meta_field_api_metafields do |t|
4
+ t.string :namespace
5
+ t.string :key
6
+ t.text :value
7
+ t.text :description
8
+ t.text :type
9
+ t.references :owner, polymorphic: true
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module MetaFieldApi
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace MetaFieldApi
4
+
5
+ # Add this line to load migrations
6
+ initializer :append_migrations do |app|
7
+ unless app.root.to_s.match?(root.to_s)
8
+ config.paths["db/migrate"].expanded.each do |expanded_path|
9
+ app.config.paths["db/migrate"] << expanded_path
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module MetaFieldApi
2
+ module HasMetafields
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ has_many :metafields, as: :owner, class_name: "MetaFieldApi::Metafield"
7
+ def as_json(options = {})
8
+ super(options.merge(include: :metafields))
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module MetaFieldApi
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require "meta_field_api/version"
2
+ require "meta_field_api/engine"
3
+ require "meta_field_api/has_metafields"
4
+
5
+ module MetaFieldApi
6
+
7
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :meta_field_api do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: meta_field_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - RumanOnMove
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-05-07 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.4.3
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.4.3
27
+ description: This Rails engine provides APIs for managing meta fields through a RESTful
28
+ interface. It includes a migration for creating the necessary database table and
29
+ a controller with methods for index, show, create, update, and delete.
30
+ email:
31
+ - oruman@moveon.com.bd
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - MIT-LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - app/assets/config/meta_field_api_manifest.js
40
+ - app/assets/stylesheets/meta_field_api/application.css
41
+ - app/controllers/meta_field_api/application_controller.rb
42
+ - app/controllers/meta_field_api/metafields_controller.rb
43
+ - app/helpers/meta_field_api/application_helper.rb
44
+ - app/helpers/meta_field_api/meta_fields_helper.rb
45
+ - app/jobs/meta_field_api/application_job.rb
46
+ - app/mailers/meta_field_api/application_mailer.rb
47
+ - app/models/meta_field_api/application_record.rb
48
+ - app/models/meta_field_api/metafield.rb
49
+ - config/routes.rb
50
+ - db/migrate/20230502083945_create_meta_field_api_metafields.rb
51
+ - lib/meta_field_api.rb
52
+ - lib/meta_field_api/engine.rb
53
+ - lib/meta_field_api/has_metafields.rb
54
+ - lib/meta_field_api/version.rb
55
+ - lib/tasks/meta_field_api_tasks.rake
56
+ homepage:
57
+ licenses:
58
+ - MIT
59
+ metadata:
60
+ source_code_uri: https://github.com/RumanOnMove/meta_field_api
61
+ changelog_uri: https://github.com/RumanOnMove/meta_field_api/blob/main/CHANGELOG.md
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubygems_version: 3.3.5
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: A Rails engine for managing meta fields
81
+ test_files: []