Sha256: 50a6a09abd3643b4115f8237fb6231f1890eda0866e19254fc5bbe8d41ce88ac
Contents?: true
Size: 1.29 KB
Versions: 2
Compression:
Stored size: 1.29 KB
Contents
module Cupper # Entity represents a Entity module Entity require 'erb' FILE = 'file' DIR = 'dir' # As default the Entity is treated as a file 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 # Create the actual file or dir in the correct place def create content(@erb_file) save end # Returns the content of the file def content(erb_file) return false if self.dir? @template = File.read("#{TEMPLATE_PATH}/#{erb_file}.erb") end def save File.open(@full_path,"a+") { |f| f.write(self.render_template) } if self.file? Dir.mkdir(@full_path) if self.dir? && !(self.exist?) end def render_template ERB.new(@template).result(binding) end # Treats entity as a file or as a dir def file? @type == FILE end def dir? @type == DIR end def exist? return File.exist?(@full_path) if self.file? return Dir.exist?(@full_path) if self.dir? end def full_path @full_path end end class Attribute attr_reader :attr end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
cupper-0.1.1 | lib/cupper/entity.rb |
cupper-0.1.0 | lib/cupper/entity.rb |