Skip to content
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

Add column_names Method to ActiveHash #310

Closed
hatsu38 opened this issue Jul 3, 2024 · 0 comments · Fixed by #311
Closed

Add column_names Method to ActiveHash #310

hatsu38 opened this issue Jul 3, 2024 · 0 comments · Fixed by #311

Comments

@hatsu38
Copy link
Contributor

hatsu38 commented Jul 3, 2024

Description

I would like to propose adding a column_names method to ActiveHash, similar to the method available in ActiveRecord. The primary motivation for this addition is to facilitate the generation of CSV headers when exporting data from models that utilize ActiveHash::Base.

In ActiveRecord, the column_names method returns an array of column names as strings. The implementation is straightforward:

# Returns an array of column names as strings.
def column_names
  @column_names ||= columns.map(&:name).freeze
end

motivation

For ActiveHash, having a column_names method would be beneficial in scenarios where we need to export data to CSV, ensuring the headers are generated dynamically based on the model's columns.

Use Case:

Exporting data from ActiveHash::Base models to CSV.
Dynamically generating CSV headers based on the model's columns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant