Skip to content

Commit

Permalink
Improve doc
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Oct 20, 2024
1 parent 419008c commit 8f81253
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions lib/datagrid/column_names_attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module ClassMethods
# will always present in the grid table and won't be listed
# in column names selection
# Accepts same options as <tt>:enum</tt> filter
# @return [Datagrid::Filters::BaseFilter] Defined filter object
# @example
# column_names_filter(header: "Choose columns")
# @see Datagrid::Filters::ClassMethods#filter
Expand Down
5 changes: 2 additions & 3 deletions lib/datagrid/columns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ def data(*column_names)
self.rows(*column_names).unshift(self.header(*column_names))
end

# Return Array of Hashes where keys are column names and values are column values
# for each row in filtered datagrid relation.
# @return [Array<{Symbol => Object}>] an array of hashes representing the rows in the filtered datagrid relation
#
# @example
# class MyGrid
Expand Down Expand Up @@ -301,7 +300,7 @@ def columns(*column_names, data: false, html: false)
end

# @param column_names [Array<String, Symbol>] list of column names if you want to limit data only to specified columns
# @return columns that can be represented in plain data(non-html) way
# @return [Array<Datagrid::Columns::Column>] columns that can be represented in plain data(non-html) way
def data_columns(*column_names, **options)
self.columns(*column_names, **options, data: true)
end
Expand Down
18 changes: 9 additions & 9 deletions lib/datagrid/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def datagrid_attribute(name, &block)
end
end

# Defines a scope at class level
# @return [void]
# @return [void] Defines a scope at class level
# @example
# scope { User }
# scope { Project.where(deleted: false) }
Expand Down Expand Up @@ -123,6 +122,9 @@ def inherited(child_class)

end

# @param [{String, Symbol => Object}, nil] attributes a hash of attributes to initialize the object
# @yield [block] an optional block that is passed to the scope method for further customization
# @return [void] Initializes a new instance with optional attributes and an optional block.
def initialize(attributes = nil, &block)
super()

Expand Down Expand Up @@ -175,7 +177,7 @@ def assets
scope
end

# Returns serializable query arguments skipping all nil values
# @return [{Symbol => Object}] serializable query arguments skipping all nil values
# @example
# grid = ProductsGrid.new(category: 'dresses', available: true)
# grid.as_query # => {category: 'dresses', available: true}
Expand All @@ -187,7 +189,7 @@ def as_query
attributes
end

# @return [Hash<Symbol, Hash<Symbol, Object>>] query parameters to link this grid from a page
# @return [{ Symbol => { Symbol => Object } }] query parameters to link this grid from a page
# @example
# grid = ProductsGrid.new(category: 'dresses', available: true)
# Rails.application.routes.url_helpers.products_path(grid.query_params)
Expand All @@ -196,7 +198,7 @@ def query_params(attributes = {})
{ param_name.to_sym => as_query.merge(attributes) }
end

# Redefines scope at instance level
# @return [void] redefines scope at instance level
# @example
# class MyGrid
# scope { Article.order('created_at desc') }
Expand Down Expand Up @@ -228,8 +230,7 @@ def original_scope
scope_value.call
end

# Resets current instance scope to default scope defined in a class
# @return [void]
# @return [void] Resets current instance scope to default scope defined in a class
def reset_scope
self.scope_value = self.class.scope_value
end
Expand Down Expand Up @@ -263,8 +264,7 @@ def ==(other)
scope == other.scope
end

# Resets loaded assets and column values cache
# @return [void]
# @return [void] Resets loaded assets and column values cache
def reset
assets.reset
end
Expand Down
10 changes: 5 additions & 5 deletions lib/datagrid/filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def self.included(base)

module ClassMethods

# @return [Datagrid::Filters::Filter, nil] filter definition object by name
# @return [Datagrid::Filters::BaseFilter, nil] filter definition object by name
def filter_by_name(attribute)
if attribute.is_a?(Datagrid::Filters::BaseFilter)
unless ancestors.include?(attribute.grid_class)
Expand All @@ -68,7 +68,7 @@ def filter_by_name(attribute)
# @param [Symbol] type filter type that defines type case and GUI representation of a filter
# @param [Hash] options hash of options
# @param [Proc] block proc to apply the filter
# @return [Datagrid::Filters::Filter] Filter definition object
# @return [Datagrid::Filters::BaseFilter] Filter definition object
# @see https://github.com/bogdan/datagrid/wiki/Filters
#
# Available options:
Expand Down Expand Up @@ -120,7 +120,7 @@ def inspect
"#{super}(#{filters_inspection})"
end

# @return [Array<Datagrid::Filters::Filter>] all defined filters
# @return [Array<Datagrid::Filters::BaseFilter>] all defined filters
def filters
filters_array
end
Expand Down Expand Up @@ -170,7 +170,7 @@ def filter_value_as_string(name)
end
end

# @return [Datagrid::Filters::Filter, nil] filter object with the given name
# @return [Datagrid::Filters::BaseFilter, nil] filter object with the given name
def filter_by_name(name)
self.class.filter_by_name(name)
end
Expand All @@ -197,7 +197,7 @@ def select_values(filter)
find_select_filter(filter).select_values(self)
end

# @return [Array<Datagrid::Filters::Filter>] all currently enabled filters
# @return [Array<Datagrid::Filters::BaseFilter>] all currently enabled filters
def filters
self.class.filters.select do |filter|
filter.enabled?(self)
Expand Down
4 changes: 2 additions & 2 deletions lib/datagrid/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def datagrid_header(grid, options = {})
# * <tt>:partials</tt> - Path for partials lookup.
# Default: 'datagrid'.
#
# @return [String]
# @example
# = datagrid_rows(grid) # Generic table rows Layout
#
Expand All @@ -85,7 +86,7 @@ def datagrid_rows(grid, assets = grid.assets, **options, &block)
datagrid_renderer.rows(grid, assets, **options, &block)
end

# Renders ordering controls for the given column name
# @return [String] renders ordering controls for the given column name
#
# Supported options:
#
Expand Down Expand Up @@ -141,7 +142,6 @@ def datagrid_order_path(grid, column, descending)
datagrid_renderer.order_path(grid, column, descending, request)
end


protected

def datagrid_renderer
Expand Down
1 change: 1 addition & 0 deletions lib/datagrid/scaffold.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "rails/generators"

# @!visibility private
class Datagrid::Scaffold < Rails::Generators::NamedBase

include Rails::Generators::ResourceHelpers
Expand Down
2 changes: 1 addition & 1 deletion lib/datagrid/utils.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Datagrid
# @!visibility private
module Utils # :nodoc:
module Utils
class << self


Expand Down

0 comments on commit 8f81253

Please sign in to comment.