-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optionally add nodoc #261
Optionally add nodoc #261
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
# Adds a :nodoc: to granite methods/constants if `DISABLE_GRANTE_DOCS` ENV var is true | ||
macro noDoc(stmt) | ||
{% if env("DISABLE_GRANTE_DOCS") == "true" %} | ||
# :nodoc: | ||
{{stmt.id}} | ||
{% else %} | ||
{{stmt.id}} | ||
{% end %} | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clever. I like that the logic is centralized.
Naming isn't my forte, but is there another name that would work better here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea...i'll think of something better |
||
|
||
module Granite::Table | ||
macro included | ||
macro inherited | ||
SETTINGS = {} of Nil => Nil | ||
PRIMARY = {name: id, type: Int64, auto: true} | ||
noDoc SETTINGS = {} of Nil => Nil | ||
noDoc PRIMARY = {name: id, type: Int64, auto: true} | ||
end | ||
end | ||
|
||
|
@@ -11,7 +21,7 @@ module Granite::Table | |
macro adapter(name) | ||
@@adapter = Granite::Adapter::{{name.id.capitalize}}.new("{{name.id}}") | ||
|
||
def self.adapter | ||
noDoc def self.adapter | ||
@@adapter | ||
end | ||
end | ||
|
@@ -27,13 +37,28 @@ module Granite::Table | |
{% PRIMARY[:type] = decl.type %} | ||
end | ||
|
||
# specify the primary key column and type and comment | ||
macro primary(decl, comment) | ||
{% PRIMARY[:name] = decl.var %} | ||
{% PRIMARY[:type] = decl.type %} | ||
{% PRIMARY[:comment] = comment %} | ||
end | ||
|
||
# specify the primary key column and type and auto_increment | ||
macro primary(decl, auto) | ||
{% PRIMARY[:name] = decl.var %} | ||
{% PRIMARY[:type] = decl.type %} | ||
{% PRIMARY[:auto] = auto %} | ||
end | ||
|
||
# specify the primary key column and type and auto_increment and comment | ||
macro primary(decl, comment, auto) | ||
{% PRIMARY[:name] = decl.var %} | ||
{% PRIMARY[:type] = decl.type %} | ||
{% PRIMARY[:auto] = auto %} | ||
{% PRIMARY[:comment] = comment %} | ||
end | ||
|
||
macro __process_table | ||
{% name_space = @type.name.gsub(/::/, "_").underscore.id %} | ||
{% table_name = SETTINGS[:table_name] || name_space + "s" %} | ||
|
@@ -46,27 +71,27 @@ module Granite::Table | |
@@primary_auto = "{{primary_auto}}" | ||
@@primary_type = "{{primary_type}}" | ||
|
||
def self.table_name | ||
noDoc def self.table_name | ||
@@table_name | ||
end | ||
|
||
def self.primary_name | ||
noDoc def self.primary_name | ||
@@primary_name | ||
end | ||
|
||
def self.primary_type | ||
noDoc def self.primary_type | ||
@@primary_type | ||
end | ||
|
||
def self.primary_auto | ||
noDoc def self.primary_auto | ||
@@primary_auto | ||
end | ||
|
||
def self.quoted_table_name | ||
noDoc def self.quoted_table_name | ||
@@adapter.quote(table_name) | ||
end | ||
|
||
def self.quote(column_name) | ||
noDoc def self.quote(column_name) | ||
@@adapter.quote(column_name) | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose here is to make the docs more terse and relevant by default, right? Should this logic default to nodoc then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depends on how you look at it. Was trying to allow you to disable the docs if you wanted while retaining current behavior.
But if we are okay with having them off by default i can do that.