Class: Configuration::FileStore

Inherits:
FileSourceStoreBase show all
Includes:
ClassLogging
Defined in:
lib/httpimagestore/configuration/file.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FileSourceStoreBase

#file_url, #initialize, #storage_path, #to_s

Methods inherited from SourceStoreBase

#initialize

Methods inherited from Scope

#initialize, node_parsers, #parse, register_node_parser

Constructor Details

This class inherits a constructor from Configuration::FileSourceStoreBase

Class Method Details

.match(node) ⇒ Object



115
116
117
# File 'lib/httpimagestore/configuration/file.rb', line 115

def self.match(node)
  node.name == 'store_file'
end

.parse(configuration, node) ⇒ Object



119
120
121
# File 'lib/httpimagestore/configuration/file.rb', line 119

def self.parse(configuration, node)
  configuration.stores << super
end

Instance Method Details

#realize(request_state) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/httpimagestore/configuration/file.rb', line 123

def realize(request_state)
  get_named_image_for_storage(request_state) do |image_name, image, rendered_path|
    storage_path = storage_path(rendered_path)

    image.store_url = file_url(rendered_path)

    log.info "storing '#{image_name}' in file '#{storage_path}' (#{image.data.length} bytes)"
    measure "storing image in file", image_name do
      storage_path.open('wb'){|io| io.write image.data}
    end
    FileSourceStoreBase.stats.incr_total_file_store
    FileSourceStoreBase.stats.incr_total_file_store_bytes(image.data.bytesize)
  end
end