Class: Libertine::Project
- Inherits:
-
Object
- Object
- Libertine::Project
- Defined in:
- lib/libertine/project.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#scm ⇒ Object
readonly
Returns the value of attribute scm.
Instance Method Summary collapse
- #by(name, email) ⇒ Object
- #description(desc = nil) ⇒ Object
- #exclude(*globs) ⇒ Object
- #files ⇒ Object
- #gemfile ⇒ Object
- #glob(*globs) ⇒ Object
- #homepage(url = nil) ⇒ Object
- #include(*globs) ⇒ Object
-
#initialize(name, dir = nil, &block) ⇒ Project
constructor
A new instance of Project.
- #inspect ⇒ Object
- #ruby(req = nil) ⇒ Object
- #rubygems(req = nil) ⇒ Object
- #spec(&block) ⇒ Object
- #summary(summ = nil) ⇒ Object
- #tasks! ⇒ Object
Constructor Details
#initialize(name, dir = nil, &block) ⇒ Project
Returns a new instance of Project.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/libertine/project.rb', line 14 def initialize name, dir = nil, &block @authors = [] @dir = dir || "." @emails = [] @excludes = [] @homepage = "http://github.com/#{ENV['USER']}/#{name}" @includes = %w(.manifest) @name = name @ruby = ">= 1.8.7" @scm = Libertine::SCM::Git.new @dir if readme = glob("README*").first grafs = File.read(readme).delete("\r").split(/\n\n+/).reject do |t| /\A\s/ =~ t || /^[#-=]/ =~ t end @description = grafs.first.gsub /\n\s*/, " " @summary = @description.split(".\s").first + "." end instance_eval(&block) if block_given? tasks! end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
10 11 12 |
# File 'lib/libertine/project.rb', line 10 def dir @dir end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/libertine/project.rb', line 11 def name @name end |
#scm ⇒ Object (readonly)
Returns the value of attribute scm.
12 13 14 |
# File 'lib/libertine/project.rb', line 12 def scm @scm end |
Instance Method Details
#by(name, email) ⇒ Object
38 39 40 41 |
# File 'lib/libertine/project.rb', line 38 def by name, email @authors << name @emails << email end |
#description(desc = nil) ⇒ Object
43 44 45 |
# File 'lib/libertine/project.rb', line 43 def description desc = nil desc ? @description = desc : @description end |
#exclude(*globs) ⇒ Object
47 48 49 |
# File 'lib/libertine/project.rb', line 47 def exclude *globs @excludes.concat globs end |
#files ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/libertine/project.rb', line 51 def files Dir.chdir dir do scm.files.tap do |ls| includes = @includes.map { |i| Dir[i] }.flatten excludes = @excludes.map { |x| Dir[x] }.flatten ls.concat includes ls.reject! { |f| excludes.include? f } ls.uniq! ls.sort! end end end |
#gemfile ⇒ Object
66 67 68 |
# File 'lib/libertine/project.rb', line 66 def gemfile "tmp/#{spec.file_name}" end |
#glob(*globs) ⇒ Object
70 71 72 73 74 |
# File 'lib/libertine/project.rb', line 70 def glob *globs Dir.chdir dir do Dir[*globs].select { |f| files.include? f } end end |
#homepage(url = nil) ⇒ Object
76 77 78 |
# File 'lib/libertine/project.rb', line 76 def homepage url = nil url ? @homepage = url : @homepage end |
#include(*globs) ⇒ Object
80 81 82 |
# File 'lib/libertine/project.rb', line 80 def include *globs @includes.concat globs end |
#inspect ⇒ Object
84 85 86 87 |
# File 'lib/libertine/project.rb', line 84 def inspect "#<Libertine::Project:#{object_id} dir: #{dir} " + "name: #{name} version: #{version}>" end |
#ruby(req = nil) ⇒ Object
89 90 91 |
# File 'lib/libertine/project.rb', line 89 def ruby req = nil req ? @ruby = req : @ruby end |
#rubygems(req = nil) ⇒ Object
93 94 95 |
# File 'lib/libertine/project.rb', line 93 def rubygems req = nil req ? @rubygems = req : @rubygems end |
#spec(&block) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/libertine/project.rb', line 97 def spec &block @specformer = block if block_given? Gem::Specification.new do |s| s. = @authors s.description = description s.email = @emails s.executables = glob("bin/*").map { |f| File.basename f } s.files = files s.homepage = homepage s.name = name s.required_ruby_version = ruby s.rubyforge_project = name s.summary = summary s.version = scm.version if rubygems s.required_rubygems_version = rubygems end Isolate.sandbox.entries.each do |entry| if entry.environments.empty? s.add_runtime_dependency entry.name, *entry.requirement elsif entry.environments.include? "development" s.add_development_dependency entry.name, *entry.requirement end end unless name == "libertine" || s.dependencies.any? { |d| d.name == "libertine" } s.add_development_dependency "libertine", ">= #{VERSION}" end @specformer[s] if @specformer begin s.validate rescue Gem::InvalidSpecificationException => e raise Libertine::Error, "Bad gemspec: #{e.}." end end end |
#summary(summ = nil) ⇒ Object
140 141 142 |
# File 'lib/libertine/project.rb', line 140 def summary summ = nil summ ? @summary = summ : @summary end |
#tasks! ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/libertine/project.rb', line 144 def tasks! file(gemfile => files) do |t| Gem::Builder.new(spec).build mv spec.file_name, t.name end desc "Build #{gemfile}." task "gem" => gemfile desc "Show the current gemspec." task("gem:spec") { puts spec.to_ruby } desc "Show the file manifest." task "manifest" do files.join("\n").tap do |manifest| File.open(".manifest", "wb") { |f| f.write manifest } puts manifest end end if scm.releaseable? desc "Release v#{scm.version}." unless scm.released? task "release" => "gem" do scm.release sh "gem push #{gemfile}" end end end |