No commit activity in last 3 years
No release in over 3 years
This is rails seed file sort tool. This tool can without changing the content & format, just replace only order.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 10.0

Runtime

 Project Readme

Gem Version Build Status Coverage Status Code Climate Dependency Status

SeedSortToolkit

SeedSortToolkit is rails seed file sort tool.
This tool can without changing the content & format, just replace only order.

note:

If you use YAML.load and sort and YAML.dump.
The format of your seed, diff comes out a little.

For example:

  • Quotes("",'') for string will be disappears.
  • nil column will be blank.

This tool does not cause the above problem.

Installation

Add this line to your application's Gemfile:

gem 'seed_sort_toolkit'

And then execute:

$ bundle

Or install it yourself as:

$ gem install seed_sort_toolkit

Usage

# numbers.yml
data3:
  id: 3
  name: "three"
data1:
  id: 1
  name: "one"
data2:
  id: 2
  name: 'two'
require 'seed_sort_toolkit'

seed = File.read('numbers.yml')

sortable_seed = SeedSortToolkit::SortableSeedYaml.new(seed)
sortable_seed.sort_by{|record| record.attributes["id"] }
# =>
# data1:
#   id: 1
#   name: "one"
# data2:
#   id: 2
#   name: 'two'
# data3:
#   id: 3
#   name: "three"

# You can use space spice operand
sortable_seed.sort{|a, b| a.attributes["id"] <=> b.attributes["id"]}
# =>
# data1:
#   id: 1
#   name: "one"
# data2:
#   id: 2
#   name: 'two'
# data3:
#   id: 3
#   name: "three"