atozfunc 0.1.1
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 +7 -0
- data/app/controllers/atoz_controller.rb +31 -0
- data/lib/atozfunc.rb +9 -0
- data/lib/atozfunc/controllers/atoz_controller.rb +4 -0
- data/lib/atozfunc/engine.rb +3 -0
- data/lib/atozfunc/general.rb +8 -0
- data/lib/atozfunc/version.rb +3 -0
- data/lib/generators/atozfunc/controller_generator.rb +28 -0
- data/lib/generators/atozfunc/generator_helpers.rb +61 -0
- data/lib/generators/atozfunc/templates/controller.rb +67 -0
- metadata +84 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 26ffb742ca0c855de45a8a9badc9d63dfd0f7117fe495f1dd70e53773a8f68e3
         | 
| 4 | 
            +
              data.tar.gz: b56f5d797d2d5eb44ac5ab2e562b8e7f325f11bf22ab257593695e8c050d77c3
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: dd889b2bd6acd9e16f981dc53fbd55e638c2aec4fee16156f8f99a18bcbc397da7d825d0aa3514d4c82d01a1259bd2755569aef6554293cca8fd224a6b0b7faf
         | 
| 7 | 
            +
              data.tar.gz: 3c5be5d9871794e5c31f6cdf985d863ae2b1d127edfab6fd125dec3bcfc913dab55ffaac7ec8980db1557bee46fdc3ae4de73ef21168fe3ca5b3e447e141efd0
         | 
| @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            class AtozController < ApplicationController
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              def render_response(type = "error", options = {})
         | 
| 4 | 
            +
                render json: construct_response(type, options)
         | 
| 5 | 
            +
              end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              def construct_response(type, options = {})
         | 
| 8 | 
            +
                options            = {}  if !options.class.eql?(Hash)
         | 
| 9 | 
            +
                options[:code]     = 200 if options[:code].blank?
         | 
| 10 | 
            +
                options[:messages] = []  if options[:messages].blank?
         | 
| 11 | 
            +
                options[:data]     = {}  if options[:data].blank?
         | 
| 12 | 
            +
                options[:meta]     = {}  if options[:meta].blank?
         | 
| 13 | 
            +
                options[:return]   = {}
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                options[:meta].merge!({
         | 
| 16 | 
            +
                  code: options[:code]
         | 
| 17 | 
            +
                }) if type.eql?("error")
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                options[:meta].merge!({
         | 
| 20 | 
            +
                  code: options[:code]
         | 
| 21 | 
            +
                }) if !type.eql?("error")
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                return options[:return].merge!({
         | 
| 24 | 
            +
                  meta: options[:meta].merge!({
         | 
| 25 | 
            +
                    messages: options[:messages]
         | 
| 26 | 
            +
                  }),
         | 
| 27 | 
            +
                  data: options[:data]
         | 
| 28 | 
            +
                })
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            end
         | 
    
        data/lib/atozfunc.rb
    ADDED
    
    
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            require 'generators/atozfunc/generator_helpers'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Atozfunc
         | 
| 4 | 
            +
              module Generators
         | 
| 5 | 
            +
                # Custom scaffolding generator
         | 
| 6 | 
            +
                class ControllerGenerator < Rails::Generators::NamedBase
         | 
| 7 | 
            +
                  include Rails::Generators::ResourceHelpers
         | 
| 8 | 
            +
                  include Atozfunc::Generators::GeneratorHelpers
         | 
| 9 | 
            +
                  source_root File.expand_path('../templates', __FILE__)
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  class_option :skip_show, type: :boolean, default: false, desc: "Skip show action"
         | 
| 12 | 
            +
                  class_option :with_params, type: :boolean, default: false, desc: "with method params"
         | 
| 13 | 
            +
                  class_option :skip_route, type: :boolean, default: false, desc: "skip adding routes"
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  desc "Generates controller, controller_spec and views for the model with the given NAME."
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  def copy_controller_and_spec_files
         | 
| 18 | 
            +
                    template "controller.rb", File.join("app/controllers/#{controller_dir}", "#{controller_file_name}_controller.rb")
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  def add_routes
         | 
| 22 | 
            +
                    routes_string = "resources :#{plural_name}"
         | 
| 23 | 
            +
                    routes_string += ', except: :show' unless show_action?
         | 
| 24 | 
            +
                    route routes_string  unless skip_route?
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
| @@ -0,0 +1,61 @@ | |
| 1 | 
            +
            module Atozfunc
         | 
