bulldog 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +4 -0
- data/VERSION +1 -1
- data/bulldog.gemspec +4 -1
- data/lib/bulldog.rb +21 -0
- data/lib/bulldog/processor/ffmpeg.rb +2 -4
- data/lib/bulldog/processor/image_magick.rb +3 -6
- data/lib/bulldog/util.rb +0 -14
- data/rails/init.rb +2 -7
- data/rails/rails.rb +47 -0
- data/spec/helpers/image_creation.rb +1 -1
- data/spec/integration/processing_image_attachments.rb +1 -1
- data/spec/spec_helper.rb +3 -1
- data/spec/unit/processor/ffmpeg_spec.rb +1 -1
- data/spec/unit/processor/image_magick_spec.rb +1 -1
- data/spec/unit/rails_spec.rb +84 -0
- metadata +4 -1
    
        data/CHANGELOG
    CHANGED
    
    
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.0. | 
| 1 | 
            +
            0.0.7
         | 
    
        data/bulldog.gemspec
    CHANGED
    
    | @@ -5,7 +5,7 @@ | |
| 5 5 |  | 
| 6 6 | 
             
            Gem::Specification.new do |s|
         | 
| 7 7 | 
             
              s.name = %q{bulldog}
         | 
| 8 | 
            -
              s.version = "0.0. | 
| 8 | 
            +
              s.version = "0.0.7"
         | 
| 9 9 |  | 
| 10 10 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 11 | 
             
              s.authors = ["George Ogata"]
         | 
| @@ -58,6 +58,7 @@ Flexible file attachments for active record. | |
| 58 58 | 
             
                 "lib/bulldog/validations.rb",
         | 
| 59 59 | 
             
                 "lib/bulldog/vector2.rb",
         | 
| 60 60 | 
             
                 "rails/init.rb",
         | 
| 61 | 
            +
                 "rails/rails.rb",
         | 
| 61 62 | 
             
                 "script/console",
         | 
| 62 63 | 
             
                 "spec/data/empty.txt",
         | 
| 63 64 | 
             
                 "spec/data/test.jpg",
         | 
| @@ -91,6 +92,7 @@ Flexible file attachments for active record. | |
| 91 92 | 
             
                 "spec/unit/processor/ffmpeg_spec.rb",
         | 
| 92 93 | 
             
                 "spec/unit/processor/image_magick_spec.rb",
         | 
| 93 94 | 
             
                 "spec/unit/processor/one_shot_spec.rb",
         | 
| 95 | 
            +
                 "spec/unit/rails_spec.rb",
         | 
| 94 96 | 
             
                 "spec/unit/reflection_spec.rb",
         | 
| 95 97 | 
             
                 "spec/unit/stream_spec.rb",
         | 
| 96 98 | 
             
                 "spec/unit/style_set_spec.rb",
         | 
| @@ -129,6 +131,7 @@ Flexible file attachments for active record. | |
| 129 131 | 
             
                 "spec/unit/processor/ffmpeg_spec.rb",
         | 
| 130 132 | 
             
                 "spec/unit/processor/image_magick_spec.rb",
         | 
| 131 133 | 
             
                 "spec/unit/processor/one_shot_spec.rb",
         | 
| 134 | 
            +
                 "spec/unit/rails_spec.rb",
         | 
| 132 135 | 
             
                 "spec/unit/reflection_spec.rb",
         | 
| 133 136 | 
             
                 "spec/unit/stream_spec.rb",
         | 
| 134 137 | 
             
                 "spec/unit/style_set_spec.rb",
         | 
    
        data/lib/bulldog.rb
    CHANGED
    
    | @@ -37,6 +37,24 @@ module Bulldog | |
| 37 37 | 
             
                #
         | 
| 38 38 | 
             
                attr_accessor :default_url_template
         | 
| 39 39 |  | 
| 40 | 
            +
                #
         | 
| 41 | 
            +
                # The path to `ffmpeg'.  Only required if you use ffmpeg
         | 
| 42 | 
            +
                # (processing videos, or retrieving video attributes).
         | 
| 43 | 
            +
                #
         | 
| 44 | 
            +
                delegate :ffmpeg_path, :ffmpeg_path=, :to => Processor::Ffmpeg
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                #
         | 
