imagizer_engine 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bea81d75eb55f1c6c8d4630b21f3e4733b7e2e0
4
- data.tar.gz: a9f6c8707c77f6508ff6ddd41edf1146b379bd00
3
+ metadata.gz: 75814d493d7bd8f5ca2cc0b071397d78c4e0795e
4
+ data.tar.gz: 5df620e7a39ef3b2bd32aa7becbae89798bbd159
5
5
  SHA512:
6
- metadata.gz: 199b68b5155afc24bccedf6946dbb633087e712f558816aded39c518dde6754f026e43e9472dfb4c07c2dbc1053c610baca7985085d1788232f86ad553c94775
7
- data.tar.gz: ac348eaae2b2ff17f1ed064226052e81cbcd71bf88c1c8906a27a54758ca7a2eaa7ad65dbc94a5507cc6c640526e52019e7eb8c3dfaf3a481d51a4734dd6a95e
6
+ metadata.gz: 52ce25853aab820d8f59b09902cdcfc9f634d4a3514ae6a4de25f7eebd6f628ddbf815a49ec04c30906fb0c765bdc5716c148b44333b71952afe1ca75d2e7662
7
+ data.tar.gz: ecbd83c5095fa1f396729ada0992710d9ec4255d2e498600286a20b60d0b24bd06307dd4b62dfdd038e3d428b9d1bd6a2e1aeba54c18c34fb957fe0d5c1d0802
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ console
data/README.md CHANGED
@@ -52,25 +52,24 @@ end
52
52
 
53
53
  ## Usage
54
54
 
55
- 1. In the class associated with the image invoke `mount_engine' method
55
+ 1. In the class that has the original image url, invoke `mount_imagizer_engine' method. This method takes two parameters: the image name and the method to be called to get the original url of the image.
56
56
 
57
- This method takes a single parameter that defines an image prefix
58
-
59
- ```
57
+ ```ruby
60
58
  class User
61
-
62
- mount_engine :profile_image
63
-
59
+ extend ImagizerEngine::Mount #this line is not necessary if you're using Rails with ActiveRecord
60
+ mount_imagizer_engine :profile_image, :original_url_method_name
61
+
64
62
  end
65
63
  ```
66
64
 
67
- 2. With the `profile_image` prefix you will need to define a `profile_image_original_url` method in your class. This method should define the original url of the image.
68
- ```
65
+ 2. Since we passed `original_url_method_name` as the method which contains the full image url, we should define it somehow. It can be a column if using on Rails/ActiveRecord for instance, or simply define:
66
+ ```ruby
69
67
  class User
70
68
 
71
- def profile_image_original_url
72
- "path/to/file"
69
+ def original_url_method_name
70
+ "http://s3aws.address/my_original_image.png"
73
71
  end
72
+ end
74
73
  ```
75
74
 
76
75
  3. To use the Imagizer Engine use the `profile_image_url()` method. This also takes an optional parameter that could be one of the versions defined in the config file
@@ -21,5 +21,9 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 1.7"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "pg"
24
26
  spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "rails", ">= 4.0.0"
28
+
25
29
  end
@@ -51,5 +51,18 @@ module ImagizerEngine
51
51
 
52
52
  end
53
53
 
54
- require "imagizer_engine/url"
54
+ if defined?(Rails)
55
55
 
56
+ module ImagizerEngine
57
+ class Railtie < Rails::Railtie
58
+
59
+ initializer "imagizer_engine.active_record" do
60
+ ActiveSupport.on_load :active_record do
61
+ require 'imagizer_engine/orm/activerecord'
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ require "imagizer_engine/url"
@@ -1,22 +1,12 @@
1
1
  module ImagizerEngine
2
2
  module Mount
3
- def mount_engine(column)
4
- mod = Module.new
5
- include mod
6
- mod.class_eval <<-RUBY, __FILE__, __LINE__+1
3
+ def mount_imagizer_engine(column, original_url_method)
7
4
 
