fakefs-rmagick 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e8b0ae9eac53c888a65c817b72207846e570f12c
4
+ data.tar.gz: 7c8aaa8934993f4aeec75d9f3510cb5406c02739
5
+ SHA512:
6
+ metadata.gz: fb7a91ae521a29e2f5aa2b62f91494b902d96a62ea1768fa5a4f958911c308689c2ad1c763b1e512cc493a28227a99f9866df6c8b7e6fb7f5ac3e9c8bf714804
7
+ data.tar.gz: 5c6546884cca70537995e203d7ad9b33f5082cc11a582309fb82ea673af31c5e3c8581563c26adfa865f5094e083117164c968a7f2b84c107ceab109d1e6a88d
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fakefs_rmagick.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Éric D.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # FakeFS/Rmagick
2
+
3
+ Allows to use [RMagick](https://rmagick.github.io/) with [FakeFS](https://github.com/fakefs/fakefs)
4
+
5
+
6
+ Warning: Both FakeFS and FakeFS break usual naming convention for gems ('fakefs' => `FakeFS`, 'rmagick' => `Magick`). I choosed to respect the naming of these gem so I had to break these conventions myself. The gem name is "fakefs-rmagick" but the corresponding module will be in `FakeFS::Magick`.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'fakefs-rmagick'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install fakefs-rmagick
23
+
24
+ ## Usage
25
+
26
+ To be able to use RMagick with FakeFS:
27
+
28
+ ```ruby
29
+ require 'fakefs'
30
+ require 'fakefs/rmagick'
31
+ ```
32
+
33
+ This will slow Magick::Image#write and a little but may also consume a lot of memory when writing large images. If you want, you may activate the override on demand with the following:
34
+
35
+ ```ruby
36
+ require 'fakefs/safe'
37
+ require 'fakefs/rmagick/safe'
38
+
39
+ FakeFS::Magick.activate!
40
+ FakeFS.activate!
41
+ # your code
42
+ FakeFS.deactivate!
43
+ FakeFS::Magick.activate!
44
+
45
+ # or (preferably)
46
+
47
+ FakeFS::Magick.with do
48
+ FakeFS.with do
49
+ # your code
50
+ end
51
+ end
52
+ ```
53
+
54
+ (the order doesn't matter, you can also start with FakeFS and then activate FakeFS::Magik)
55
+
56
+ For convenience, you can hook directly into FakeFS and let FakeFS::Magick activate itself automaticaly with FakeFS.
57
+
58
+ ```ruby
59
+ require 'fakefs/rmagick/hook'
60
+ ```
61
+
62
+ or manualy with:
63
+ ```ruby
64
+ require 'fakefs/rmagick/safe'
65
+
66
+ FakeFS::Magick.hook!
67
+ ```
68
+
69
+
70
+
71
+ ## Development
72
+
73
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
74
+
75
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/edas/fakefs_rmagick.
80
+
81
+
82
+ ## License
83
+
84
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
85
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fakefs/rmagick/safe"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fakefs/rmagick/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fakefs-rmagick"
8
+ spec.version = FakeFS::Magick::VERSION
9
+ spec.authors = ["Éric Daspet"]
10
+ spec.email = ["eric.daspet+gem@survol.fr"]
11
+
12
+ spec.summary = %q{Be able to use Rmagick with FakeFS}
13
+ spec.description = %q{This is a quick'n dirty solution. It certainly covers only a few use cases.}
14
+ spec.homepage = "https://github.com/edas/fakefs-rmagick"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "rmagick", "~> 2"
34
+ spec.add_development_dependency "fakefs", "~> 0"
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.14"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ end
@@ -0,0 +1,3 @@
1
+ require "fakefs/rmagick/safe"
2
+
3
+ FakeFS::Magick.activate!
@@ -0,0 +1,51 @@
1
+ require "rmagick"
2
+ require "fakefs/rmagick/real_image"
3
+
4
+ module FakeFS
5
+ module Magick
6
+
7
+ module FakeImageInstance
8
+
9
+ def write(file)
10
+ m = file.match /(?:^([a-zA-Z0-9]+):)|(?:\.([a-zA-Z0-9]+)$)/
11
+ myformat = (m[1] || m[2]).sub("jpg", "jpeg").upcase if m
12
+ ::File.write(file.sub(/^([a-zA-Z0-9]+):/, ''), to_blob {
13
+ self.format = myformat if m
14
+ yield if block_given?
15
+ })
16
+ self
17
+ end
18
+
19
+ def faked?
20
+ true
21
+ end
22
+
23
+ end
24
+
25
+ module FakeImageClass
26
+
27
+ def read(file, &block)
28
+ from_blob(::File.read(file),&block).each do |image|
29
+ image.extend(FakeImageInstance)
30
+ end
31
+ end
32
+
33
+ def ping(file, &block)
34
+ read(file, &block)
35
+ end
36
+
37
+ def fake?
38
+ true
39
+ end
40
+
41
+ end
42
+
43
+ class FakeImage < RealImage
44
+
45
+ extend FakeImageClass
46
+ include FakeImageInstance
47
+
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,23 @@
1
+ module FakeFS
2
+ module Magick
3
+
4
+ module FakeFSHook
5
+ def activate!
6
+ FakeFS::Magick.activate! if with_rmagick_hook?
7
+ super
8
+ end
9
+
10
+ def deactivate!
11
+ super
12
+ FakeFS::Magick.deactivate! if with_rmagick_hook?
13
+ end
14
+
15
+ def with_rmagick_hook?
16
+ FakeFS::Magick.hook_activated?
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+ end
23
+
@@ -0,0 +1,3 @@
1
+ require "fakefs/rmagick/safe"
2
+
3
+ FakeFS::Magick.hook!
@@ -0,0 +1,47 @@
1
+ require "rmagick"
2
+
3
+ module FakeFS
4
+ module Magick
5
+
6
+ def self.activate!
7
+ ::Magick.class_eval do
8
+ remove_const(:Image)
9
+ const_set(:Image, ::FakeFS::Magick::FakeImage)
10
+ end
11
+ end
12
+
13
+ def self.deactivate!
14
+ ::Magick.class_eval do
15
+ remove_const(:Image)
16
+ const_set(:Image, ::FakeFS::Magick::RealImage)
17
+ end
18
+ end
19
+
20
+ def self.activated?
21
+ ::Magick::Image == ::FakeFS::Magick::FakeImage
22
+ end
23
+
24
+ def self.with
25
+ begin
26
+ self.activate!
27
+ yield
28
+ ensure
29
+ self.deactivate!
30
+ end
31
+ end
32
+
33
+ def self.hook!
34
+ FakeFS.singleton_class.prepend(FakeFSHook) unless FakeFS.respond_to?(:with_rmagick_hook?)
35
+ @@with_hook = true
36
+ end
37
+
38
+ def self.hook_activated?
39
+ @@with_hook
40
+ end
41
+
42
+ def self.deactivate_hook!
43
+ @@with_hook = false
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,24 @@
1
+ require "rmagick"
2
+
3
+ module FakeFS
4
+ module Magick
5
+
6
+ RealImage = ::Magick::Image
7
+
8
+ module RealImageInstance
9
+ def faked?
10
+ false
11
+ end
12
+ end
13
+
14
+ module RealImageClass
15
+ def fake?
16
+ false
17
+ end
18
+ end
19
+
20
+ RealImage.include(RealImageInstance)
21
+ RealImage.extend(RealImageClass)
22
+
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ require "fakefs/safe"
2
+ require "fakefs/rmagick/version"
3
+ require "fakefs/rmagick/magick"
4
+ require "fakefs/rmagick/fakefs_hook"
5
+ require "fakefs/rmagick/real_image"
6
+ require "fakefs/rmagick/fake_image"
7
+
@@ -0,0 +1,5 @@
1
+ module FakeFS
2
+ module Magick
3
+ VERSION = "0.2.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fakefs-rmagick
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Éric Daspet
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rmagick
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fakefs
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: This is a quick'n dirty solution. It certainly covers only a few use
84
+ cases.
85
+ email:
86
+ - eric.daspet+gem@survol.fr
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - fakefs_rmagick.gemspec
101
+ - lib/fakefs-rmagick.rb
102
+ - lib/fakefs/rmagick/fake_image.rb
103
+ - lib/fakefs/rmagick/fakefs_hook.rb
104
+ - lib/fakefs/rmagick/hook.rb
105
+ - lib/fakefs/rmagick/magick.rb
106
+ - lib/fakefs/rmagick/real_image.rb
107
+ - lib/fakefs/rmagick/safe.rb
108
+ - lib/fakefs/rmagick/version.rb
109
+ homepage: https://github.com/edas/fakefs-rmagick
110
+ licenses:
111
+ - MIT
112
+ metadata:
113
+ allowed_push_host: https://rubygems.org
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.6.8
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Be able to use Rmagick with FakeFS
134
+ test_files: []