yamljam 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ test_files/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in yamljam.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ yamljam
2
+ =======
3
+
4
+ jam your yaml
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/yamljam ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'yamljam'
4
+
5
+ if !ARGV[0] || ARGV[0] == "--help"
6
+ puts "usage: yamljam <directory>"
7
+ puts "Creates a <directory>.yml file containing the keys from all yml files found in <directory>. Does not work recursively yet!"
8
+ else
9
+ Yamljam::Concatenator.new.jam(Dir.getwd, ARGV[0])
10
+ end
@@ -0,0 +1,39 @@
1
+ module Yamljam
2
+ class Concatenator
3
+ def concatenate(input_files, output_file)
4
+ output_hashmap = merge_files(input_files)
5
+ write_output(output_hashmap, output_file)
6
+ end
7
+
8
+ def write_output(output_hashmap, output_file)
9
+ File.open(output_file, 'w') do |f|
10
+ f.puts("# Generated by Yamljam. Do not directly edit this file.")
11
+ f.write(output_hashmap.to_yaml)
12
+ end
13
+ rescue Exception => ex # if it's any solace I cringed when I wrote that
14
+ puts "hit exception when writing output file! #{ex.class} #{ex.message} #{ex.backtrace}"
15
+ raise ex
16
+ end
17
+
18
+ def merge_files(input_files)
19
+ {@namespace => input_files.map{|input_file| make_hashmap(input_file)}.reduce({}, &:merge)}
20
+ end
21
+
22
+ def make_hashmap(input_file)
23
+ base_hashmap = YAML::load_file(input_file)
24
+ end
25
+
26
+ def jam(input_directory_path = nil, namespace)
27
+ # input directory will contain #{namespace}.yml (output file, which will be blown away)
28
+ # and a directory called #{namespace}. All files in the #{namespace} directory will be
29
+ # assumed to be yaml input files if they end in .yml or .yaml, and ignored otherwise.
30
+ @namespace = namespace
31
+ input_directory_path ||= Dir.getwd
32
+ input_file_dir = File.join(input_directory_path, namespace)
33
+ Dir.chdir(input_file_dir) do
34
+ input_files = Dir.glob("*.yaml") + Dir.glob("*.yml")
35
+ concatenate(input_files, File.join("..", "#{namespace}.yml"))
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Yamljam
2
+ VERSION = "0.0.1"
3
+ end
data/lib/yamljam.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "yamljam/version"
2
+
3
+ module Yamljam
4
+ require 'yaml'
5
+
6
+ require File.join("yamljam", "concatenator")
7
+ end
data/yamljam.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "yamljam/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "yamljam"
7
+ s.version = Yamljam::VERSION
8
+ s.authors = ["Bill Abney"]
9
+ s.email = ["bill.abney@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = "Jam your yaml files"
12
+ s.description = "concatenates multiple yaml files from a subdirectory into one yaml file. Useful for splitting up and re-joining en.yml"
13
+
14
+ s.rubyforge_project = "yamljam"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ #s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.executables = 'yamljam'
20
+ s.require_paths = ["lib"]
21
+
22
+ # specify any dependencies here; for example:
23
+ # s.add_development_dependency "rspec"
24
+ # s.add_runtime_dependency "rest-client"
25
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yamljam
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bill Abney
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-11 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: concatenates multiple yaml files from a subdirectory into one yaml file.
15
+ Useful for splitting up and re-joining en.yml
16
+ email:
17
+ - bill.abney@gmail.com
18
+ executables:
19
+ - yamljam
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - .gitignore
24
+ - Gemfile
25
+ - README.md
26
+ - Rakefile
27
+ - lib/yamljam.rb
28
+ - lib/yamljam/concatenator.rb
29
+ - lib/yamljam/version.rb
30
+ - yamljam.gemspec
31
+ - bin/yamljam
32
+ homepage: ''
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project: yamljam
52
+ rubygems_version: 1.8.15
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Jam your yaml files
56
+ test_files: []