Module: Working
- Defined in:
- lib/working.rb,
lib/working/init.rb,
lib/working/gemspec.rb,
lib/working/version.rb
Defined Under Namespace
Classes: Initializer, PlainInitializer
Constant Summary
collapse
- README_PATH =
Dir['README.{rdoc,md}'].first
- REQUIRED_FIELDS =
[
:name,
:summary,
:description,
:authors,
:email,
:version,
:github,
:deps,
]
- VERSION =
'1.0.1'
Class Method Summary
collapse
Class Method Details
.cli_plain(argv) ⇒ Object
3
4
5
6
|
# File 'lib/working/init.rb', line 3
def self.cli_plain argv
fail RAILS_TODO_APOLOGY if is_rails?
Working::PlainInitializer.new.run argv
end
|
.file_snippet(path, start_pattern, end_pattern) ⇒ Object
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/working/gemspec.rb', line 60
def file_snippet path, start_pattern, end_pattern
desired = []
in_desired_region = false
File.readlines(path).each do |e|
break if e[end_pattern]
in_desired_region = true if e[start_pattern]
desired << e if in_desired_region
end
desired.join
end
|
.file_third_line(path) ⇒ Object
74
75
76
|
# File 'lib/working/gemspec.rb', line 74
def file_third_line path
File.readlines(path)[2]
end
|
.gemspec(args) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/working/gemspec.rb', line 17
def gemspec args
validate_gem_args! args
require_version_file args[:name]
Gem::Specification.new do |gem|
[ :name, :summary, :authors, :email, :version ].each do |e|
gem.send "#{e}=", args[e]
end
gem.description = gem.summary + "\n\n" + args[:description]
gem.homepage = 'https://github.com/' + args[:github]
gem.files = git_ls_files
gem.executables = gem.files.grep(%r{^bin/}).map{|f| File.basename f}
gem.test_files = gem.files.grep %r{^(test|spec|features)}
args[:deps].each do |e|
gem.add_dependency e
end
end
end
|
.git_ls_files ⇒ Object
50
51
52
|
# File 'lib/working/gemspec.rb', line 50
def git_ls_files
`git ls-files`.split $/
end
|
.is_rails? ⇒ Boolean
8
|
# File 'lib/working/init.rb', line 8
def self.is_rails?; File.exists? 'config/environment.ru' end
|
.readme_snippet(start_pattern, end_pattern) ⇒ Object
70
71
72
|
# File 'lib/working/gemspec.rb', line 70
def readme_snippet start_pattern, end_pattern
file_snippet README_PATH, start_pattern, end_pattern
end
|
.require_version_file(name) ⇒ Object
54
55
56
57
58
|
# File 'lib/working/gemspec.rb', line 54
def require_version_file name
require name
rescue LoadError
end
|
.third_line_of_readme ⇒ Object
77
78
79
|
# File 'lib/working/gemspec.rb', line 77
def third_line_of_readme
file_third_line README_PATH
end
|
.validate_gem_args!(input) ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/working/gemspec.rb', line 39
def validate_gem_args! input
args = input.dup
missing_fields = REQUIRED_FIELDS.find_all{|e| !args.delete e}
fail <<-EOT unless args.size.zero?
Working.gem got #{args.keys.join ' and '},
but only expected #{REQUIRED_FIELDS.map(&:to_s).join ', '}
EOT
return if missing_fields.size.zero?
fail "Working.gem needs: #{missing_fields.map(&:to_s).join ', '}"
end
|