seed_sort_toolkit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: da0d6d591ebfafaee0790f1e9507d1532cdb8759
4
+ data.tar.gz: 23c1edb14b9c9f8bfbef92958a97414b34389ac0
5
+ SHA512:
6
+ metadata.gz: 9c89255d6e78434d092a8377ff947a462157c2163ec60632716b7a0dd4f22281d55f26452f670e4b2567c26529bf06698ec3260a88b14ca4eb4e957c18b51edb
7
+ data.tar.gz: 2ecefbde36076cf92e494b2d8ed02c145c3f34ff0a613df74f905eebc53374eacc28f91fc2dcf53fcb8617e0b47d3427f3de3693af79f014f8c40b947b813433
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm: 2.1.0
3
+ script: rake test
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in seed_sort_toolkit.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Shinya131
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ [![Build Status](https://travis-ci.org/Shinya131/seed_sort_toolkit.svg?branch=master)](https://travis-ci.org/Shinya131/seed_sort_toolkit)
2
+ [![Coverage Status](https://coveralls.io/repos/Shinya131/seed_sort_toolkit/badge.png)](https://coveralls.io/r/Shinya131/seed_sort_toolkit)
3
+ [![Code Climate](https://codeclimate.com/github/Shinya131/seed_sort_toolkit/badges/gpa.svg)](https://codeclimate.com/github/Shinya131/seed_sort_toolkit)
4
+
5
+ # SeedSortToolkit
6
+
7
+ `SeedSortToolkit` is rails seed file sort tool.
8
+ This tool can without changing the content & format, just replace only order.
9
+
10
+ note:
11
+ If you use `YAML.load` and sort and `YAML.dump`.
12
+ The format of your seed, diff comes out a little.
13
+ For example:
14
+ - Quotes for string will be disappears.
15
+ - nil column will be blank.
16
+
17
+ This tool does not cause the above problem.
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'seed_sort_toolkit'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install seed_sort_toolkit
34
+
35
+ ## Usage
36
+ ```yaml
37
+ # numbers.yml
38
+ data3:
39
+ id: 3
40
+ name: "three"
41
+ data1:
42
+ id: 1
43
+ name: "one"
44
+ data2:
45
+ id: 2
46
+ name: 'two'
47
+ ```
48
+
49
+ ```ruby
50
+ require 'seed_sort_toolkit'
51
+
52
+ seed = File.read('numbers.yml')
53
+
54
+ sortable_seed = SeedSortToolkit::SortableSeedYaml.new(seed)
55
+ sortable_seed.sort_by{|record| record.attributes["id"] }
56
+ # =>
57
+ # data1:
58
+ # id: 1
59
+ # name: "one"
60
+ # data2:
61
+ # id: 2
62
+ # name: 'two'
63
+ # data3:
64
+ # id: 3
65
+ # name: "three"
66
+
67
+ # You can use space spice operand
68
+ sortable_seed.sort{|a, b| a.attributes["id"] <=> b.attributes["id"]}
69
+ # =>
70
+ # data1:
71
+ # id: 1
72
+ # name: "one"
73
+ # data2:
74
+ # id: 2
75
+ # name: 'two'
76
+ # data3:
77
+ # id: 3
78
+ # name: "three"
79
+ ```
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ end
7
+
8
+ task :default => :test
9
+
@@ -0,0 +1,24 @@
1
+ require 'accessible_seed_yaml'
2
+
3
+ class SortableSeedYaml
4
+ def initialize(seed)
5
+ seed = AccessibleSeedYaml::Table.new(seed)
6
+ @records = seed.records
7
+ end
8
+
9
+ def sort_by(&block)
10
+ @records.sort_by!(&block)
11
+ fetch_seed
12
+ end
13
+
14
+ def sort(&block)
15
+ @records.sort!(&block)
16
+ fetch_seed
17
+ end
18
+
19
+ private
20
+
21
+ def fetch_seed
22
+ @records.map(&:original_seed).join
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module SeedSortToolkit
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "seed_sort_toolkit/version"
2
+
3
+ module SeedSortToolkit
4
+ require 'seed_sort_toolkit/sortable_seed_yaml'
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'seed_sort_toolkit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "seed_sort_toolkit"
8
+ spec.version = SeedSortToolkit::VERSION
9
+ spec.authors = ["Shinya131"]
10
+ spec.email = ["nagai3mt5b@gmail.com"]
11
+ spec.summary = "This is rails seed file sort tool. This tool can without changing the content & format, just replace only order."
12
+ spec.description = "This is rails seed file sort tool. This tool can without changing the content & format, just replace only order."
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "accessible_seed_yaml", "~> 1.0.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest"
26
+ spec.add_development_dependency "coveralls"
27
+ end
@@ -0,0 +1,7 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
5
+ require 'seed_sort_toolkit'
6
+
7
+ require 'minitest/autorun'
data/test/test_data.rb ADDED
@@ -0,0 +1,49 @@
1
+ module TestData
2
+ module Seed
3
+ Record01 =
4
+ [
5
+ "data1:\n",
6
+ " id: 1\n",
7
+ " name: \"coffee\"\n",
8
+ " category_id: 2\n"
9
+ ].join
10
+
11
+ Record02 =
12
+ [
13
+ "data2:\n",
14
+ " id: 2\n",
15
+ " name: \"tea\"\n",
16
+ " category_id: 2\n"
17
+ ].join
18
+
19
+ Record03 =
20
+ [
21
+ "data3:\n",
22
+ " id: 3\n",
23
+ " name: \"water\"\n",
24
+ " category_id: 2\n"
25
+ ].join
26
+
27
+ Record04 =
28
+ [
29
+ "data4:\n",
30
+ " id: 4\n",
31
+ " name: \"beer\"\n",
32
+ " category_id: 1\n"
33
+ ].join
34
+
35
+ Record05 =
36
+ [
37
+ "data5:\n",
38
+ " id: 5\n",
39
+ " name: \"wine\"\n",
40
+ " category_id: 1\n"
41
+ ].join
42
+
43
+ SortById = [Record01, Record02, Record03, Record04, Record05].join
44
+ SortByCategoryIdAndId = [Record04, Record05, Record01, Record02, Record03].join
45
+ SortByCategoryId_ASC_And_Id_DESC = [Record05, Record04, Record03, Record02, Record01].join
46
+
47
+ RandomOrder = [Record03, Record01, Record02, Record05, Record04].join
48
+ end
49
+ end
@@ -0,0 +1,40 @@
1
+ require 'minitest_helper'
2
+
3
+ MiniTest::Unit.autorun
4
+
5
+ class TestSortableSeedYaml < MiniTest::Unit::TestCase
6
+ def setup
7
+ @sortable_seed = SortableSeedYaml.new(TestData::Seed::RandomOrder)
8
+ end
9
+
10
+ def test_sort_by
11
+ # Case: sort by one sort key
12
+ sort_by_id = @sortable_seed.sort_by{|record| record.attributes["id"] }
13
+ assert_equal(TestData::Seed::SortById, sort_by_id)
14
+
15
+ # Case: sort by
16
+ # first sort key : category_id
17
+ # second sort key: id
18
+ sort_by_category_id_and_id =
19
+ @sortable_seed.sort_by do |record|
20
+ [ record.attributes["category_id"], record.attributes["id"] ]
21
+ end
22
+
23
+ assert_equal(TestData::Seed::SortByCategoryIdAndId, sort_by_category_id_and_id)
24
+ end
25
+
26
+ def test_sort
27
+ # Case: sort by
28
+ # first sort key : category_id -- ASC
29
+ # second sort key: id -- DES
30
+ #
31
+ # note: I don't think there is such use cases, but I made.
32
+ sort_by_category_id_asc_and_id_desc =
33
+ @sortable_seed.sort do |a, b|
34
+ first_compare = (a.attributes["category_id"] <=> b.attributes["category_id"])
35
+ first_compare.nonzero? || -(a.attributes["id"] <=> b.attributes["id"])
36
+ end
37
+
38
+ assert_equal(TestData::Seed::SortByCategoryId_ASC_And_Id_DESC, sort_by_category_id_asc_and_id_desc)
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seed_sort_toolkit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shinya131
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: accessible_seed_yaml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This is rails seed file sort tool. This tool can without changing the
84
+ content & format, just replace only order.
85
+ email:
86
+ - nagai3mt5b@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".coveralls.yml"
92
+ - ".gitignore"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/seed_sort_toolkit.rb
99
+ - lib/seed_sort_toolkit/sortable_seed_yaml.rb
100
+ - lib/seed_sort_toolkit/version.rb
101
+ - seed_sort_toolkit.gemspec
102
+ - test/minitest_helper.rb
103
+ - test/test_data.rb
104
+ - test/test_sortable_seed_yaml.rb
105
+ homepage: ''
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.2.0
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: This is rails seed file sort tool. This tool can without changing the content
129
+ & format, just replace only order.
130
+ test_files:
131
+ - test/minitest_helper.rb
132
+ - test/test_data.rb
133
+ - test/test_sortable_seed_yaml.rb
134
+ has_rdoc: