Class: Gris::Generators::ApiGenerator
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Gris::Generators::ApiGenerator
- Includes:
- Thor::Actions
- Defined in:
- lib/gris/generators/api_generator.rb
Instance Method Summary collapse
- #api ⇒ Object
- #append_endpoint_links_to_root_presenter ⇒ Object
- #append_endpoint_to_application_endpoint ⇒ Object
- #name_tableize ⇒ Object
- #name_underscore ⇒ Object
- #output_directory ⇒ Object
- #path_to_application_endpoint ⇒ Object
- #path_to_root_presenter ⇒ Object
Instance Method Details
#api ⇒ Object
62 63 64 65 66 67 |
# File 'lib/gris/generators/api_generator.rb', line 62 def api self.class.source_root "#{File.dirname(__FILE__)}/templates/api" say 'Generating api...' directory '.', output_directory say 'API files created!', :green end |
#append_endpoint_links_to_root_presenter ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gris/generators/api_generator.rb', line 38 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 << "\n" text end end |
#append_endpoint_to_application_endpoint ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/gris/generators/api_generator.rb', line 30 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 |
#name_tableize ⇒ Object
14 15 16 |
# File 'lib/gris/generators/api_generator.rb', line 14 def name_tableize name.tableize end |
#name_underscore ⇒ Object
10 11 12 |
# File 'lib/gris/generators/api_generator.rb', line 10 def name_underscore name.underscore end |
#output_directory ⇒ Object
18 19 20 |
# File 'lib/gris/generators/api_generator.rb', line 18 def output_directory '.' end |
#path_to_application_endpoint ⇒ Object
22 23 24 |
# File 'lib/gris/generators/api_generator.rb', line 22 def path_to_application_endpoint "#{output_directory}/app/endpoints/application_endpoint.rb" end |
#path_to_root_presenter ⇒ Object
26 27 28 |
# File 'lib/gris/generators/api_generator.rb', line 26 def path_to_root_presenter "#{output_directory}/app/presenters/root_presenter.rb" end |