| 2 | 
            +
              module Generators
         | 
| 3 | 
            +
                # Some helpers for generating scaffolding
         | 
| 4 | 
            +
                module GeneratorHelpers
         | 
| 5 | 
            +
                  attr_accessor :options, :attributes
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                  private
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  def model_columns_for_attributes
         | 
| 10 | 
            +
                    class_name.constantize.columns.reject do |column|
         | 
| 11 | 
            +
                      column.name.to_s =~ /^(id|user_id|created_at|updated_at)$/
         | 
| 12 | 
            +
                    end
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  def editable_attributes
         | 
| 16 | 
            +
                    attributes ||= model_columns_for_attributes.map do |column|
         | 
| 17 | 
            +
                      Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
                    return attributes.map { |a| a.name.prepend(':') }.join(', ')
         | 
| 20 | 
            +
                  rescue
         | 
| 21 | 
            +
                    {}
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  def show_action?
         | 
| 25 | 
            +
                    !options['skip_show']
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  def skip_route?
         | 
| 29 | 
            +
                    options['skip_route']
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  def with_params?
         | 
| 33 | 
            +
                    options['with_params']
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  def controller_class_name
         | 
| 37 | 
            +
                    @controller_class_name = super
         | 
| 38 | 
            +
                    return @controller_class_name
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  def split_controller
         | 
| 42 | 
            +
                    controller_class_name.split("::")
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  def is_group_controller?
         | 
| 46 | 
            +
                    split_controller.size > 1
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  def cutted_last_namespace
         | 
| 50 | 
            +
                    split_controller.size - 2
         | 
| 51 | 
            +
                  end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                  def controller_dir
         | 
| 54 | 
            +
                    if is_group_controller?
         | 
| 55 | 
            +
                      dir = split_controller[0..cutted_last_namespace].join("/").downcase
         | 
| 56 | 
            +
                      return dir
         | 
| 57 | 
            +
                    end
         | 
| 58 | 
            +
                  end
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
            end
         | 
| @@ -0,0 +1,67 @@ | |
| 1 | 
            +
            class <%= controller_class_name %>Controller < Atozfunc::AtozController
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              def index
         | 
| 4 | 
            +
                @<%=plural_name %> = <%= singular_name.camelize %>.all
         | 
| 5 | 
            +
                if @<%= plural_name %>.present?
         | 
| 6 | 
            +
                  render_response("success", { messages: ['success'], code: 200, data: @<%= plural_name %> })
         | 
| 7 | 
            +
                else
         | 
| 8 | 
            +
                  render_response("warning", { messages: ['data not available'], code: 402, data: @<%= plural_name %> })
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              def show
         | 
| 13 | 
            +
                @<%=singular_name %> = <%= singular_name.camelize %>.find(params[:id])
         | 
| 14 | 
            +
                if @<%= plural_name %>.present?
         | 
| 15 | 
            +
                  render_response("success", { messages: ['success'], code: 200, data: @<%= singular_name %> })
         | 
| 16 | 
            +
                else
         | 
| 17 | 
            +
                  render_response("warning", { messages: ['data not available'], code: 402, data: @<%= singular_name %> })
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              def new
         | 
| 22 | 
            +
                @<%=singular_name %> = <%= singular_name.camelize %>.new
         | 
| 23 | 
            +
                render_response("success", { messages: ['success'], code: 200, data: @<%= singular_name %> })
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              def create
         | 
| 27 | 
            +
                @<%=singular_name %> = <%= singular_name.camelize %>.new(<%= singular_name %>_params)
         | 
| 28 | 
            +
                if @<%= plural_name %>.save
         | 
| 29 | 
            +
                  render_response("success", { messages: ['success'], code: 200, data: @<%= singular_name %> })
         | 
| 30 | 
            +
                else
         | 
| 31 | 
            +
                  render_response("warning", { messages: @<%=singular_name %>.errors.full_messages, code: 402, data: @<%= singular_name %> })
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
              def edit
         | 
| 36 | 
            +
                @<%=singular_name %> = <%= singular_name.camelize %>.find(params[:id])
         | 
| 37 | 
            +
                if @<%= plural_name %>.present?
         | 
| 38 | 
            +
                  render_response("success", { messages: ['success'], code: 200, data: @<%= singular_name %> })
         | 
| 39 | 
            +
                else
         | 
| 40 | 
            +
                  render_response("warning", { messages: ['data not available'], code: 402, data: @<%= singular_name %> })
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              def update
         | 