| 47 | 
            +
                # The path to `convert'.  Only required if you use convert
         | 
| 48 | 
            +
                # (processing images or pdfs).
         | 
| 49 | 
            +
                #
         | 
| 50 | 
            +
                delegate :convert_path, :convert_path=, :to => Processor::ImageMagick
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                #
         | 
| 53 | 
            +
                # The path to `identify'.  Only required if you use identify
         | 
| 54 | 
            +
                # (retrieving image attributes).
         | 
| 55 | 
            +
                #
         | 
| 56 | 
            +
                delegate :identify_path, :identify_path=, :to => Processor::ImageMagick
         | 
| 57 | 
            +
             | 
| 40 58 | 
             
                #
         | 
| 41 59 | 
             
                # Define an interpolation token.
         | 
| 42 60 | 
             
                #
         | 
| @@ -89,6 +107,9 @@ module Bulldog | |
| 89 107 | 
             
              self.logger = nil
         | 
| 90 108 | 
             
              self.default_path_template = nil
         | 
| 91 109 | 
             
              self.default_url_template = "/assets/:class/:id.:style.:extension"
         | 
| 110 | 
            +
              self.convert_path = 'convert'
         | 
| 111 | 
            +
              self.identify_path = 'identify'
         | 
| 112 | 
            +
              self.ffmpeg_path = 'ffmpeg'
         | 
| 92 113 | 
             
            end
         | 
| 93 114 |  | 
| 94 115 | 
             
            ActiveRecord::Base.send :include, Bulldog::HasAttachment
         | 
| @@ -2,11 +2,9 @@ module Bulldog | |
| 2 2 | 
             
              module Processor
         | 
| 3 3 | 
             
                class Ffmpeg < Base
         | 
| 4 4 | 
             
                  class << self
         | 
| 5 | 
            -
                    attr_accessor : | 
| 5 | 
            +
                    attr_accessor :ffmpeg_path
         | 
| 6 6 | 
             
                  end
         | 
| 7 7 |  | 
| 8 | 
            -
                  self.ffmpeg_command = Bulldog.find_in_path('ffmpeg')
         | 
| 9 | 
            -
             | 
| 10 8 | 
             
                  def initialize(*args)
         | 
| 11 9 | 
             
                    super
         | 
| 12 10 | 
             
                    @operation = nil
         | 
| @@ -155,7 +153,7 @@ module Bulldog | |
| 155 153 |  | 
| 156 154 | 
             
                  def run_ffmpeg
         | 
| 157 155 | 
             
                    @arguments.each do |style, arguments|
         | 
