Module: Cupper::Entity
- Included in:
- CookbookFile, Recipe, Structure
- Defined in:
- lib/cupper/entity.rb
Overview
Entity represents a Entity
Constant Summary collapse
- FILE =
'file'
- DIR =
'dir'
Instance Method Summary collapse
-
#content(erb_file) ⇒ Object
Returns the content of the file.
-
#create ⇒ Object
Create the actual file or dir in the correct place.
- #dir? ⇒ Boolean
- #exist? ⇒ Boolean
-
#file? ⇒ Boolean
Treats entity as a file or as a dir.
- #full_path ⇒ Object
-
#initialize(name, dest_path, erb_file = nil, type = nil, extension = '') ⇒ Object
As default the Entity is treated as a file.
- #render_template ⇒ Object
- #save ⇒ Object
Instance Method Details
#content(erb_file) ⇒ Object
Returns the content of the file
27 28 29 30 |
# File 'lib/cupper/entity.rb', line 27 def content(erb_file) return false if self.dir? @template = File.read("#{TEMPLATE_PATH}/#{erb_file}.erb") end |
#create ⇒ Object
Create the actual file or dir in the correct place
21 22 23 24 |
# File 'lib/cupper/entity.rb', line 21 def create content(@erb_file) save end |
#exist? ⇒ Boolean
49 50 51 52 |
# File 'lib/cupper/entity.rb', line 49 def exist? return File.exist?(@full_path) if self.file? return Dir.exist?(@full_path) if self.dir? end |
#file? ⇒ Boolean
Treats entity as a file or as a dir
42 43 44 |
# File 'lib/cupper/entity.rb', line 42 def file? @type == FILE end |
#full_path ⇒ Object
54 55 56 |
# File 'lib/cupper/entity.rb', line 54 def full_path @full_path end |
#initialize(name, dest_path, erb_file = nil, type = nil, extension = '') ⇒ Object
As default the Entity is treated as a file
10 11 12 13 14 15 16 17 18 |
# File 'lib/cupper/entity.rb', line 10 def initialize(name, dest_path, erb_file = nil, type = nil, extension = '') @name = name @dest_path = dest_path @erb_file = erb_file @type = type.nil? ? FILE : type @ext = extension @full_path = "#{@dest_path}/#{@name}#{@ext}" end |
#render_template ⇒ Object
37 38 39 |
# File 'lib/cupper/entity.rb', line 37 def render_template ERB.new(@template, 0, '-').result(binding) end |
#save ⇒ Object
32 33 34 35 |
# File 'lib/cupper/entity.rb', line 32 def save File.open(@full_path,"w+") { |f| f.write(self.render_template) } if self.file? Dir.mkdir(@full_path) if self.dir? && !(self.exist?) end |