local_resource 0.1.0

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.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +9 -0
  4. data/.hound.yml +4 -0
  5. data/.rspec +3 -0
  6. data/.rubocop.yml +1038 -0
  7. data/.ruby-version +1 -0
  8. data/.travis.yml +15 -0
  9. data/CHANGELOG.md +7 -0
  10. data/Gemfile +14 -0
  11. data/Gemfile.lock +212 -0
  12. data/Guardfile +15 -0
  13. data/LICENSE.txt +21 -0
  14. data/README.md +72 -0
  15. data/Rakefile +10 -0
  16. data/bin/test +5 -0
  17. data/lib/local_resource/engine.rb +14 -0
  18. data/lib/local_resource/instance.rb +46 -0
  19. data/lib/local_resource/version.rb +3 -0
  20. data/lib/local_resource.rb +32 -0
  21. data/lib/tasks/local_resource_tasks.rake +4 -0
  22. data/local_resource.gemspec +30 -0
  23. data/spec/dummy/Rakefile +6 -0
  24. data/spec/dummy/app/assets/config/manifest.js +4 -0
  25. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  26. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  27. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  28. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  29. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  30. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  31. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  32. data/spec/dummy/app/jobs/application_job.rb +2 -0
  33. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  34. data/spec/dummy/app/models/application_record.rb +3 -0
  35. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  36. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  37. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  38. data/spec/dummy/bin/bundle +3 -0
  39. data/spec/dummy/bin/rails +4 -0
  40. data/spec/dummy/bin/rake +4 -0
  41. data/spec/dummy/bin/setup +38 -0
  42. data/spec/dummy/bin/update +29 -0
  43. data/spec/dummy/bin/yarn +11 -0
  44. data/spec/dummy/config/application.rb +26 -0
  45. data/spec/dummy/config/boot.rb +5 -0
  46. data/spec/dummy/config/cable.yml +10 -0
  47. data/spec/dummy/config/database.yml +25 -0
  48. data/spec/dummy/config/environment.rb +5 -0
  49. data/spec/dummy/config/environments/development.rb +54 -0
  50. data/spec/dummy/config/environments/production.rb +91 -0
  51. data/spec/dummy/config/environments/test.rb +42 -0
  52. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  53. data/spec/dummy/config/initializers/assets.rb +14 -0
  54. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  55. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  56. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  57. data/spec/dummy/config/initializers/inflections.rb +16 -0
  58. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  59. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  60. data/spec/dummy/config/locales/en.yml +33 -0
  61. data/spec/dummy/config/puma.rb +56 -0
  62. data/spec/dummy/config/routes.rb +3 -0
  63. data/spec/dummy/config/secrets.yml +32 -0
  64. data/spec/dummy/config/spring.rb +6 -0
  65. data/spec/dummy/config.ru +5 -0
  66. data/spec/dummy/db/schema.rb +15 -0
  67. data/spec/dummy/package.json +5 -0
  68. data/spec/dummy/public/404.html +67 -0
  69. data/spec/dummy/public/422.html +67 -0
  70. data/spec/dummy/public/500.html +66 -0
  71. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  72. data/spec/dummy/public/apple-touch-icon.png +0 -0
  73. data/spec/dummy/public/favicon.ico +0 -0
  74. data/spec/dummy/spec/assets/image.png +0 -0
  75. data/spec/dummy/spec/assets/video.mp4 +0 -0
  76. data/spec/dummy/spec/lib/local_resource/instance_spec.rb +42 -0
  77. data/spec/dummy/spec/lib/local_resource_spec.rb +42 -0
  78. data/spec/rails_helper.rb +47 -0
  79. data/spec/spec_helper.rb +9 -0
  80. metadata +293 -0
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ script:
6
+ - RAILS_ENV=test bundle exec rake db:create db:migrate
7
+ - bundle exec rspec spec
8
+ deploy:
9
+ provider: rubygems
10
+ api_key:
11
+ secure: Q6b64qxy3KznA87Ctb/VRmmFvf94hoM/XmbU/ZCMf3Rpyh2E8tYWFredUjoaJYtW2UlPlEvYOpkGlNCVFxV4aCcyxhRvHYqW6q0ThhPoMRqJ6prEOiwG3f5qtmm3ugdNqieeUDDsDAVmp/8Oql4O56o0obsQHqD1zBOZw+QTrbB+C/hsQUF8PYaH+iqDhCxg6q1ukJsICIR0nO1jPjUcqPQXVjCAQAjNaQt3xbaybvB/kk89HbA1KX0HOndNQn5bE3cNVTnYoG//79VMcgxWwUqe2G9Oea8yzoiXX+qthQvSHen6e59qHWbm4jyBfSLiMrVP6y3jZKB9Iuqf+2woPkjEdkKrSqUjkhF6oR7ZmDMm2ccWy7Me0SM8zoG1vusLuNRZ5dYgBaKk6a3lQRNMnV4SegLz7NR/+LLuDuFv95PrDXYj6HPFrrnwiOWfiz5qNDh34K/AaWDjoRELv8IYGbpPeb92qjWqbHvFrjpHez7ZCrqR2C9jSQNYm5HOY/lT332KXsdZ/jius3nN9sb8jr37tSN0zJZJYUNPXTtJJqaauzDKfhs5hCcFOstpKmC4u4APfEvsB1KZnyZtJv5wNF7CQ+YxZcNZS++JUsoKJB+f698P7MuEp/yMkwyEMqKyS1BnMQDhAqaSOHXB1PciHW3+uXtEQlYTf31LckozmvY=
12
+ gem: local_resource
13
+ on:
14
+ tags: true
15
+ repo: platanus/local_resource
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+ ### v0.1.0
6
+
7
+ * Initial release.
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Declare your gem's dependencies in local_resource.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use a debugger
14
+ # gem 'byebug', group: [:development, :test]
data/Gemfile.lock ADDED
@@ -0,0 +1,212 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ local_resource (0.1.0)
5
+ rails (>= 4.2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (5.2.0)
11
+ actionpack (= 5.2.0)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailer (5.2.0)
15
+ actionpack (= 5.2.0)
16
+ actionview (= 5.2.0)
17
+ activejob (= 5.2.0)
18
+ mail (~> 2.5, >= 2.5.4)
19
+ rails-dom-testing (~> 2.0)
20
+ actionpack (5.2.0)
21
+ actionview (= 5.2.0)
22
+ activesupport (= 5.2.0)
23
+ rack (~> 2.0)
24
+ rack-test (>= 0.6.3)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ actionview (5.2.0)
28
+ activesupport (= 5.2.0)
29
+ builder (~> 3.1)
30
+ erubi (~> 1.4)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
+ activejob (5.2.0)
34
+ activesupport (= 5.2.0)
35
+ globalid (>= 0.3.6)
36
+ activemodel (5.2.0)
37
+ activesupport (= 5.2.0)
38
+ activerecord (5.2.0)
39
+ activemodel (= 5.2.0)
40
+ activesupport (= 5.2.0)
41
+ arel (>= 9.0)
42
+ activestorage (5.2.0)
43
+ actionpack (= 5.2.0)
44
+ activerecord (= 5.2.0)
45
+ marcel (~> 0.3.1)
46
+ activesupport (5.2.0)
47
+ concurrent-ruby (~> 1.0, >= 1.0.2)
48
+ i18n (>= 0.7, < 2)
49
+ minitest (~> 5.1)
50
+ tzinfo (~> 1.1)
51
+ arel (9.0.0)
52
+ builder (3.2.3)
53
+ coderay (1.1.2)
54
+ concurrent-ruby (1.0.5)
55
+ coveralls (0.8.21)
56
+ json (>= 1.8, < 3)
57
+ simplecov (~> 0.14.1)
58
+ term-ansicolor (~> 1.3)
59
+ thor (~> 0.19.4)
60
+ tins (~> 1.6)
61
+ crass (1.0.4)
62
+ diff-lcs (1.3)
63
+ docile (1.1.5)
64
+ erubi (1.7.1)
65
+ factory_bot (4.10.0)
66
+ activesupport (>= 3.0.0)
67
+ factory_bot_rails (4.10.0)
68
+ factory_bot (~> 4.10.0)
69
+ railties (>= 3.0.0)
70
+ ffi (1.9.25)
71
+ formatador (0.2.5)
72
+ globalid (0.4.1)
73
+ activesupport (>= 4.2.0)
74
+ guard (2.14.2)
75
+ formatador (>= 0.2.4)
76
+ listen (>= 2.7, < 4.0)
77
+ lumberjack (>= 1.0.12, < 2.0)
78
+ nenv (~> 0.1)
79
+ notiffany (~> 0.0)
80
+ pry (>= 0.9.12)
81
+ shellany (~> 0.0)
82
+ thor (>= 0.18.1)
83
+ guard-compat (1.2.1)
84
+ guard-rspec (4.7.3)
85
+ guard (~> 2.1)
86
+ guard-compat (~> 1.1)
87
+ rspec (>= 2.99.0, < 4.0)
88
+ i18n (1.0.1)
89
+ concurrent-ruby (~> 1.0)
90
+ json (2.1.0)
91
+ listen (3.1.5)
92
+ rb-fsevent (~> 0.9, >= 0.9.4)
93
+ rb-inotify (~> 0.9, >= 0.9.7)
94
+ ruby_dep (~> 1.2)
95
+ loofah (2.2.2)
96
+ crass (~> 1.0.2)
97
+ nokogiri (>= 1.5.9)
98
+ lumberjack (1.0.13)
99
+ mail (2.7.0)
100
+ mini_mime (>= 0.1.1)
101
+ marcel (0.3.2)
102
+ mimemagic (~> 0.3.2)
103
+ method_source (0.9.0)
104
+ mimemagic (0.3.2)
105
+ mini_mime (1.0.0)
106
+ mini_portile2 (2.3.0)
107
+ minitest (5.11.3)
108
+ nenv (0.3.0)
109
+ nio4r (2.3.1)
110
+ nokogiri (1.8.3)
111
+ mini_portile2 (~> 2.3.0)
112
+ notiffany (0.1.1)
113
+ nenv (~> 0.1)
114
+ shellany (~> 0.0)
115
+ pry (0.11.3)
116
+ coderay (~> 1.1.0)
117
+ method_source (~> 0.9.0)
118
+ pry-rails (0.3.6)
119
+ pry (>= 0.10.4)
120
+ rack (2.0.5)
121
+ rack-test (1.0.0)
122
+ rack (>= 1.0, < 3)
123
+ rails (5.2.0)
124
+ actioncable (= 5.2.0)
125
+ actionmailer (= 5.2.0)
126
+ actionpack (= 5.2.0)
127
+ actionview (= 5.2.0)
128
+ activejob (= 5.2.0)
129
+ activemodel (= 5.2.0)
130
+ activerecord (= 5.2.0)
131
+ activestorage (= 5.2.0)
132
+ activesupport (= 5.2.0)
133
+ bundler (>= 1.3.0)
134
+ railties (= 5.2.0)
135
+ sprockets-rails (>= 2.0.0)
136
+ rails-dom-testing (2.0.3)
137
+ activesupport (>= 4.2.0)
138
+ nokogiri (>= 1.6)
139
+ rails-html-sanitizer (1.0.4)
140
+ loofah (~> 2.2, >= 2.2.2)
141
+ railties (5.2.0)
142
+ actionpack (= 5.2.0)
143
+ activesupport (= 5.2.0)
144
+ method_source
145
+ rake (>= 0.8.7)
146
+ thor (>= 0.18.1, < 2.0)
147
+ rake (12.3.1)
148
+ rb-fsevent (0.10.3)
149
+ rb-inotify (0.9.10)
150
+ ffi (>= 0.5.0, < 2)
151
+ rspec (3.7.0)
152
+ rspec-core (~> 3.7.0)
153
+ rspec-expectations (~> 3.7.0)
154
+ rspec-mocks (~> 3.7.0)
155
+ rspec-core (3.7.1)
156
+ rspec-support (~> 3.7.0)
157
+ rspec-expectations (3.7.0)
158
+ diff-lcs (>= 1.2.0, < 2.0)
159
+ rspec-support (~> 3.7.0)
160
+ rspec-mocks (3.7.0)
161
+ diff-lcs (>= 1.2.0, < 2.0)
162
+ rspec-support (~> 3.7.0)
163
+ rspec-rails (3.7.2)
164
+ actionpack (>= 3.0)
165
+ activesupport (>= 3.0)
166
+ railties (>= 3.0)
167
+ rspec-core (~> 3.7.0)
168
+ rspec-expectations (~> 3.7.0)
169
+ rspec-mocks (~> 3.7.0)
170
+ rspec-support (~> 3.7.0)
171
+ rspec-support (3.7.1)
172
+ ruby_dep (1.5.0)
173
+ shellany (0.0.1)
174
+ simplecov (0.14.1)
175
+ docile (~> 1.1.0)
176
+ json (>= 1.8, < 3)
177
+ simplecov-html (~> 0.10.0)
178
+ simplecov-html (0.10.2)
179
+ sprockets (3.7.2)
180
+ concurrent-ruby (~> 1.0)
181
+ rack (> 1, < 3)
182
+ sprockets-rails (3.2.1)
183
+ actionpack (>= 4.0)
184
+ activesupport (>= 4.0)
185
+ sprockets (>= 3.0.0)
186
+ sqlite3 (1.3.13)
187
+ term-ansicolor (1.6.0)
188
+ tins (~> 1.0)
189
+ thor (0.19.4)
190
+ thread_safe (0.3.6)
191
+ tins (1.16.3)
192
+ tzinfo (1.2.5)
193
+ thread_safe (~> 0.1)
194
+ websocket-driver (0.7.0)
195
+ websocket-extensions (>= 0.1.0)
196
+ websocket-extensions (0.1.3)
197
+
198
+ PLATFORMS
199
+ ruby
200
+
201
+ DEPENDENCIES
202
+ coveralls
203
+ factory_bot_rails
204
+ guard-rspec
205
+ local_resource!
206
+ pry
207
+ pry-rails
208
+ rspec-rails
209
+ sqlite3
210
+
211
+ BUNDLED WITH
212
+ 1.16.1
data/Guardfile ADDED
@@ -0,0 +1,15 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ spec_dic = "spec/dummy/spec"
3
+ # RSpec files
4
+ watch("spec/spec_helper.rb") { spec_dic }
5
+ watch("spec/rails_helper.rb") { spec_dic }
6
+ watch(%r{^spec\/dummy\/spec\/support\/(.+)\.rb$}) { spec_dic }
7
+ watch(%r{^spec\/dummy\/spec\/.+_spec\.rb$})
8
+ # Engine files
9
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/dummy/spec/lib/#{m[1]}_spec.rb" }
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/dummy/spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb)$}) { |m| "spec/dummy/spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ # Dummy app files
13
+ watch(%r{^spec\/dummy\/app/(.+)\.rb$}) { |m| "spec/dummy/spec/#{m[1]}_spec.rb" }
14
+ watch(%r{^spec\/dummy\/app/(.*)(\.erb)$}) { |m| "spec/dummy/spec/#{m[1]}#{m[2]}_spec.rb" }
15
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2018 Platanus
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,72 @@
1
+ # Local Resource
2
+
3
+ [![Build Status](https://travis-ci.org/platanus/local_resource.svg?branch=master)](https://travis-ci.org/platanus/local_resource)
4
+
5
+ Rails engine to take a file from a url, download it to the tmp, use it and delete it
6
+
7
+ ## Installation
8
+
9
+ Add to your Gemfile:
10
+
11
+ ```ruby
12
+ gem "local_resource"
13
+ ```
14
+
15
+ ```bash
16
+ bundle install
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Using `Instance`
22
+
23
+ ```ruby
24
+ instance = LocalResource::Instance.new("http://lorempixel.com/400/200", "my-photo.jpeg")
25
+ instance.file # it downloads the photo from lorempixel.com to the tmp file.
26
+ instance.file_path # it shows the local path of your downloaded image.
27
+ instance.destroy # it removes the photo from the /tmp directory.
28
+ ```
29
+
30
+ ### Using `as_local_resource`
31
+
32
+ ```ruby
33
+ LocalResource.as_local_resource("http://lorempixel.com/400/200", "my-photo.jpeg") do |tmp_file_path|
34
+ # some code needing the local file.
35
+ end
36
+ ```
37
+
38
+ The previous code...
39
+
40
+ - It downloads the photo from lorempixel.com to the tmp file.
41
+ - It executes custom code that needs the local file.
42
+ - It removes the tmp file from tmp.
43
+
44
+ ## Testing
45
+
46
+ To run the specs you need to execute, **in the root path of the gem**, the following command:
47
+
48
+ ```bash
49
+ bundle exec guard
50
+ ```
51
+
52
+ You need to put **all your tests** in the `/local_resource/spec/dummy/spec/` directory.
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create new Pull Request
61
+
62
+ ## Credits
63
+
64
+ Thank you [contributors](https://github.com/platanus/local_resource/graphs/contributors)!
65
+
66
+ <img src="http://platan.us/gravatar_with_text.png" alt="Platanus" width="250"/>
67
+
68
+ Local Resource is maintained by [platanus](http://platan.us).
69
+
70
+ ## License
71
+
72
+ Local Resource is © 2018 platanus, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ begin
2
+ require "bundler/setup"
3
+ rescue LoadError
4
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
+ end
6
+
7
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
8
+ load "rails/tasks/engine.rake"
9
+ load "rails/tasks/statistics.rake"
10
+ Bundler::GemHelper.install_tasks
data/bin/test ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path(File.expand_path("../../test", __FILE__))
3
+
4
+ require "bundler/setup"
5
+ require "rails/plugin/test"
@@ -0,0 +1,14 @@
1
+ module LocalResource
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace LocalResource
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec, fixture: false
7
+ g.fixture_replacement :factory_bot, dir: "spec/factories"
8
+ end
9
+
10
+ initializer "initialize" do
11
+ require_relative "./instance"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,46 @@
1
+ module LocalResource
2
+ class Instance
3
+ def initialize(url, tmp_filename)
4
+ @url = url
5
+ @tmp_file_name = File.basename(tmp_filename, ".*")
6
+ @tmp_file_ext = File.extname(tmp_filename)
7
+ end
8
+
9
+ def file
10
+ @file ||= load_tempfile
11
+ end
12
+
13
+ def file_path
14
+ file.path
15
+ end
16
+
17
+ def destroy
18
+ return unless @file
19
+ @file.delete
20
+ @file = nil
21
+ end
22
+
23
+ def self.tmp_dir
24
+ path = Rails.root.join('tmp/local_resources')
25
+ FileUtils::mkdir_p(path.to_s).first
26
+ end
27
+
28
+ private
29
+
30
+ def load_downloaded_data
31
+ open(@url) do |io|
32
+ return io.read
33
+ end
34
+ end
35
+
36
+ def load_tempfile
37
+ filename = [@tmp_file_name, @tmp_file_ext]
38
+ data = load_downloaded_data
39
+
40
+ Tempfile.new(filename, self.class.tmp_dir, encoding: data.encoding).tap do |f|
41
+ f.write(data)
42
+ f.close
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module LocalResource
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,32 @@
1
+ require "local_resource/engine"
2
+
3
+ module LocalResource
4
+ extend self
5
+
6
+ # You can add, in this module, your own configuration options as in the example below...
7
+ #
8
+ # attr_writer :my_option
9
+ #
10
+ # def my_option
11
+ # return "Default Value" unless @my_option
12
+ # @my_option
13
+ # end
14
+ #
15
+ # Then, you can customize the default behaviour (typically in a Rails initializer) like this:
16
+ #
17
+ # LocalResource.setup do |config|
18
+ # config.root_url = "Another value"
19
+ # end
20
+
21
+ def setup
22
+ yield self
23
+ require "local_resource"
24
+ end
25
+
26
+ def as_local_resource(url, tmp_filename, &block)
27
+ instance = LocalResource::Instance.new(url, tmp_filename)
28
+ block.call(instance.file_path)
29
+ ensure
30
+ instance&.destroy
31
+ end
32
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :local_resource do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,30 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem"s version:
4
+ require "local_resource/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "local_resource"
9
+ s.version = LocalResource::VERSION
10
+ s.authors = ["Platanus", "Leandro Segovia"]
11
+ s.email = ["rubygems@platan.us", "ldlsegovia@gmail.com"]
12
+ s.homepage = "https://github.com/platanus/local_resource"
13
+ s.summary = "Engine to treat external resources as if they were local"
14
+ s.description = "Rails engine to treat external resources as if they were local"
15
+ s.license = "MIT"
16
+
17
+ s.files = `git ls-files`.split($/).reject { |fn| fn.start_with? "spec" }
18
+ s.bindir = "exe"
19
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ s.test_files = Dir["spec/**/*"]
21
+
22
+ s.add_dependency "rails", ">= 4.2.0"
23
+ s.add_development_dependency "pry"
24
+ s.add_development_dependency "pry-rails"
25
+ s.add_development_dependency "sqlite3"
26
+ s.add_development_dependency "rspec-rails"
27
+ s.add_development_dependency "guard-rspec"
28
+ s.add_development_dependency "factory_bot_rails"
29
+ s.add_development_dependency "coveralls"
30
+ end
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,4 @@
1
+
2
+ //= link_tree ../images
3
+ //= link_directory ../javascripts .js
4
+ //= link_directory ../stylesheets .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ // Action Cable provides the framework to deal with WebSockets in Rails.
2
+ // You can generate new channels where WebSocket features live using the `rails generate channel` command.
3
+ //
4
+ //= require action_cable
5
+ //= require_self
6
+ //= require_tree ./channels
7
+
8
+ (function() {
9
+ this.App || (this.App = {});
10
+
11
+ App.cable = ActionCable.createConsumer();
12
+
13
+ }).call(this);
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
6
+
7
+ <%= stylesheet_link_tag 'application', media: 'all' %>
8
+ <%= javascript_include_tag 'application' %>
9
+ </head>
10
+
11
+ <body>
12
+ <%= yield %>
13
+ </body>
14
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run