class Grape::ScaffoldGenerator

Public Instance Methods

attributes() click to toggle source
# File lib/generators/grape/scaffold_generator.rb, line 24
def attributes
  @raw_attributes ||= []
  raw_attributes.map do |attr|
    parts = attr.split(':')
    {
      name: parts[0],
      type: (parts[1].presence || 'string').classify,
      required: parts[2] == 'r'
    }
  end
end
attributes_names() click to toggle source
# File lib/generators/grape/scaffold_generator.rb, line 36
def attributes_names
  attributes.map { |attr| attr[:name] }
end
attributes_params() click to toggle source
# File lib/generators/grape/scaffold_generator.rb, line 40
def attributes_params
  params = attributes.map do |attr|
    line = attr[:required] ? 'requires' : 'optional'
    line += " :#{attr[:name]}"
    line += ", type: #{attr[:type]}"

    line
  end

  params.join("\n        ")
end
create_api_file() click to toggle source
# File lib/generators/grape/scaffold_generator.rb, line 9
def create_api_file
  template "api/resource_api.rb",
           "app/api/#{vendor}/#{resource}_api.rb"
end
create_base_entity_file() click to toggle source
# File lib/generators/grape/scaffold_generator.rb, line 14
def create_base_entity_file
  template "entities/base.rb",
           "app/api/#{vendor}/entities/base.rb"
end
create_resource_entity_file() click to toggle source
# File lib/generators/grape/scaffold_generator.rb, line 19
def create_resource_entity_file
  template "entities/resource.rb",
           "app/api/#{vendor}/entities/#{resource}.rb"
end