Sha256: 5017bd3a7c243cd480b3ef41e6a92c32525d0c428ad0edf5d3ebe1e4fd40da42

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

require 'thor'
require 'active_support/all'
require 'indefinite_article'

module Gris
  module Generators
    class ApiGenerator < Thor::Group
      include Thor::Actions
      argument :name

      def name_underscore
        name.underscore
      end

      def name_tableize
        name.tableize
      end

      def output_directory
        '.'
      end

      def path_to_application_endpoint
        "#{output_directory}/app/endpoints/application_endpoint.rb"
      end

      def path_to_root_presenter
        "#{output_directory}/app/presenters/root_presenter.rb"
      end

      def append_endpoint_to_application_endpoint
        say 'Mounting new endpoint on ApplicationEndpoint.'
        insert_into_file path_to_application_endpoint, after: "# Additional mounted endpoints\n" do
          text =  "  mount #{name.classify.pluralize}Endpoint\n"
          text
        end
      end

      def append_endpoint_links_to_root_presenter
        say 'Appending links to RootPresenter.'
        insert_into_file path_to_root_presenter, after: "# Additional endpoint links\n" do
          text =  "\n"
          text << "  resource_links :#{name_underscore}\n"
          text
        end
      end

      def api
        self.class.source_root "#{File.dirname(__FILE__)}/templates/api"
        say 'Generating api...'
        directory '.', output_directory
        say 'API files created!', :green
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gris-0.4.6 lib/gris/generators/api_generator.rb
gris-0.4.5 lib/gris/generators/api_generator.rb
gris-0.4.4 lib/gris/generators/api_generator.rb