Sha256: 4ba7bf2a226ac35c615164925a5130b22be29a62a6c9e330e603e735eb1c6f66
Contents?: true
Size: 1.36 KB
Versions: 8
Compression:
Stored size: 1.36 KB
Contents
module Adva module Generators class Gemfile attr_reader :source, :target, :engines def initialize(target, options = {}) self.engines = options[:engines] @target = Pathname.new(target) @source = options[:source] || raise('no source given') # TODO [cli] should bubble up to find the current Gemfile @engines = engines end def write File.open(target, 'w+') { |f| f.write(with_engines) } end protected def engines=(engines) engines = engine_names if engines.blank? || Array(engines).include?(:all) engines.unshift(:core) unless engines.include?(:core) @engines = engines.map(&:to_sym).uniq end def with_engines lines.join.sub(adva_gem_lines.join, engine_lines.join("\n")) end def engine_lines engines.map { |engine| engine_line(engine) } end def engine_line(engine) "gem 'adva-#{engine}', :path => '#{File.expand_path("../adva-#{engine}", source)}'" end def engine_names Adva.engines.map { |engine| engine.name.demodulize.underscore.to_sym } end def adva_gem_lines @adva_gem_lines ||= lines.select { |line| line =~ /gem ("|')adva-/ } end def lines @lines ||= File.readlines(source) end end end end
Version data entries
8 entries across 8 versions & 1 rubygems