| 45 | 
            +
                @<%=singular_name %> = <%= singular_name.camelize %>.update(<%= singular_name %>_params)
         | 
| 46 | 
            +
                if  @<%=singular_name %>.errors.blank?
         | 
| 47 | 
            +
                  render_response("success", { messages: ['success'], code: 200, data: @<%= singular_name %> })
         | 
| 48 | 
            +
                else
         | 
| 49 | 
            +
                  render_response("warning", { messages: @<%=singular_name %>.errors.full_messages, code: 402, data: @<%= singular_name %> })
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
              def destroy
         | 
| 54 | 
            +
                @<%=singular_name %> = <%= singular_name.camelize %>.find(params[:id])
         | 
| 55 | 
            +
                if  @<%=singular_name %>.destroy
         | 
| 56 | 
            +
                  render_response("success", { messages: ['success'], code: 200, data: @<%= singular_name %> })
         | 
| 57 | 
            +
                else
         | 
| 58 | 
            +
                  render_response("warning", { messages: @<%=singular_name %>.errors.full_messages, code: 402, data: @<%= singular_name %> })
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
              private
         | 
| 63 | 
            +
             | 
| 64 | 
            +
              def <%= singular_name %>_params
         | 
| 65 | 
            +
                params.require(:<%= singular_name %>).permit(<%= editable_attributes %>)
         | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,84 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: atozfunc
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.1
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Gilang Ramadan
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: exe
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2019-02-15 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: bundler
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '1.16'
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '1.16'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: rake
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '10.0'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '10.0'
         | 
| 41 | 
            +
            description: THIS GEM FOR ATOZ APPLICATION FUNCTION
         | 
| 42 | 
            +
            email:
         | 
| 43 | 
            +
            - mgrware@gmail.com
         | 
| 44 | 
            +
            executables: []
         | 
| 45 | 
            +
            extensions: []
         | 
| 46 | 
            +
            extra_rdoc_files: []
         | 
| 47 | 
            +
            files:
         | 
| 48 | 
            +
            - app/controllers/atoz_controller.rb
         | 
| 49 | 
            +
            - lib/atozfunc.rb
         | 
| 50 | 
            +
            - lib/atozfunc/controllers/atoz_controller.rb
         | 
| 51 | 
            +
            - lib/atozfunc/engine.rb
         | 
| 52 | 
            +
            - lib/atozfunc/general.rb
         | 
| 53 | 
            +
            - lib/atozfunc/version.rb
         | 
| 54 | 
            +
            - lib/generators/atozfunc/controller_generator.rb
         | 
| 55 | 
            +
            - lib/generators/atozfunc/generator_helpers.rb
         | 
| 56 | 
            +
            - lib/generators/atozfunc/templates/controller.rb
         | 
| 57 | 
            +
            homepage: http://mgrdev.com
         | 
| 58 | 
            +
            licenses: []
         | 
| 59 | 
            +
            metadata:
         | 
| 60 | 
            +
              allowed_push_host: https://rubygems.org
         | 
| 61 | 
            +
              homepage_uri: http://mgrdev.com
         | 
| 62 | 
            +
              source_code_uri: https://github.com/mgrware/atozfunc
         | 
| 63 | 
            +
              changelog_uri: https://github.com/mgrware/atozfunc/change.md
         | 
| 64 | 
            +
            post_install_message: 
         | 
| 65 | 
            +
            rdoc_options: []
         | 
| 66 | 
            +
            require_paths:
         | 
| 67 | 
            +
            - lib
         | 
| 68 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 69 | 
            +
              requirements:
         | 
| 70 | 
            +
              - - ">="
         | 
| 71 | 
            +
                - !ruby/object:Gem::Version
         | 
| 72 | 
            +
                  version: '0'
         | 
| 73 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 74 | 
            +
              requirements:
         | 
| 75 | 
            +
              - - ">="
         | 
| 76 | 
            +
                - !ruby/object:Gem::Version
         | 
| 77 | 
            +
                  version: '0'
         | 
| 78 | 
            +
            requirements: []
         | 
| 79 | 
            +
            rubyforge_project: 
         | 
| 80 | 
            +
            rubygems_version: 2.7.7
         | 
| 81 | 
            +
            signing_key: 
         | 
| 82 | 
            +
            specification_version: 4
         | 
| 83 | 
            +
            summary: THIS GEM FOR ATOZ APPLICATION FUNCTION
         | 
| 84 | 
            +
            test_files: []
         |