Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ordy

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ordy

  • 1.1.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Build Status

Usage

Ordering

Model usage

class User < ApplicationRecord
  include Ordy::Orm::ActiveRecord::Orderable
  
  has_many :comments

  orderable_by do
    # order by field
    columns :name, :email
    
    # order by relations field
    associations comments: :scripts
    
    # sort by specified order
    specified(state: %w(new, pending, active, removed))
    
    # custom query
    query :custom_query do |scope, args|
      scope.where(name: 'example').order(email: args[:direction])
    end
  end
end

Code usage

# order by columns
User.order_by(name: :asc)
# or
User.order_by('name-asc')

# order by multiple columns
User.order_by(name: :asc, email: :desc) 
# or
User.order_by(name: :asc).order_by(email: :desc)

# order by association column
User.order_by(comments: :asc)

# order by specified column values
User.order_by_specified(:state)

# order by custom query
User.order_by(custom_query: :asc)

# default ordering
User.order_by('') 
# or
User.order_by(nil)

# ordering by more than one criteria
User.order_by(email: :asc, state: :desc)
View helper

Helper inclusion

# users_helper.rb 

include Ordy::Helpers::ActionView::OrderableLinkHelper

Html usage

# index.html

<%= order_link('link_title', 'ordering_filed') %>

Controller usage

class UsersController
    def index
        if params[:order_by].present? && params[:direction].present?
          @users = User.order_by(params[:order_by] => params[:direction])
        else
          @users = User.all
        end
    end
end

Run development environment

# position in gem dir
cd ordy

# build app
docker-compose build app

# run app and attach with bash 
docker-compose run app /bin/bash

Test

# install dependencies
bundle exec appraisal install

# run tests for rails 4 env 
bundle exec appraisal rails-4 rspec

# run tests for rails 5 env
bundle exec appraisal rails-5 rspec

Contributing

Bug reports and pull requests are very welcome on GitHub.

Before opening a PR, please

extend the existing specs

  • run rspec
  • run rubocop and fix your warnings
  • check if this README.md file needs adjustments

#License The gem is available as open source under the terms of the MIT License.

About

This gem is currently maintained and funded by nine.

logo of the company 'nine'

FAQs

Package last updated on 11 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc