-
Notifications
You must be signed in to change notification settings - Fork 598
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
Support YARD notation #724
Changes from 7 commits
84e0f49
8857ace
bb4d4f0
32c239b
5720c4e
e3b9cfe
55ce931
cf303fd
3df1e1c
4f489b8
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 |
---|---|---|
|
@@ -267,7 +267,7 @@ def get_schema_info(klass, header, options = {}) | |
if col_type == 'decimal' | ||
col_type << "(#{col.precision}, #{col.scale})" | ||
elsif !%w[spatial geometry geography].include?(col_type) | ||
if col.limit | ||
if col.limit && !options[:format_yard] | ||
if col.limit.is_a? Array | ||
attrs << "(#{col.limit.join(', ')})" | ||
else | ||
|
@@ -306,6 +306,10 @@ def get_schema_info(klass, header, options = {}) | |
end | ||
if options[:format_rdoc] | ||
info << sprintf("# %-#{max_size}.#{max_size}s<tt>%s</tt>", "*#{col_name}*::", attrs.unshift(col_type).join(", ")).rstrip + "\n" | ||
elsif options[:format_yard] | ||
info << sprintf("# @!attribute #{col_name}") + "\n" | ||
ruby_class = col.respond_to?(:array) && col.array ? "Array<#{map_col_type_to_ruby_classes(col_type)}>": map_col_type_to_ruby_classes(col_type) | ||
info << sprintf("# @return [#{ruby_class}]") + "\n" | ||
elsif options[:format_markdown] | ||
name_remainder = max_size - col_name.length - non_ascii_length(col_name) | ||
type_remainder = (md_type_allowance - 2) - col_type.length | ||
|
@@ -894,6 +898,19 @@ def classified_sort(cols) | |
([id] << rest_cols << timestamps << associations).flatten.compact | ||
end | ||
|
||
def map_col_type_to_ruby_classes(col_type) | ||
case col_type | ||
when 'integer' then Integer.to_s | ||
when 'float' then Float.to_s | ||
when 'decimal' then BigDecimal.to_s | ||
when 'datetime', 'timestamp', 'time' then Time.to_s | ||
when 'date' then Date.to_s | ||
when 'text', 'string', 'binary', 'inet', 'uuid' then String.to_s | ||
when 'json', 'jsonb' then Hash.to_s | ||
when 'boolean' then 'Boolean' | ||
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. Does this change any current behavior? 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. Seems not. Boolean is a class that YARD understand quite well. It's better than TrueClass and FalseClass 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. If you are referring to just the boolean case, 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. Gotcha |
||
end | ||
end | ||
|
||
private | ||
|
||
def with_comments?(klass, options) | ||
|
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.
Just curious - can you elaborate why it should not be private and public instead?
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.
I don't know, my first idea was that it can be reused somewhere else but seems not yet so i'll add it in private