No commit activity in last 3 years
No release in over 3 years
Extension of active support classes with usefull methods
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.6
>= 11.3.0
>= 2.14
>= 2.99.4
>= 0.14.1

Runtime

 Project Readme

ActiveExt

Code Climate Test Coverage Issue Count

Usage

This project adds some new methods to the core active_record classes

To use active-ext either intall directly

gem install darthjee-active_ext

or add it to Gemfile

gem 'darthjee-active_ext'
bundle install darthjee-active_ext

methods added

ActiveRecord::Relation

ActiveRecord::Schema.define do
  self.verbose = false
  
  create_table :documents, :force => true do |t|
    t.string :status
    t.boolean :active, default: false
    t.timestamps null: true
  end
end


class Document < ActiveRecord::Base
  scope :with_error, -> { where(status: :error) }
  scope :with_success, -> { where(status: :success) }
  scope :active, -> { where(active: true) }
end

2.times { Document.with_error.create }
Document.active.with_error.create
Document.active.with_success.create

#percentage

Returns the percentage of objects of a certain scope within another scope

Document.percentage(:with_error)
0.75
Document.percentage(status: :error)
0.75
Document.percentage("status = 'error'")
0.75

Works also when using nested scopes

Document.active.percentage(:with_error)
0.5

#pluck_as_json

Just as pluck returns some specifc columns, pluck_as_json returns the same coluns with keys to identify

Document.pluck(:id, :active)
[[1, true], [2, true]]
Document.pluck_as_json(:id, :active)
[
  {id: 18, active: false},
  {id: 19, active: false},
  {id: 20, active: true},
  {id: 21, active: true}
]