8
- def #{column}_url(version=nil)
9
- raise NoMethodError, "define `#{column}_original_url' for #{self.inspect}" unless respond_to?(:#{column}_original_url)
10
- to_imagizer_url(((#{column}_original_url)), version)
11
- end
5
+ self.send(:define_method, "#{column}_url") do |version=nil|
6
+ raise NoMethodError, "there's no instance method called #{original_url_method}" unless respond_to?(original_url_method)
7
+ ImagizerEngine::Url.new.to_url(self.send(original_url_method), version)
8
+ end
12
9
 
13
- private
14
-
15
- def to_imagizer_url(url, version)
16
- Url.new.to_url(url, version)
17
- end
18
-
19
- RUBY
20
- end
10
+ end
21
11
  end
22
- end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'active_record'
2
+
3
+ module ImagizerEngine
4
+ module ActiveRecord
5
+
6
+ include ImagizerEngine::Mount
7
+
8
+
9
+ end # ActiveRecord
10
+ end # ImagizerEngine
11
+
12
+ ActiveRecord::Base.extend ImagizerEngine::ActiveRecord
@@ -1,3 +1,3 @@
1
1
  module ImagizerEngine
2
- VERSION = "0.0.2"
3
- end
2
+ VERSION = "0.0.3"
3
+ end
@@ -6,8 +6,8 @@ describe ImagizerEngine do
6
6
  @class = Class.new
7
7
  @class.send(:extend, ImagizerEngine::Mount)
8
8
 
9
- @class.mount_engine(:image)
10
- @class.mount_engine(:cover)
9
+ @class.mount_imagizer_engine(:image, :image_original_url)
10
+ @class.mount_imagizer_engine(:cover, :image_original_url)
11
11
  @instance = @class.new
12
12
  @instance.define_singleton_method(:image_original_url) do
13
13
  "path/to/file.png"
@@ -46,7 +46,9 @@ describe ImagizerEngine do
46
46
  end
47
47
 
48
48
  it "should raise error if `cover_original_url is not defined" do
49
- expect{@instance.cover_url}.to raise_error(NoMethodError)
49
+ @class.mount_imagizer_engine(:main, :undefined_method)
50
+ instance = @class.new
51
+ expect{instance.main_url}.to raise_error(NoMethodError)
50
52
  end
51
53
 
52
54
  it "should have `_url method defined" do
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'support/activerecord'
3
+
4
+ def create_table(name)
5
+ ActiveRecord::Base.connection.create_table(name, force: true) do |t|
6
+ t.column :image, :string
7
+ t.column :images, :json
8
+ t.column :textfile, :string
9
+ t.column :textfiles, :json
10
+ t.column :foo, :string
11
+ end
12
+ end
13
+
14
+ def drop_table(name)
15
+ ActiveRecord::Base.connection.drop_table(name)
16
+ end
17
+
18
+ def reset_class(class_name)
19
+ Object.send(:remove_const, class_name) rescue nil
20
+ Object.const_set(class_name, Class.new(ActiveRecord::Base))
21
+ end
22
+
23
+ describe ImagizerEngine::ActiveRecord do
24
+ before(:all) { create_table("artworks") }
25
+ after(:all) { drop_table("artworks") }
26
+
27
+ before do
28
+ reset_class("Artwork")
29
+ Artwork.class_eval do
30
+ mount_imagizer_engine :main_image, :my_original_image_url
31
+
32
+ def my_original_image_url
33
+ "path/to/file.png"
34
+ end
35
+ end
36
+ @artwork = Artwork.new
37
+ end
38
+
39
+ after do
40
+ Artwork.delete_all
41
+ end
42
+
43
+ describe("ImagizerEngine::Mount") do
44
+
45
+ it "should respond to main_image_url" do
46
+ expect(@artwork).to respond_to(:main_image_url)
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -1 +1,3 @@
1
- require 'imagizer_engine'
1
+ require 'bundler'
2
+ require 'imagizer_engine'
3
+ require 'pry'
@@ -0,0 +1,30 @@
1
+ if RUBY_ENGINE == 'jruby'
2
+ require 'activerecord-jdbcpostgresql-adapter'
3
+ else
4
+ require 'pg'
5
+ end
6
+ require 'active_record'
7
+ require 'imagizer_engine/orm/activerecord'
8
+ Bundler.require
9
+
10
+ # Change this if PG is unavailable
11
+ dbconfig = {
12
+ :adapter => 'postgresql',
13
+ :database => 'imagizer_engine_test',
14
+ :encoding => 'utf8'
15
+ }
16
+
17
+ database = dbconfig.delete(:database)
18
+
19
+ ActiveRecord::Base.establish_connection(dbconfig.merge(database: "template1"))
20
+ begin
21
+ ActiveRecord::Base.connection.create_database database
22
+ rescue ActiveRecord::StatementInvalid => e # database already exists
23
+ end
24
+ ActiveRecord::Base.establish_connection(dbconfig.merge(:database => database))
25
+
26
+ ActiveRecord::Migration.verbose = false
27
+
28
+ if ActiveRecord::VERSION::STRING >= '4.2'
29
+ ActiveRecord::Base.raise_in_transactional_callbacks = true
30
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imagizer_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - sfkaos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-30 00:00:00.000000000 Z
11
+ date: 2016-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pg
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rspec
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +80,20 @@ dependencies:
52
80
  - - ">="
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 4.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 4.0.0
55
97
  description: "Super simple ruby client to use the Imagizer Media Engine created by
56
98
  nventify. Imagizer is a real-time image processing engine on top of AMAZON aws.
57
99
  \n Install the engine using the AWS Marketplace. =You can find it at www.imagizercdn.com."
@@ -69,10 +111,13 @@ files:
69
111
  - imagizer_engine.gemspec
70
112
  - lib/imagizer_engine.rb
71
113
  - lib/imagizer_engine/mount.rb
114
+ - lib/imagizer_engine/orm/activerecord.rb
72
115
  - lib/imagizer_engine/url.rb
73
116
  - lib/imagizer_engine/version.rb
74
117
  - spec/imagizer_engine_spec.rb
118
+ - spec/orm/activerecord_spec.rb
75
119
  - spec/spec_helper.rb
120
+ - spec/support/activerecord.rb
76
121
  - tasks/rspec.rake
77
122
  homepage: ''
78
123
  licenses:
@@ -100,4 +145,6 @@ specification_version: 4
100
145
  summary: Ruby client for using the Imagizer Media Engine from nvnentify.
101
146
  test_files:
102
147
  - spec/imagizer_engine_spec.rb
148
+ - spec/orm/activerecord_spec.rb
103
149
  - spec/spec_helper.rb
150
+ - spec/support/activerecord.rb