Class: Flipper::Generators::SetupGenerator::InjectIntoEncryptedFile

Inherits:
Thor::Actions::InjectIntoFile
  • Object
show all
Defined in:
lib/generators/flipper/setup_generator.rb

Overview

Action to inject content into ActiveSupport::EncryptedFile

Instance Method Summary collapse

Constructor Details

#initialize(base, encrypted_file, data, config) ⇒ InjectIntoEncryptedFile

Returns a new instance of InjectIntoEncryptedFile.



44
45
46
47
# File 'lib/generators/flipper/setup_generator.rb', line 44

def initialize(base, encrypted_file, data, config)
  @encrypted_file = encrypted_file
  super(base, encrypted_file.content_path, data, config)
end

Instance Method Details

#contentObject



49
50
51
# File 'lib/generators/flipper/setup_generator.rb', line 49

def content
  @content ||= @encrypted_file.read
end

#replace!(regexp, string, force) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/generators/flipper/setup_generator.rb', line 53

def replace!(regexp, string, force)
  if force || !replacement_present?
    success = content.gsub!(regexp, string)
    @encrypted_file.write content unless pretend?
    success
  end
end