FoodTruck
Installation
Add this line to your application's Gemfile:
gem "food_truck"
And then execute:
bundle
Or install it yourself as:
gem install food_truck
Usage
From the command line
# person.yml
---
name: Human
description: This class models a person.
modules: [MilkyWay, Earth]
parent: Mammal
attrs:
- name: Name
type: String
- name: Age
description: Number of years the human has been alive.
type: Integer
read_only: true
$ food_truck person.yml
From Ruby code
require "food_truck"
data = {
name: "Human",
description: "This class models a person.",
modules: ["MilkyWay", "Earth"],
parent: "Mammal",
attrs: [
{ name: "name", type: "String" },
{ name: "age", type: "Integer" read_only: true, description: "Number of years the human has been alive." },
],
}
c = FoodTruck::Class.create(data)
c.render() #=> Returns the generated code as a string.
c.generate() #=> Writes the generated code to a given folder, or the current directory if no argument is passed.
# human.rb
module MilkyWay
module Earth
# This class models a person.
class Human < Mammal
# @return [String]
attr_accessor :name
# Number of years the human has been alive.
# @return [Integer]
attr_reader :age
end
end
end
Supported Arguments
FoodTruck::Class
Name | Type | Description |
---|---|---|
name (required) | String |
Name of the class. |
description | String |
Description of the class. [Markdown][markdown] is supported. |
body | String |
String to write into the body of the class. |
parent | String |
Name of a class to inherit from. (Ex: YourNewClass < Parent ) |
modules | Array<String> |
List of modules to declare the class inside of |
attrs | Array<FoodTruck::Attr> |
An array of Attrs. |
FoodTruck::Attr
Name | Type | Description |
---|---|---|
name (required) | String |
Name of the attribute. |
description | String |
Description of the attribute. Markdown is supported. |
type | String |
Type of the attribute. |
default | Any |
Default value for the attribute; set in it's Class's initialize function. |
read_only | Boolean |
If true , an attr_reader will be generated for the attribute instead of an attr_accessor . |
FoodTruck::Func
Name | Type | Description |
---|---|---|
name (required) | String |
Name of the function. |
description | String |
Description of the function. [Markdown][markdown] is supported. |
return_type | String |
Return type of the function. |
body | String |
String to write into the body of the function. |
modules | Array<String> |
List of modules to declare the function inside of |
params | Array<FoodTruck::Param> |
An array of Params. |
FoodTruck::Param
Name | Type | Description |
---|---|---|
name (required) | String |
Name of the param. |
description | String |
Description of the param. Markdown is supported. |
type | String |
Type of the param. |
default | Any |
Default value for the param. Set optional as true for a default nil value. |
optional | Boolean |
If true , the default value will be nil . |
keyword | Boolean |
If true , the param will be generated as a keyword argument. |
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/tcd/food_truck.
License
The gem is available as open source under the terms of the MIT License.