Module: ZendeskAppsSupport::Validations::Banner

Defined in:
lib/zendesk_apps_support/validations/banner.rb

Constant Summary collapse

830
200

Class Method Summary collapse

Class Method Details

.call(package) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/zendesk_apps_support/validations/banner.rb', line 12

def call(package)
  File.open(package.path_to('assets/banner.png'), 'rb') do |fh|
    begin
      image = ImageSize.new(fh)

      unless image.format == :png
        return [ValidationError.new('banner.invalid_format')]
      end

      unless (image.width == BANNER_WIDTH && image.height == BANNER_HEIGHT) ||
             (image.width == 2 * BANNER_WIDTH && image.height == 2 * BANNER_HEIGHT)
        return [ValidationError.new('banner.invalid_size', required_banner_width: BANNER_WIDTH,
                                                           required_banner_height: BANNER_HEIGHT)]
      end
    rescue
      return [ValidationError.new('banner.invalid_format')]
    end
  end
  []
end