Module: Pullentity::Client::Utils
- Includes:
- Thor::Actions
- Included in:
- Builder::Middleman, CLI, Generate::Auth, Generate::Exporter, Generate::Exporter, Generate::Project, Generate::Project, Generate::Theme
- Defined in:
- lib/pullentity-client/utils.rb
Class Method Summary collapse
Instance Method Summary collapse
- #base_location ⇒ Object (also: #location)
- #create_directories(*dirs) ⇒ Object
- #create_new_file(name, file = nil) ⇒ Object
- #create_with_template(name, template_location, contents = {}) ⇒ Object
- #error(msg) ⇒ Object
- #log(msg) ⇒ Object
- #remove_directories(*names) ⇒ Object
- #remove_files(*files) ⇒ Object
- #templates(path) ⇒ Object
- #touch(*filenames) ⇒ Object
- #underscore(string) ⇒ Object
Class Method Details
.source_root ⇒ Object
6 7 8 |
# File 'lib/pullentity-client/utils.rb', line 6 def self.source_root File.dirname(__FILE__) end |
Instance Method Details
#base_location ⇒ Object Also known as: location
64 65 66 |
# File 'lib/pullentity-client/utils.rb', line 64 def base_location @location ||= Pathname.new(Dir.pwd) end |
#create_directories(*dirs) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/pullentity-client/utils.rb', line 32 def create_directories(*dirs) dirs.each do |dir| log "Creating the #{dir} directory." FileUtils.mkdir_p(location.join(dir)) end end |
#create_new_file(name, file = nil) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/pullentity-client/utils.rb', line 10 def create_new_file(name, file=nil) log "Creating #{name}" contents = file.nil? ? '' : File.read(file) unless File.file?(location.join(name)) File.open(location.join(name), 'w') { |f| f.write(contents) } end end |
#create_with_template(name, template_location, contents = {}) ⇒ Object
46 47 48 49 50 |
# File 'lib/pullentity-client/utils.rb', line 46 def create_with_template(name, template_location, contents={}) template = templates("#{template_location}.erb") eruby = Erubis::Eruby.new(File.read(template)) File.open(location.join(name.gsub(/^\//, '')), 'w') { |f| f.write(eruby.result(contents))} end |
#error(msg) ⇒ Object
60 61 62 |
# File 'lib/pullentity-client/utils.rb', line 60 def error(msg) ::Pullentity::Client::Logger.error(msg) end |
#log(msg) ⇒ Object
56 57 58 |
# File 'lib/pullentity-client/utils.rb', line 56 def log(msg) ::Pullentity::Client::Logger.report(msg) end |
#remove_directories(*names) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/pullentity-client/utils.rb', line 39 def remove_directories(*names) names.each do |name| log "Removing #{name} directory." FileUtils.rm_rf(location.join(name)) end end |
#remove_files(*files) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/pullentity-client/utils.rb', line 18 def remove_files(*files) files.each do |file| log "Removing #{file} file." FileUtils.rm(location.join(file)) end end |
#templates(path) ⇒ Object
52 53 54 |
# File 'lib/pullentity-client/utils.rb', line 52 def templates(path) ::Pullentity::Client.root.join('pullentity-client/templates').join(path) end |
#touch(*filenames) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/pullentity-client/utils.rb', line 25 def touch(*filenames) filenames.each do |filename| log "Creating #{filename} file." FileUtils.touch(location.join(filename)) end end |
#underscore(string) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/pullentity-client/utils.rb', line 70 def underscore(string) string.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |