class GrapeCherry::Generators::ApiGenerator
Public Instance Methods
generate_api_base()
click to toggle source
def echo_constant
puts "Type: #{type.to_s}"
end
# File lib/generators/grape_cherry/api_generator.rb, line 17 def generate_api_base # if File.exist? 'app/controllers/api/base.rb' # # else # template 'base.rb', 'app/controllers/api/base.rb' # end end
generate_api_endpoint()
click to toggle source
# File lib/generators/grape_cherry/api_generator.rb, line 29 def generate_api_endpoint template 'resource.rb', file_path template 'helpers.rb', helpers_path end
generate_api_version()
click to toggle source
# File lib/generators/grape_cherry/api_generator.rb, line 25 def generate_api_version end
Private Instance Methods
attribute_required?(attribute)
click to toggle source
# File lib/generators/grape_cherry/api_generator.rb, line 97 def attribute_required?(attribute) type.validators_on(attribute).map(&:class).include?(ActiveRecord::Validations::PresenceValidator) end
attribute_type(attribute)
click to toggle source
# File lib/generators/grape_cherry/api_generator.rb, line 101 def attribute_type(attribute) attr_type = type.columns_hash[attribute.to_s].type if type_hash.include? attr_type type_hash[attr_type].to_s else String.to_s end end
attributes()
click to toggle source
# File lib/generators/grape_cherry/api_generator.rb, line 110 def attributes type.attribute_names.map {|attribute| attribute.downcase.to_sym } end
content_type()
click to toggle source
# File lib/generators/grape_cherry/api_generator.rb, line 43 def content_type "content_type :#{valid_format}, 'application/#{valid_format}'" end
file_path()
click to toggle source
# File lib/generators/grape_cherry/api_generator.rb, line 63 def file_path "app/controllers/api/#{version}/#{resource.underscore}.rb" end
helpers_namespace()
click to toggle source
# File lib/generators/grape_cherry/api_generator.rb, line 59 def helpers_namespace "API::#{version.upcase}::Helpers::#{resource_name.camelize}Helpers" end
helpers_path()
click to toggle source
# File lib/generators/grape_cherry/api_generator.rb, line 67 def helpers_path "app/controllers/api/#{version}/helpers/#{resource_name.underscore}_helpers.rb" end
namespace()
click to toggle source
# File lib/generators/grape_cherry/api_generator.rb, line 55 def namespace "API::#{version.upcase}::#{resource}" end
resource()
click to toggle source
# File lib/generators/grape_cherry/api_generator.rb, line 51 def resource resource_name.downcase.pluralize.camelize end
type()
click to toggle source
# File lib/generators/grape_cherry/api_generator.rb, line 79 def type if options.resource_class.present? options.resource_class.constantize else resource_name.constantize end end
type_hash()
click to toggle source
# File lib/generators/grape_cherry/api_generator.rb, line 87 def type_hash { :string => String, :decimal => BigDecimal, :integer => Integer, :datetime => DateTime, :date => Date } end
type_name()
click to toggle source
# File lib/generators/grape_cherry/api_generator.rb, line 71 def type_name if options.resource_class.present? options.resource_class.camelize else resource_name.camelize end end
valid_format()
click to toggle source
# File lib/generators/grape_cherry/api_generator.rb, line 36 def valid_format unless options.format.downcase == 'xml' or options.format.downcase == 'json' options.format = 'json' end options.format.downcase end
version()
click to toggle source
# File lib/generators/grape_cherry/api_generator.rb, line 47 def version options.api_version end