Class: Embryo::Filesystem

Inherits:
Object
  • Object
show all
Defined in:
lib/embryo/filesystem.rb

Instance Method Summary collapse

Constructor Details

#initialize(generator, *write_options) ⇒ Filesystem

Returns a new instance of Filesystem.



7
8
9
10
11
12
# File 'lib/embryo/filesystem.rb', line 7

def initialize(generator, *write_options)
  @generator = generator
  @write_options = write_options
  @write_cache = {}
  @gemfile = nil
end

Instance Method Details

#application_human_nameObject



49
50
51
# File 'lib/embryo/filesystem.rb', line 49

def application_human_name
  application_name.titleize
end

#application_nameObject



45
46
47
# File 'lib/embryo/filesystem.rb', line 45

def application_name
  File.basename Dir.getwd
end

#commit_changesObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/embryo/filesystem.rb', line 14

def commit_changes
  @gemfile.write(*@write_options) if @gemfile
  sorted_cache.each do |path, data|
    if data
      @generator.create_file path, data, *@write_options
    else
      @generator.remove_file path, *@write_options if File.exist? path
    end
  end
end

#delete(path) ⇒ Object



41
42
43
# File 'lib/embryo/filesystem.rb', line 41

def delete(path)
  @write_cache[path] = nil
end

#gemfileObject



33
34
35
# File 'lib/embryo/filesystem.rb', line 33

def gemfile
  @gemfile ||= Gemfile.current generator: @generator
end

#require_gem(*args) ⇒ Object



29
30
31
# File 'lib/embryo/filesystem.rb', line 29

def require_gem(*args)
  gemfile.require_gem(*args)
end

#sorted_cacheObject



25
26
27
# File 'lib/embryo/filesystem.rb', line 25

def sorted_cache
  @write_cache.sort.to_h
end

#write(path, data) ⇒ Object



37
38
39
# File 'lib/embryo/filesystem.rb', line 37

def write(path, data)
  @write_cache[path] = data
end