Class: Skele::Skeleton
- Inherits:
-
Object
- Object
- Skele::Skeleton
- Defined in:
- lib/skele.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#skeleton ⇒ Object
readonly
Returns the value of attribute skeleton.
-
#skeleton_dir ⇒ Object
readonly
Returns the value of attribute skeleton_dir.
Instance Method Summary collapse
- #bundle_install ⇒ Object
- #bundler_installed? ⇒ Boolean
- #copy_files ⇒ Object
-
#initialize(skeleton, destination, root = SKELETON_ROOT) ⇒ Skeleton
constructor
A new instance of Skeleton.
- #relative_path(abspath, relativeto) ⇒ Object
- #summon ⇒ Object
Constructor Details
#initialize(skeleton, destination, root = SKELETON_ROOT) ⇒ Skeleton
Returns a new instance of Skeleton.
11 12 13 14 15 16 |
# File 'lib/skele.rb', line 11 def initialize(skeleton, destination, root=SKELETON_ROOT) @skeleton = skeleton @skeleton_dir = root + @skeleton @destination = destination + File::SEPARATOR @ignore = [".git", ".hg"] end |
Instance Attribute Details
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
9 10 11 |
# File 'lib/skele.rb', line 9 def destination @destination end |
#skeleton ⇒ Object (readonly)
Returns the value of attribute skeleton.
9 10 11 |
# File 'lib/skele.rb', line 9 def skeleton @skeleton end |
#skeleton_dir ⇒ Object (readonly)
Returns the value of attribute skeleton_dir.
9 10 11 |
# File 'lib/skele.rb', line 9 def skeleton_dir @skeleton_dir end |
Instance Method Details
#bundle_install ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/skele.rb', line 83 def bundle_install if File.exists? @destination + "Gemfile" bundler_result = "" unless bundler_installed? bundler_result += "Bundler wasn't found, so we're installing it\n\n" bundler_result += `gem install bundler` bundler_result += "\n\n" end bundler_result += `bundle install` return bundler_result end return nil end |
#bundler_installed? ⇒ Boolean
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/skele.rb', line 70 def bundler_installed? # make sure bundler is installed bundler_list = `gem list bundler` bundler_list.split("\n").each do |line| if (/^bundler/i).match(line) return true end end return false end |
#copy_files ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/skele.rb', line 35 def copy_files if File.directory? @skeleton_dir result = Array.new Find.find(@skeleton_dir) do |file| relative_path = relative_path file, @skeleton_dir # skip the containing directory next if relative_path.empty? # skip .git directory next if @ignore.include? relative_path.split(File::SEPARATOR)[0] # copy files if(File.directory? file) if File.exists?(@destination + relative_path) result.push({:action => "exists", :file => relative_path}) else Dir::mkdir(@destination + relative_path) result.push({:action => "mkdir", :file => relative_path}) end else if File.exists?(@destination + relative_path) result.push({:action => "exists", :file => relative_path}) else FileUtils::copy(file, @destination + relative_path) result.push({:action => "create", :file => relative_path}) end end end end return result end |
#relative_path(abspath, relativeto) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/skele.rb', line 18 def relative_path(abspath,relativeto) path = abspath.split(File::SEPARATOR) rel = relativeto.split(File::SEPARATOR) while (path.length > 0) && (path.first == rel.first) path.shift rel.shift end path.join(File::SEPARATOR) end |
#summon ⇒ Object
30 31 32 33 |
# File 'lib/skele.rb', line 30 def summon copy_files bundle_install end |