* Fastly refactor - Create FastlyConfig - Create FastlyConfig::Base - Create FastlyConfig::Snippets - Move safe_params to its own VCL file - Rescue unauthorized errors in development - Add FastlyConfig errors * Move active version to method * Update naming option --> config * Refactor InvalidConfigsFormat msg to Error class * Refactor active version logic * Fix log_to_datadog call * Move get_active_version logic back into method * Add some specs ¯\_(ツ)_/¯ * Update Fastly rake task * Remove old Fastly way * Update docs for Fastly * Move snippets to config/ & remove old config * Change update_config to upsert_config * Change error type to SubclassResponsibility * Refactor get_updated_files with filter_map * Refactor update * Cleanup update_config --> upsert_config * Fix updater specs
33 lines
855 B
Ruby
33 lines
855 B
Ruby
module FastlyConfig
|
|
class Base
|
|
attr_reader :fastly, :active_version, :updated_files
|
|
|
|
def initialize(fastly, active_version)
|
|
@fastly = fastly
|
|
@active_version = active_version
|
|
@updated_files = get_updated_files
|
|
end
|
|
|
|
def update_needed?
|
|
updated_files.present?
|
|
end
|
|
|
|
def update(new_version)
|
|
updated_files.each { |filename| upsert_config(new_version, filename) }
|
|
end
|
|
|
|
private
|
|
|
|
def get_updated_files(files: self.class::FASTLY_FILES)
|
|
Dir.glob(files).filter_map { |filename| filename if file_updated?(filename) }
|
|
end
|
|
|
|
def file_updated?
|
|
raise SubclassResponsibility, "Fastly configs must implement their own file_updated? method"
|
|
end
|
|
|
|
def upsert_config
|
|
raise SubclassResponsibility, "Fastly configs must implement their own upsert_config method"
|
|
end
|
|
end
|
|
end
|