Skip to content

Shinya131/seed_sort_toolkit

Repository files navigation

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"

About

rails seed file sort tool.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages