{"id":16701656,"url":"https://github.com/coryodaniel/collectively","last_synced_at":"2025-04-05T04:17:32.923Z","repository":{"id":9794564,"uuid":"11771461","full_name":"coryodaniel/collectively","owner":"coryodaniel","description":"Add methods to ActiveRecord relations and collections. ","archived":false,"fork":false,"pushed_at":"2013-07-30T22:31:59.000Z","size":148,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-11T18:56:25.374Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coryodaniel.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-30T17:51:49.000Z","updated_at":"2018-01-06T19:42:41.000Z","dependencies_parsed_at":"2022-08-29T11:11:57.543Z","dependency_job_id":null,"html_url":"https://github.com/coryodaniel/collectively","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coryodaniel%2Fcollectively","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coryodaniel%2Fcollectively/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coryodaniel%2Fcollectively/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coryodaniel%2Fcollectively/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coryodaniel","download_url":"https://codeload.github.com/coryodaniel/collectively/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284956,"owners_count":20913704,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T18:45:03.958Z","updated_at":"2025-04-05T04:17:32.894Z","avatar_url":"https://github.com/coryodaniel.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Collectively\n====================\n\nA simple gem for adding methods to ActiveRecord relations and collections. \n\nGreat for quickly adding statistical methods to subsets of results from ActiveRecord.\n\nSupport for Rails 3.2+ and 4.0+\n\nUsage\n---------------------\n\nGenerate a collection:\n\n```bash\nrails g collectively:collection posts\n```\n\nAdd some code to app/collections/posts_collection.rb:\n\n```ruby\nclass PostsCollection \u003c Collectively::Base\n  def page_views_by_day\n    collection.inject({}){|memo, post|\n      post.page_views.each do |page_view|\n        date = page_view.created_at.to_date.to_s\n        memo[date] ||= 0\n        memo[date] += 1\n      end\n      \n      memo\n    }\n  end\nend\n```\n\n\nAdd 'acts_collectively' to app/models/post.rb:\n\n```ruby\nclass Post \u003c ActiveRecord::Base\n  acts_collectively\n  # optionally override the collection name:\n  # acts_collectively as: :blogs #=\u003e BlogsCollection\n  has_many :page_views\nend\n```\n\nAccess your collection methods:\n\n```ruby\n  # Page views by day this month\n  Post.where(created_at: (Time.beginning_of_month..Time.now)).collection.page_views_by_day\n\n  # Page views since first post\n  Post.all.collection.page_views_by_day\n```\n\n\nAuthors\n---------------------\n\n  * Cory ODaniel\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoryodaniel%2Fcollectively","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoryodaniel%2Fcollectively","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoryodaniel%2Fcollectively/lists"}