seed_formatter 0.3.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -1
- data/DEVELOPER_README.md +10 -0
- data/README.md +5 -38
- data/lib/seed_formatter/version.rb +1 -1
- data/lib/seed_formatter.rb +5 -19
- data/seed_formatter.gemspec +1 -2
- data/spec/lib/seed_formatter_spec.rb +8 -26
- metadata +33 -64
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm use
|
1
|
+
rvm use 1.9.3-p392@seed_formatter --create
|
data/DEVELOPER_README.md
ADDED
data/README.md
CHANGED
@@ -24,7 +24,7 @@ class Seed
|
|
24
24
|
def create_admin_user
|
25
25
|
# create an admin user here
|
26
26
|
end
|
27
|
-
end
|
27
|
+
end
|
28
28
|
end
|
29
29
|
|
30
30
|
Seed.create_categories
|
@@ -53,7 +53,7 @@ class Seed
|
|
53
53
|
message "Creating some categories"
|
54
54
|
|
55
55
|
["Sedan", "SUV", "Hatchback"].each do |category_name|
|
56
|
-
category = Category.create :name => category_name
|
56
|
+
category = Category.create :name => category_name
|
57
57
|
if category.valid?
|
58
58
|
success "Created #{category_name}"
|
59
59
|
else
|
@@ -71,9 +71,9 @@ end
|
|
71
71
|
|
72
72
|
You can override the display of output with the following options:
|
73
73
|
|
74
|
-
- `:prefix` Pass in a string to prefix the output.
|
75
|
-
- `:suffix` Pass in a string to suffix the output.
|
76
|
-
- `:color` Pass in a symbol representing the color your want the ouput to be. The list of acceptable colors can be found in colored gem's [documentation](https://github.com/defunkt/colored/blob/master/lib/colored.rb).
|
74
|
+
- `:prefix` Pass in a string to prefix the output.
|
75
|
+
- `:suffix` Pass in a string to suffix the output.
|
76
|
+
- `:color` Pass in a symbol representing the color your want the ouput to be. The list of acceptable colors can be found in colored gem's [documentation](https://github.com/defunkt/colored/blob/master/lib/colored.rb).
|
77
77
|
|
78
78
|
So, there are three methods of customizing the output of SeedFormatter.
|
79
79
|
|
@@ -104,36 +104,3 @@ def my_custom_output message, options={}
|
|
104
104
|
output message, options
|
105
105
|
end
|
106
106
|
```
|
107
|
-
|
108
|
-
## Example: Parsing yaml file
|
109
|
-
|
110
|
-
SeedFormatter provides a function for parsing [YAML files](http://www.yaml.org/spec/1.2/spec.html).
|
111
|
-
|
112
|
-
The function `load_yaml_file` accepts a single argument `path` that is the path to a .yml file.
|
113
|
-
|
114
|
-
`load_yaml_file` also accepts a block that provides an argument `hash` representing the contents of each YAML structure in the .yml file.
|
115
|
-
|
116
|
-
For example, a .yml file that has a structure such as:
|
117
|
-
|
118
|
-
```YAML
|
119
|
-
-
|
120
|
-
something: "Other Thing"
|
121
|
-
ruby: "Programming Language"
|
122
|
-
readme: "Time Consuming"
|
123
|
-
```
|
124
|
-
|
125
|
-
will yield a hash as such:
|
126
|
-
|
127
|
-
```ruby
|
128
|
-
{:something => "Other Thing", :ruby => "Programming Language", :readme => "Time Consuming"}
|
129
|
-
```
|
130
|
-
|
131
|
-
As an example, if you wanted to print the contents of each structure in a .yml file you could call:
|
132
|
-
|
133
|
-
```ruby
|
134
|
-
load_yaml_file file_path do |hash|
|
135
|
-
puts hash
|
136
|
-
end
|
137
|
-
```
|
138
|
-
|
139
|
-
This will call the block passed through on each structure in the .yml file
|
data/lib/seed_formatter.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require "seed_formatter/version"
|
2
2
|
require "colored"
|
3
|
-
require "active_support/core_ext/hash/indifferent_access"
|
4
3
|
|
5
4
|
module SeedFormatter
|
6
|
-
|
5
|
+
|
7
6
|
# Outputs a message with a set of given options
|
8
7
|
#
|
9
8
|
# @param [String] message: The message to format
|
@@ -19,43 +18,30 @@ module SeedFormatter
|
|
19
18
|
options[:color] ||= :white
|
20
19
|
$stdout.puts "#{options[:prefix]}#{message}#{options[:suffix]}".send(options[:color])
|
21
20
|
end
|
22
|
-
|
21
|
+
|
23
22
|
# A preset formatter with overridable options
|
24
23
|
def message message, options = {}
|
25
24
|
options[:prefix] ||= "*** "
|
26
25
|
options[:color] ||= :white
|
27
26
|
output message, options
|
28
27
|
end
|
29
|
-
|
28
|
+
|
30
29
|
# A preset formatter with overridable options
|
31
30
|
def success message, options = {}
|
32
31
|
options[:prefix] ||= " + "
|
33
32
|
options[:color] ||= :green
|
34
33
|
output message, options
|
35
34
|
end
|
36
|
-
|
35
|
+
|
37
36
|
# A preset formatter with overridable options
|
38
37
|
def error message, options = {}
|
39
38
|
options[:prefix] ||= " - "
|
40
39
|
options[:color] ||= :red
|
41
40
|
output message, options
|
42
41
|
end
|
43
|
-
|
42
|
+
|
44
43
|
def spacer
|
45
44
|
$stdout.puts ""
|
46
45
|
end
|
47
46
|
|
48
|
-
# Allows you to run a block on each section of a .yml file.
|
49
|
-
#
|
50
|
-
# @param [String] path: The full path of the .yml file
|
51
|
-
def load_yaml_file path
|
52
|
-
begin
|
53
|
-
items = YAML::load(File.read(path))
|
54
|
-
items.each do |hash|
|
55
|
-
yield(hash.with_indifferent_access)
|
56
|
-
end
|
57
|
-
rescue
|
58
|
-
error "Unable to load YAML file #{path}, exception: #{$!}"
|
59
|
-
end
|
60
|
-
end
|
61
47
|
end
|
data/seed_formatter.gemspec
CHANGED
@@ -15,7 +15,6 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib"]
|
18
|
-
|
18
|
+
|
19
19
|
s.add_dependency 'colored'
|
20
|
-
s.add_dependency 'active_support'
|
21
20
|
end
|
@@ -5,14 +5,14 @@ class TestClass
|
|
5
5
|
end
|
6
6
|
|
7
7
|
describe SeedFormatter do
|
8
|
-
|
8
|
+
|
9
9
|
let(:tc) { TestClass.new }
|
10
|
-
|
10
|
+
|
11
11
|
describe '#output' do
|
12
12
|
subject { tc.output message, options }
|
13
13
|
let(:message) { "message" }
|
14
14
|
let(:options) { {} }
|
15
|
-
|
15
|
+
|
16
16
|
context 'options[:prefix] is provided' do
|
17
17
|
let(:options) { {:prefix => "a prefix "} }
|
18
18
|
it "prefixes the message with options[:prefix]" do
|
@@ -42,7 +42,7 @@ describe SeedFormatter do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
describe '#message' do
|
47
47
|
subject { tc.message message, options }
|
48
48
|
let(:message) { "message" }
|
@@ -76,7 +76,7 @@ describe SeedFormatter do
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
describe '#success' do
|
81
81
|
subject { tc.success message, options }
|
82
82
|
let(:message) { "message" }
|
@@ -110,7 +110,7 @@ describe SeedFormatter do
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
describe '#error' do
|
115
115
|
subject { tc.error message, options }
|
116
116
|
let(:message) { "message" }
|
@@ -144,7 +144,7 @@ describe SeedFormatter do
|
|
144
144
|
end
|
145
145
|
end
|
146
146
|
end
|
147
|
-
|
147
|
+
|
148
148
|
describe '#spacer' do
|
149
149
|
subject { tc.spacer }
|
150
150
|
it 'prints a blank line' do
|
@@ -152,23 +152,5 @@ describe SeedFormatter do
|
|
152
152
|
subject
|
153
153
|
end
|
154
154
|
end
|
155
|
-
|
156
|
-
describe '#load_yaml_file' do
|
157
|
-
context 'valid .yml file' do
|
158
|
-
it 'allows a block to process the contents of each section in the .yml file' do
|
159
|
-
tc.load_yaml_file File.join(Dir.pwd, "spec", "support", "yml", "spec.yml") do |hash|
|
160
|
-
hash["tautology"].should == "tautology"
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
context 'invalid file' do
|
165
|
-
it 'prints out an error' do
|
166
|
-
tc.should_receive(:error)
|
167
|
-
tc.load_yaml_file File.join(Dir.pwd, "spec", "support", "yml", "nothing.yml") do |hash|
|
168
|
-
# Nothing
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
155
|
+
|
174
156
|
end
|
metadata
CHANGED
@@ -1,64 +1,43 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: seed_formatter
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
- 1
|
10
|
-
version: 0.3.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Jordan Maguire
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-07-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: colored
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: active_support
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
25
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
version: "0"
|
47
|
-
type: :runtime
|
48
|
-
version_requirements: *id002
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
49
30
|
description: Easily format the output of your seeds and parse YAML files
|
50
|
-
email:
|
31
|
+
email:
|
51
32
|
- jmaguire@thefrontiergroup.com.au
|
52
33
|
executables: []
|
53
|
-
|
54
34
|
extensions: []
|
55
|
-
|
56
35
|
extra_rdoc_files: []
|
57
|
-
|
58
|
-
files:
|
36
|
+
files:
|
59
37
|
- .gitignore
|
60
38
|
- .rspec
|
61
39
|
- .rvmrc
|
40
|
+
- DEVELOPER_README.md
|
62
41
|
- Gemfile
|
63
42
|
- README.md
|
64
43
|
- Rakefile
|
@@ -68,41 +47,31 @@ files:
|
|
68
47
|
- spec/lib/seed_formatter_spec.rb
|
69
48
|
- spec/spec_helper.rb
|
70
49
|
- spec/support/yml/spec.yml
|
71
|
-
has_rdoc: true
|
72
50
|
homepage: https://github.com/jordanmaguire/seed_formatter
|
73
51
|
licenses: []
|
74
|
-
|
75
52
|
post_install_message:
|
76
53
|
rdoc_options: []
|
77
|
-
|
78
|
-
require_paths:
|
54
|
+
require_paths:
|
79
55
|
- lib
|
80
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
57
|
none: false
|
82
|
-
requirements:
|
83
|
-
- -
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
|
86
|
-
|
87
|
-
- 0
|
88
|
-
version: "0"
|
89
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
63
|
none: false
|
91
|
-
requirements:
|
92
|
-
- -
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
|
95
|
-
segments:
|
96
|
-
- 0
|
97
|
-
version: "0"
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
98
68
|
requirements: []
|
99
|
-
|
100
69
|
rubyforge_project:
|
101
|
-
rubygems_version: 1.
|
70
|
+
rubygems_version: 1.8.25
|
102
71
|
signing_key:
|
103
72
|
specification_version: 3
|
104
73
|
summary: Easily format the output of your seeds and parse YAML files
|
105
|
-
test_files:
|
74
|
+
test_files:
|
106
75
|
- spec/lib/seed_formatter_spec.rb
|
107
76
|
- spec/spec_helper.rb
|
108
77
|
- spec/support/yml/spec.yml
|