Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

MirrorService needs work #9

Closed
ghost opened this issue Jul 6, 2017 · 3 comments
Closed

MirrorService needs work #9

ghost opened this issue Jul 6, 2017 · 3 comments

Comments

@ghost
Copy link

ghost commented Jul 6, 2017

There are two problems with ActiveStorage::Service::MirrorService in the current code:

  1. The generated sample config is wrong. Looking at the service code, it should be something like this instead:
mirror:
  service: Mirror
  services: [ local, amazon, google ]
  1. Even with that change, the service still doesn't work, because the services attribute gets initialized to an array of strings, when it really needs to be an array of other Services. Quick and dirty fix is to edit the initializer:
  # def initialize(services:)
  #   @services = services
  # end
  def initialize(services:)
    service_array = []
    config_file   = Pathname.new(Rails.root.join("config/storage_services.yml"))
    configs = YAML.load(ERB.new(config_file.read).result)
    services.each do |service|
      if service_configuration = configs[service.to_s].symbolize_keys
        service_name = service_configuration.delete(:service)
        service_array << ActiveStorage::Service.configure(service_name, service_configuration)
      end
    end

    @services = service_array
  end

I'm not putting in a PR at the moment because it's entirely possible the current code authors have a better fix in mind and just haven't gotten around to implementing it yet. Mostly just noting this for anyone else playing with early versions.

@dhh
Copy link
Member

dhh commented Jul 7, 2017 via email

@ghost
Copy link
Author

ghost commented Jul 7, 2017

I opted for a generic concept of services-with-children rather than special case the Mirror service. There's probably some sexy recursive way to write the code but I have trouble conceiving of a good reason to go more than one level deep so I left it unrolled.

@dhh
Copy link
Member

dhh commented Jul 8, 2017

Work happening in #16.

@dhh dhh closed this as completed Jul 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant