lib/bebox/profile.rb in bebox-0.0.1 vs lib/bebox/profile.rb in bebox-0.1.0
- old
+ new
@@ -1,10 +1,11 @@
-require 'tilt'
module Bebox
class Profile
+ include Bebox::FilesHelper
+
attr_accessor :project_root, :name, :path
def initialize(name, project_root, path)
self.project_root = project_root
self.name = name
@@ -34,22 +35,16 @@
`cd #{self.project_root} && mkdir -p puppet/profiles/#{relative_path}/manifests`
end
# Generate the manifests init.pp file
def generate_manifests_file
- manifests_template = Tilt::ERBTemplate.new("#{templates_path}/puppet/profiles/manifests/init.pp.erb")
- File.open("#{absolute_path}/manifests/init.pp", 'w') do |f|
- f.write manifests_template.render(nil, :profile => self)
- end
+ generate_file_from_template("#{templates_path}/puppet/profiles/manifests/init.pp.erb", "#{absolute_path}/manifests/init.pp", {profile: self})
end
# Generate the Puppetfile
def generate_puppetfile
- puppetfile_template = Tilt::ERBTemplate.new("#{templates_path}/puppet/profiles/Puppetfile.erb")
- File.open("#{absolute_path}/Puppetfile", 'w') do |f|
- f.write puppetfile_template.render(nil)
- end
+ generate_file_from_template("#{templates_path}/puppet/profiles/Puppetfile.erb", "#{absolute_path}/Puppetfile", {})
end
# Path to the templates directory in the gem
def templates_path
File.join((File.expand_path '..', File.dirname(__FILE__)), 'templates')
@@ -63,16 +58,10 @@
# Counts existing profiles
def self.profiles_count(project_root)
Bebox::Profile.list(project_root).count
end
- # Check if the profile has a valid name
- def self.valid_name?(name)
- valid_name = (name =~ /\A[a-z][a-z0-9_]*\Z/).nil? ? false : true
- valid_name && !Bebox::RESERVED_WORDS.include?(name)
- end
-
# Check if the profile has a valid path name
def self.valid_pathname?(pathname)
#Split the name and validate each path part
pathname.split('/').each do |path_child|
valid_name = (path_child =~ /\A[a-z][a-z0-9_]*\Z/).nil? ? false : true
@@ -89,10 +78,10 @@
return valid_path.nil? ? '' : valid_path.join('/')
end
# Create the profile path relative to the project
def relative_path
- File.join("#{self.path}", "#{self.name}")
+ path.empty? ? self.name : File.join("#{self.path}", "#{self.name}")
end
# Generate the namespace name from the profile relative path
def namespace_name
relative_path.gsub('/','::')
\ No newline at end of file