Class: Gris::Generators::ApiGenerator

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/gris/generators/api_generator.rb

Instance Method Summary collapse

Instance Method Details

#apiObject



48
49
50
51
52
53
# File 'lib/gris/generators/api_generator.rb', line 48

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


39
40
41
42
43
44
45
46
# File 'lib/gris/generators/api_generator.rb', line 39

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

#append_endpoint_to_application_endpointObject



31
32
33
34
35
36
37
# File 'lib/gris/generators/api_generator.rb', line 31

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_tableizeObject



15
16
17
# File 'lib/gris/generators/api_generator.rb', line 15

def name_tableize
  name.tableize
end

#name_underscoreObject



11
12
13
# File 'lib/gris/generators/api_generator.rb', line 11

def name_underscore
  name.underscore
end

#output_directoryObject



19
20
21
# File 'lib/gris/generators/api_generator.rb', line 19

def output_directory
  '.'
end

#path_to_application_endpointObject



23
24
25
# File 'lib/gris/generators/api_generator.rb', line 23

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

#path_to_root_presenterObject



27
28
29
# File 'lib/gris/generators/api_generator.rb', line 27

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