| 158 | 
            -
                      command = [self.class. | 
| 156 | 
            +
                      command = [self.class.ffmpeg_path]
         | 
| 159 157 | 
             
                      command << '-i' << input_file
         | 
| 160 158 | 
             
                      command.concat(arguments)
         | 
| 161 159 | 
             
                      Bulldog.run(*command) or
         | 
| @@ -4,13 +4,10 @@ module Bulldog | |
| 4 4 | 
             
              module Processor
         | 
| 5 5 | 
             
                class ImageMagick < Base
         | 
| 6 6 | 
             
                  class << self
         | 
| 7 | 
            -
                    attr_accessor : | 
| 8 | 
            -
                    attr_accessor : | 
| 7 | 
            +
                    attr_accessor :convert_path
         | 
| 8 | 
            +
                    attr_accessor :identify_path
         | 
| 9 9 | 
             
                  end
         | 
| 10 10 |  | 
| 11 | 
            -
                  self.convert_command = Bulldog.find_in_path('convert')
         | 
| 12 | 
            -
                  self.identify_command = Bulldog.find_in_path('identify')
         | 
| 13 | 
            -
             | 
| 14 11 | 
             
                  def initialize(*args)
         | 
| 15 12 | 
             
                    super
         | 
| 16 13 | 
             
                    @tree = ArgumentTree.new(styles)
         | 
| @@ -119,7 +116,7 @@ module Bulldog | |
| 119 116 | 
             
                  end
         | 
| 120 117 |  | 
| 121 118 | 
             
                  def run_convert_command
         | 
| 122 | 
            -
                    command = [self.class. | 
| 119 | 
            +
                    command = [self.class.convert_path, "#{input_file}[0]", *@tree.arguments].flatten
         | 
| 123 120 | 
             
                    output = Bulldog.run(*command) or
         | 
| 124 121 | 
             
                      record.errors.add name, "convert failed (status #$?)"
         | 
| 125 122 | 
             
                    output
         | 
    
        data/lib/bulldog/util.rb
    CHANGED
    
    | @@ -1,19 +1,5 @@ | |
| 1 1 | 
             
            module Bulldog
         | 
| 2 2 | 
             
              module Util
         | 
| 3 | 
            -
                #
         | 
| 4 | 
            -
                # Return the path of the first occurrence of +basename+ in the
         | 
| 5 | 
            -
                # current PATH, or nil if the file cannot be found.
         | 
| 6 | 
            -
                #
         | 
| 7 | 
            -
                def find_in_path(basename)
         | 
| 8 | 
            -
                  ENV['PATH'].split(/:+/).each do |dirname|
         | 
| 9 | 
            -
                    path = File.join(dirname, basename)
         | 
| 10 | 
            -
                    if File.file?(path) && File.executable?(path)
         | 
| 11 | 
            -
                      return path
         | 
| 12 | 
            -
                    end
         | 
| 13 | 
            -
                  end
         | 
| 14 | 
            -
                  nil
         | 
| 15 | 
            -
                end
         | 
| 16 | 
            -
             | 
| 17 3 | 
             
                #
         | 
| 18 4 | 
             
                # Run the given command, logging everything obsessively.
         | 
| 19 5 | 
             
                #
         | 
    
        data/rails/init.rb
    CHANGED
    
    | @@ -1,9 +1,4 @@ | |
| 1 1 | 
             
            require 'bulldog'
         | 
| 2 | 
            +
            require File.dirname(__FILE__) + '/rails'
         | 
| 2 3 |  | 
| 3 | 
            -
            Bulldog. | 
| 4 | 
            -
              self.logger = Rails.logger
         | 
| 5 | 
            -
             | 
| 6 | 
            -
              to_interpolate(:rails_root){Rails.root}
         | 
| 7 | 
            -
              to_interpolate(:rails_env){Rails.env}
         | 
| 8 | 
            -
              to_interpolate(:public_path){Rails.public_path}
         | 
| 9 | 
            -
            end
         | 
| 4 | 
            +
            Bulldog::Rails.init("#{Rails.root}/config/bulldog.yml", Rails)
         | 
    
        data/rails/rails.rb
    ADDED
    
    | @@ -0,0 +1,47 @@ | |
| 1 | 
            +
            #
         | 
| 2 | 
            +
            # Helper library for rails/init.rb.
         | 
| 3 | 
            +
            #
         | 
| 4 | 
            +
            module Bulldog
         | 
| 5 | 
            +
              module Rails
         | 
| 6 | 
            +
                class << self
         | 
| 7 | 
            +
                  def init(config_path, rails)
         | 
| 8 | 
            +
                    config = read_config(config_path, rails.env)
         | 
| 9 | 
            +
                    set_logger(config, rails.logger)
         | 
| 10 | 
            +
                    set_attribute config, :default_path_template
         | 
| 11 | 
            +
                    set_attribute config, :default_url_template
         | 
| 12 | 
            +
                    set_attribute config, :convert_path
         | 
| 13 | 
            +
                    set_attribute config, :identify_path
         | 
| 14 | 
            +
                    set_attribute config, :ffmpeg_path
         | 
| 15 | 
            +
                    define_interpolations(rails)
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  def read_config(path, environment)
         | 
| 19 | 
            +
                    File.exist?(path) or
         | 
| 20 | 
            +
                      return {}
         | 
| 21 | 
            +
                    YAML.load_file(path)[environment]
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  def set_logger(config, default_logger)
         | 
| 25 | 
            +
                    case (log_path = config['log_path'])
         | 
| 26 | 
            +
                    when false
         | 
| 27 | 
            +
                      Bulldog.logger = nil
         | 
| 28 | 
            +
                    when nil
         | 
| 29 | 
            +
                      Bulldog.logger = default_logger
         | 
| 30 | 
            +
                    else
         | 
| 31 | 
            +
                      Bulldog.logger = Logger.new(log_path)
         | 
| 32 | 
            +
                    end
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  def set_attribute(config, name)
         | 
| 36 | 
            +
                    value = config[name.to_s] and
         | 
| 37 | 
            +
                      Bulldog.send("#{name}=", value)
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  def define_interpolations(rails)
         | 
| 41 | 
            +
                    Bulldog.to_interpolate(:rails_root){rails.root}
         | 
| 42 | 
            +
                    Bulldog.to_interpolate(:rails_env){rails.env}
         | 
| 43 | 
            +
                    Bulldog.to_interpolate(:public_path){rails.public_path}
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
            end
         | 
| @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            module ImageCreation
         | 
| 2 2 | 
             
              def create_image(path, options={})
         | 
| 3 3 | 
             
                options[:size] ||= '10x10'
         | 
| 4 | 
            -
                convert = Bulldog::Processor::ImageMagick. | 
| 4 | 
            +
                convert = Bulldog::Processor::ImageMagick.convert_path
         | 
| 5 5 | 
             
                system(convert, '-geometry', "#{options[:size]}!", 'pattern:checkerboard', path)
         | 
| 6 6 | 
             
                path
         | 
| 7 7 | 
             
              end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -42,7 +42,6 @@ module SpecHelper | |
| 42 42 | 
             
                mod.use_temporary_attribute_value Bulldog, :default_path_template do
         | 
| 43 43 | 
             
                  "#{temporary_directory}/attachments/:class/:id.:style"
         | 
| 44 44 | 
             
                end
         | 
| 45 | 
            -
             | 
| 46 45 | 
             
                mod.use_temporary_attribute_value Bulldog, :logger do
         | 
| 47 46 | 
             
                  buffer = StringIO.new
         | 
| 48 47 | 
             
                  logger = Logger.new(buffer)
         | 
| @@ -51,6 +50,9 @@ module SpecHelper | |
| 51 50 | 
             
                  end
         | 
| 52 51 | 
             
                  logger
         | 
| 53 52 | 
             
                end
         | 
| 53 | 
            +
                mod.use_temporary_attribute_value Bulldog, :convert_path, 'convert'
         | 
| 54 | 
            +
                mod.use_temporary_attribute_value Bulldog, :identify_path, 'identify'
         | 
| 55 | 
            +
                mod.use_temporary_attribute_value Bulldog, :ffmpeg_path, 'ffmpeg'
         | 
| 54 56 | 
             
              end
         | 
| 55 57 |  | 
| 56 58 | 
             
              #
         | 
| @@ -0,0 +1,84 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
            require "#{ROOT}/rails/rails"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            describe Rails do
         | 
| 5 | 
            +
              describe "#init" do
         | 
| 6 | 
            +
                def config_path
         | 
| 7 | 
            +
                  "#{temporary_directory}/config.yml"
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def make_config(attributes)
         | 
| 11 | 
            +
                  config = {'ENVIRONMENT' => attributes}
         | 
| 12 | 
            +
                  open(config_path, 'w') do |file|
         | 
| 13 | 
            +
                    file.puts config.to_yaml
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def init
         | 
| 18 | 
            +
                  fake_rails = OpenStruct.new(
         | 
| 19 | 
            +
                    :env => 'ENVIRONMENT',
         | 
| 20 | 
            +
                    :logger => Logger.new('/dev/null'),
         | 
| 21 | 
            +
                    :root => 'ROOT',
         | 
| 22 | 
            +
                    :public_path => 'PUBLIC'
         | 
| 23 | 
            +
                  )
         | 
| 24 | 
            +
                  Rails.init(config_path, fake_rails)
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                it "should set the default path template from the configuration file, if present" do
         | 
| 28 | 
            +
                  make_config('default_path_template' => 'DEFAULT PATH TEMPLATE')
         | 
| 29 | 
            +
                  init
         | 
| 30 | 
            +
                  Bulldog.default_path_template.should == 'DEFAULT PATH TEMPLATE'
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                it "should set the default url template from the configuration file, if present" do
         | 
| 34 | 
            +
                  make_config('default_url_template' => 'DEFAULT URL TEMPLATE')
         | 
| 35 | 
            +
                  init
         | 
| 36 | 
            +
                  Bulldog.default_url_template.should == 'DEFAULT URL TEMPLATE'
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                it "should set the ffmpeg path from the configuration file, if present" do
         | 
| 40 | 
            +
                  make_config('ffmpeg_path' => 'FFMPEG')
         | 
| 41 | 
            +
                  init
         | 
| 42 | 
            +
                  Bulldog.ffmpeg_path.should == 'FFMPEG'
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                it "should set the convert path from the configuration file, if present" do
         | 
| 46 | 
            +
                  make_config('convert_path' => 'CONVERT')
         | 
| 47 | 
            +
                  init
         | 
| 48 | 
            +
                  Bulldog.convert_path.should == 'CONVERT'
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                it "should set the identify path from the configuration file, if present" do
         | 
| 52 | 
            +
                  make_config('identify_path' => 'IDENTIFY')
         | 
| 53 | 
            +
                  init
         | 
| 54 | 
            +
                  Bulldog.identify_path.should == 'IDENTIFY'
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                it "should not set anything if the configuration file does not exist" do
         | 
| 58 | 
            +
                  default_default_path_template = Bulldog.default_path_template
         | 
| 59 | 
            +
                  init
         | 
| 60 | 
            +
                  Bulldog.default_path_template.should == default_default_path_template
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                describe "interpolations" do
         | 
| 64 | 
            +
                  def interpolate(template)
         | 
| 65 | 
            +
                    Interpolation.interpolate(template, @thing, :photo, Style.new(:style))
         | 
| 66 | 
            +
                  end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                  it "should interpolate :rails_root as Rails.root" do
         | 
| 69 | 
            +
                    init
         | 
| 70 | 
            +
                    interpolate("a/:rails_root/b").should == "a/ROOT/b"
         | 
| 71 | 
            +
                  end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                  it "should interpolate :rails_env as Rails.env" do
         | 
| 74 | 
            +
                    init
         | 
| 75 | 
            +
                    interpolate("a/:rails_env/b").should == "a/ENVIRONMENT/b"
         | 
| 76 | 
            +
                  end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                  it "should interpolate :public_path as Rails.public_path" do
         | 
| 79 | 
            +
                    init
         | 
| 80 | 
            +
                    interpolate("a/:public_path/b").should == "a/PUBLIC/b"
         | 
| 81 | 
            +
                  end
         | 
| 82 | 
            +
                end
         | 
| 83 | 
            +
              end
         | 
| 84 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: bulldog
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.7
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - George Ogata
         | 
| @@ -94,6 +94,7 @@ files: | |
| 94 94 | 
             
            - lib/bulldog/validations.rb
         | 
| 95 95 | 
             
            - lib/bulldog/vector2.rb
         | 
| 96 96 | 
             
            - rails/init.rb
         | 
| 97 | 
            +
            - rails/rails.rb
         | 
| 97 98 | 
             
            - script/console
         | 
| 98 99 | 
             
            - spec/data/empty.txt
         | 
| 99 100 | 
             
            - spec/data/test.jpg
         | 
| @@ -127,6 +128,7 @@ files: | |
| 127 128 | 
             
            - spec/unit/processor/ffmpeg_spec.rb
         | 
| 128 129 | 
             
            - spec/unit/processor/image_magick_spec.rb
         | 
| 129 130 | 
             
            - spec/unit/processor/one_shot_spec.rb
         | 
| 131 | 
            +
            - spec/unit/rails_spec.rb
         | 
| 130 132 | 
             
            - spec/unit/reflection_spec.rb
         | 
| 131 133 | 
             
            - spec/unit/stream_spec.rb
         | 
| 132 134 | 
             
            - spec/unit/style_set_spec.rb
         | 
| @@ -187,6 +189,7 @@ test_files: | |
| 187 189 | 
             
            - spec/unit/processor/ffmpeg_spec.rb
         | 
| 188 190 | 
             
            - spec/unit/processor/image_magick_spec.rb
         | 
| 189 191 | 
             
            - spec/unit/processor/one_shot_spec.rb
         | 
| 192 | 
            +
            - spec/unit/rails_spec.rb
         | 
| 190 193 | 
             
            - spec/unit/reflection_spec.rb
         | 
| 191 194 | 
             
            - spec/unit/stream_spec.rb
         | 
| 192 195 | 
             
            - spec/unit/style_set_spec.rb
         |