Sha256: 06103a40c6daf9ba59c37f7b2bfe237f5d001f025f0b2a71d5a8596d6c09355f
Contents?: true
Size: 1.93 KB
Versions: 5
Compression:
Stored size: 1.93 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 << " link :#{name_tableize} do |opts|\n" text << " {\n" text << ' href: "#{base_url(opts)}/' text << "#{name_tableize}{?page,size}\",\n" text << " templated: true\n" text << " }\n" text << " end\n" text << "\n" text << " link :#{name_underscore} do |opts|\n" text << " {\n" text << ' href: "#{base_url(opts)}/' text << "#{name_tableize}/{id}\",\n" text << " templated: true\n" text << " }\n" text << " end\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
5 entries across 5 versions & 1 rubygems