erb-yaml 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Rakefile +113 -0
- data/erb-yaml.gemspec +27 -0
- data/lib/erb-yaml.rb +12 -0
- data/lib/erb-yaml/version.rb +3 -0
- metadata +66 -0
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
#############################################################################
|
6
|
+
#
|
7
|
+
# Helper functions
|
8
|
+
#
|
9
|
+
#############################################################################
|
10
|
+
|
11
|
+
def name
|
12
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
13
|
+
end
|
14
|
+
|
15
|
+
def version
|
16
|
+
line = File.read("lib/#{name}/version.rb")[/^\s*VERSION\s*=\s*.*/]
|
17
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
18
|
+
end
|
19
|
+
|
20
|
+
def date
|
21
|
+
Date.today.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def rubyforge_project
|
25
|
+
name
|
26
|
+
end
|
27
|
+
|
28
|
+
def gemspec_file
|
29
|
+
"#{name}.gemspec"
|
30
|
+
end
|
31
|
+
|
32
|
+
def gem_file
|
33
|
+
"#{name}-#{version}.gem"
|
34
|
+
end
|
35
|
+
|
36
|
+
def replace_header(head, header_name)
|
37
|
+
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
|
38
|
+
end
|
39
|
+
|
40
|
+
#############################################################################
|
41
|
+
#
|
42
|
+
# Custom tasks
|
43
|
+
#
|
44
|
+
#############################################################################
|
45
|
+
|
46
|
+
|
47
|
+
#############################################################################
|
48
|
+
#
|
49
|
+
# Packaging tasks
|
50
|
+
#
|
51
|
+
#############################################################################
|
52
|
+
|
53
|
+
desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
|
54
|
+
task :release => :build do
|
55
|
+
unless `git branch` =~ /^\* master$/
|
56
|
+
puts "You must be on the master branch to release!"
|
57
|
+
exit!
|
58
|
+
end
|
59
|
+
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
60
|
+
sh "git tag v#{version}"
|
61
|
+
sh "git push origin master"
|
62
|
+
sh "git push origin v#{version}"
|
63
|
+
sh "gem push pkg/#{name}-#{version}.gem"
|
64
|
+
end
|
65
|
+
|
66
|
+
desc "Build #{gem_file} into the pkg directory"
|
67
|
+
task :build => :gemspec do
|
68
|
+
sh "mkdir -p pkg"
|
69
|
+
sh "gem build #{gemspec_file}"
|
70
|
+
sh "mv #{gem_file} pkg"
|
71
|
+
end
|
72
|
+
|
73
|
+
desc "Generate #{gemspec_file}"
|
74
|
+
task :gemspec => :validate do
|
75
|
+
# read spec file and split out manifest section
|
76
|
+
spec = File.read(gemspec_file)
|
77
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
78
|
+
|
79
|
+
# replace name version and date
|
80
|
+
replace_header(head, :name)
|
81
|
+
replace_header(head, :version)
|
82
|
+
replace_header(head, :date)
|
83
|
+
#comment this out if your rubyforge_project has a different name
|
84
|
+
#replace_header(head, :rubyforge_project)
|
85
|
+
|
86
|
+
# determine file list from git ls-files
|
87
|
+
files = `git ls-files`.
|
88
|
+
split("\n").
|
89
|
+
sort.
|
90
|
+
reject { |file| file =~ /^\./ }.
|
91
|
+
reject { |file| file =~ /^(rdoc|pkg)/ }.
|
92
|
+
map { |file| " #{file}" }.
|
93
|
+
join("\n")
|
94
|
+
|
95
|
+
# piece file back together and write
|
96
|
+
manifest = " s.files = %w[\n#{files}\n ]\n"
|
97
|
+
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
98
|
+
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
99
|
+
puts "Updated #{gemspec_file}"
|
100
|
+
end
|
101
|
+
|
102
|
+
desc "Validate #{gemspec_file}"
|
103
|
+
task :validate do
|
104
|
+
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
|
105
|
+
unless libfiles.empty?
|
106
|
+
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
|
107
|
+
exit!
|
108
|
+
end
|
109
|
+
unless Dir['VERSION*'].empty?
|
110
|
+
puts "A `VERSION` file at root level violates Gem best practices."
|
111
|
+
exit!
|
112
|
+
end
|
113
|
+
end
|
data/erb-yaml.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'erb-yaml'
|
3
|
+
s.version = '1.0.0'
|
4
|
+
s.date = '2011-09-14'
|
5
|
+
s.platform = Gem::Platform::RUBY
|
6
|
+
s.authors = ['Lee Henson', 'Guy Boertje']
|
7
|
+
s.email = ['lee.m.henson@gmail.com', 'guyboertje@gmail.com']
|
8
|
+
s.homepage = ""
|
9
|
+
s.summary = %q{}
|
10
|
+
s.description = %q{}
|
11
|
+
## Leave this section as-is. It will be automatically generated from the
|
12
|
+
## contents of your Git repository via the gemspec task. DO NOT REMOVE
|
13
|
+
## THE MANIFEST COMMENTS, they are used as delimiters by the task.
|
14
|
+
# = MANIFEST =
|
15
|
+
s.files = %w[
|
16
|
+
Gemfile
|
17
|
+
Rakefile
|
18
|
+
erb-yaml.gemspec
|
19
|
+
lib/erb-yaml.rb
|
20
|
+
lib/erb-yaml/version.rb
|
21
|
+
]
|
22
|
+
# = MANIFEST =
|
23
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
|
+
s.require_paths = ["lib"]
|
26
|
+
s.add_dependency('hash-keys', [">= 1.0.0", "< 2.0.0"])
|
27
|
+
end
|
data/lib/erb-yaml.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'hash-keys'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module ErbYaml
|
6
|
+
def self.read(path, env)
|
7
|
+
yaml = ERB.new(IO.read path).result
|
8
|
+
hash = YAML.load(yaml)[env.to_s]
|
9
|
+
raise "No content at: #{path} for key: #{env}" if hash.nil?
|
10
|
+
hash.recursive_symbolize_keys!
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: erb-yaml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lee Henson
|
9
|
+
- Guy Boertje
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-09-14 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hash-keys
|
17
|
+
requirement: &8986800 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.0
|
23
|
+
- - <
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 2.0.0
|
26
|
+
type: :runtime
|
27
|
+
prerelease: false
|
28
|
+
version_requirements: *8986800
|
29
|
+
description: ''
|
30
|
+
email:
|
31
|
+
- lee.m.henson@gmail.com
|
32
|
+
- guyboertje@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- Gemfile
|
38
|
+
- Rakefile
|
39
|
+
- erb-yaml.gemspec
|
40
|
+
- lib/erb-yaml.rb
|
41
|
+
- lib/erb-yaml/version.rb
|
42
|
+
homepage: ''
|
43
|
+
licenses: []
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.8.6
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: ''
|
66
|
+
test_files: []
|