resizor 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/lib/resizor/asset.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Resizor
2
- class Asset
2
+ class ResizorAsset
3
3
  attr_accessor :id, :name, :mime_type, :size, :width, :height, :path
4
4
 
5
5
  def initialize(options={})
@@ -41,7 +41,7 @@ module Resizor
41
41
  end
42
42
  end
43
43
 
44
- class AttachedAsset < Resizor::Asset
44
+ class AttachedResizorAsset < Resizor::ResizorAsset
45
45
 
46
46
  attr_accessor :attachment_name, :instance, :file
47
47
 
@@ -58,7 +58,7 @@ module Resizor
58
58
  end
59
59
 
60
60
  def assign in_file
61
- if in_file.is_a?(Resizor::Asset)
61
+ if in_file.is_a?(Resizor::ResizorAsset)
62
62
  @id = in_file.id
63
63
  @name = in_file.name
64
64
  @mime_type = in_file.mime_type
@@ -1,6 +1,6 @@
1
1
  require 'cgi'
2
2
  module Resizor
3
- class Connection
3
+ class ResizorConnection
4
4
  attr_accessor :api_host, :api_port, :api_key, :use_ssl
5
5
 
6
6
  def initialize(options={})
@@ -34,7 +34,7 @@ module Resizor
34
34
  end
35
35
 
36
36
  def api_url(force_http = false)
37
- @api_url ||= "#{(@use_ssl == true && force_http == false) ? 'https' : 'http'}://#{@api_host}:#{(@use_ssl == true && force_http == false) ? '443' : @api_port}"
37
+ "#{(@use_ssl == true && force_http == false) ? 'https' : 'http'}://#{@api_host}:#{(@use_ssl == true && force_http == false) ? '443' : @api_port}"
38
38
  end
39
39
 
40
40
  protected
@@ -13,26 +13,26 @@ module Resizor
13
13
 
14
14
  class Railtie
15
15
  def self.insert
16
- ActiveRecord::Base.send(:include, Resizor)
16
+ ActiveRecord::Base.send(:include, Resizor::Glue)
17
17
  end
18
18
  end
19
19
 
20
- class << self
21
- def included base
20
+ module Glue
21
+ def self.included base
22
22
  base.extend ClassMethods
23
23
  end
24
24
  end
25
-
25
+
26
26
  module ClassMethods
27
27
  def has_resizor_asset name, options = {}
28
28
  include InstanceMethods
29
-
29
+
30
30
  write_inheritable_attribute(:resizor_assets, {}) if resizor_assets.nil?
31
31
  resizor_assets[name] = options
32
-
32
+
33
33
  before_save :save_attached_files_for_resizor
34
34
  before_destroy :delete_attached_files_on_resizor
35
-
35
+
36
36
  define_method name do |*args|
37
37
  asset_for(name)
38
38
  end
@@ -51,19 +51,19 @@ module Resizor
51
51
  read_inheritable_attribute(:resizor_assets)
52
52
  end
53
53
  end
54
-
55
- module InstanceMethods
54
+
55
+ module InstanceMethods
56
56
  def asset_for name
57
57
  @resizor_assets ||= {}
58
- @resizor_assets[name] ||= Resizor::AttachedAsset.new(name, self, self.class.resizor_assets[name])
58
+ @resizor_assets[name] ||= Resizor::AttachedResizorAsset.new(name, self, self.class.resizor_assets[name])
59
59
  end
60
-
60
+
61
61
  def save_attached_files_for_resizor
62
62
  self.class.resizor_assets.each do |name, options|
63
63
  asset_for(name).send(:save)
64
64
  end
65
65
  end
66
-
66
+
67
67
  def delete_attached_files_on_resizor
68
68
  self.class.resizor_assets.each do |name, options|
69
69
  asset_for(name).send(:destroy)
@@ -7,11 +7,11 @@ module Resizor
7
7
  extend Forwardable
8
8
  attr_reader :connection
9
9
  def_delegators :connection, :get, :post, :delete, :api_url, :api_key, :use_ssl
10
-
10
+
11
11
  def configure
12
- yield @connection = Connection.new
12
+ yield @connection = ResizorConnection.new
13
13
  end
14
-
14
+
15
15
  def connection
16
16
  raise "Not connected. Please setup Resizor configuration first." unless @connection
17
17
  @connection
@@ -1,3 +1,3 @@
1
1
  module Resizor
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/test/asset_test.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
2
 
3
- class AssetTest < Test::Unit::TestCase
4
- context "A Asset" do
3
+ class ResizorAssetTest < Test::Unit::TestCase
4
+ context "A ResizorAsset" do
5
5
  setup do
6
6
  setup_resizor
7
- @asset = Resizor::Asset.new(:id => 10,
7
+ @asset = Resizor::ResizorAsset.new(:id => 10,
8
8
  :name => 'my_file.jpg',
9
9
  :mime_type => 'image/jpeg',
10
10
  :width => 200,