activestorage-memory 0.1.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
+ SHA256:
3
+ metadata.gz: 225cd38418cfa2b7318059599b306cecb07a0a14f16673ab13468a261ca7c87d
4
+ data.tar.gz: c96879c4425e6df7c435b52be5718187f8b5bf6cfba92131da1f6d5632cb3a01
5
+ SHA512:
6
+ metadata.gz: 0a69efcb428a4a2b9fead9ee4d1c78427fcd6823e4314cb4a550c98ab05bf8fd88ebb476f9c90761f09b3b581cd5f7ed91d294112a897a8f94a81c4bf96cbeee
7
+ data.tar.gz: bd0a3463ec6ad8d08b93c318a9f299610be8452d09f5b0ed862cd5417c0ffe33ee1210f4124997d7a049853b50d4821b2f66f007469a15b7bb5cb9481f5c7245
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v4
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.2.2
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.4
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in activestorage-memory.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,204 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ activestorage-memory (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actioncable (7.1.3.2)
10
+ actionpack (= 7.1.3.2)
11
+ activesupport (= 7.1.3.2)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ zeitwerk (~> 2.6)
15
+ actionmailbox (7.1.3.2)
16
+ actionpack (= 7.1.3.2)
17
+ activejob (= 7.1.3.2)
18
+ activerecord (= 7.1.3.2)
19
+ activestorage (= 7.1.3.2)
20
+ activesupport (= 7.1.3.2)
21
+ mail (>= 2.7.1)
22
+ net-imap
23
+ net-pop
24
+ net-smtp
25
+ actionmailer (7.1.3.2)
26
+ actionpack (= 7.1.3.2)
27
+ actionview (= 7.1.3.2)
28
+ activejob (= 7.1.3.2)
29
+ activesupport (= 7.1.3.2)
30
+ mail (~> 2.5, >= 2.5.4)
31
+ net-imap
32
+ net-pop
33
+ net-smtp
34
+ rails-dom-testing (~> 2.2)
35
+ actionpack (7.1.3.2)
36
+ actionview (= 7.1.3.2)
37
+ activesupport (= 7.1.3.2)
38
+ nokogiri (>= 1.8.5)
39
+ racc
40
+ rack (>= 2.2.4)
41
+ rack-session (>= 1.0.1)
42
+ rack-test (>= 0.6.3)
43
+ rails-dom-testing (~> 2.2)
44
+ rails-html-sanitizer (~> 1.6)
45
+ actiontext (7.1.3.2)
46
+ actionpack (= 7.1.3.2)
47
+ activerecord (= 7.1.3.2)
48
+ activestorage (= 7.1.3.2)
49
+ activesupport (= 7.1.3.2)
50
+ globalid (>= 0.6.0)
51
+ nokogiri (>= 1.8.5)
52
+ actionview (7.1.3.2)
53
+ activesupport (= 7.1.3.2)
54
+ builder (~> 3.1)
55
+ erubi (~> 1.11)
56
+ rails-dom-testing (~> 2.2)
57
+ rails-html-sanitizer (~> 1.6)
58
+ activejob (7.1.3.2)
59
+ activesupport (= 7.1.3.2)
60
+ globalid (>= 0.3.6)
61
+ activemodel (7.1.3.2)
62
+ activesupport (= 7.1.3.2)
63
+ activerecord (7.1.3.2)
64
+ activemodel (= 7.1.3.2)
65
+ activesupport (= 7.1.3.2)
66
+ timeout (>= 0.4.0)
67
+ activestorage (7.1.3.2)
68
+ actionpack (= 7.1.3.2)
69
+ activejob (= 7.1.3.2)
70
+ activerecord (= 7.1.3.2)
71
+ activesupport (= 7.1.3.2)
72
+ marcel (~> 1.0)
73
+ activesupport (7.1.3.2)
74
+ base64
75
+ bigdecimal
76
+ concurrent-ruby (~> 1.0, >= 1.0.2)
77
+ connection_pool (>= 2.2.5)
78
+ drb
79
+ i18n (>= 1.6, < 2)
80
+ minitest (>= 5.1)
81
+ mutex_m
82
+ tzinfo (~> 2.0)
83
+ base64 (0.2.0)
84
+ bigdecimal (3.1.6)
85
+ builder (3.2.4)
86
+ concurrent-ruby (1.2.3)
87
+ connection_pool (2.4.1)
88
+ crass (1.0.6)
89
+ date (3.3.4)
90
+ diff-lcs (1.5.1)
91
+ drb (2.2.1)
92
+ erubi (1.12.0)
93
+ globalid (1.2.1)
94
+ activesupport (>= 6.1)
95
+ i18n (1.14.1)
96
+ concurrent-ruby (~> 1.0)
97
+ io-console (0.7.2)
98
+ irb (1.11.2)
99
+ rdoc
100
+ reline (>= 0.4.2)
101
+ loofah (2.22.0)
102
+ crass (~> 1.0.2)
103
+ nokogiri (>= 1.12.0)
104
+ mail (2.8.1)
105
+ mini_mime (>= 0.1.1)
106
+ net-imap
107
+ net-pop
108
+ net-smtp
109
+ marcel (1.0.4)
110
+ mini_mime (1.1.5)
111
+ minitest (5.22.2)
112
+ mutex_m (0.2.0)
113
+ net-imap (0.4.10)
114
+ date
115
+ net-protocol
116
+ net-pop (0.1.2)
117
+ net-protocol
118
+ net-protocol (0.2.2)
119
+ timeout
120
+ net-smtp (0.4.0.1)
121
+ net-protocol
122
+ nio4r (2.7.0)
123
+ nokogiri (1.16.2-x86_64-darwin)
124
+ racc (~> 1.4)
125
+ psych (5.1.2)
126
+ stringio
127
+ racc (1.7.3)
128
+ rack (3.0.9.1)
129
+ rack-session (2.0.0)
130
+ rack (>= 3.0.0)
131
+ rack-test (2.1.0)
132
+ rack (>= 1.3)
133
+ rackup (2.1.0)
134
+ rack (>= 3)
135
+ webrick (~> 1.8)
136
+ rails (7.1.3.2)
137
+ actioncable (= 7.1.3.2)
138
+ actionmailbox (= 7.1.3.2)
139
+ actionmailer (= 7.1.3.2)
140
+ actionpack (= 7.1.3.2)
141
+ actiontext (= 7.1.3.2)
142
+ actionview (= 7.1.3.2)
143
+ activejob (= 7.1.3.2)
144
+ activemodel (= 7.1.3.2)
145
+ activerecord (= 7.1.3.2)
146
+ activestorage (= 7.1.3.2)
147
+ activesupport (= 7.1.3.2)
148
+ bundler (>= 1.15.0)
149
+ railties (= 7.1.3.2)
150
+ rails-dom-testing (2.2.0)
151
+ activesupport (>= 5.0.0)
152
+ minitest
153
+ nokogiri (>= 1.6)
154
+ rails-html-sanitizer (1.6.0)
155
+ loofah (~> 2.21)
156
+ nokogiri (~> 1.14)
157
+ railties (7.1.3.2)
158
+ actionpack (= 7.1.3.2)
159
+ activesupport (= 7.1.3.2)
160
+ irb
161
+ rackup (>= 1.0.0)
162
+ rake (>= 12.2)
163
+ thor (~> 1.0, >= 1.2.2)
164
+ zeitwerk (~> 2.6)
165
+ rake (13.1.0)
166
+ rdoc (6.6.2)
167
+ psych (>= 4.0.0)
168
+ reline (0.4.3)
169
+ io-console (~> 0.5)
170
+ rspec (3.13.0)
171
+ rspec-core (~> 3.13.0)
172
+ rspec-expectations (~> 3.13.0)
173
+ rspec-mocks (~> 3.13.0)
174
+ rspec-core (3.13.0)
175
+ rspec-support (~> 3.13.0)
176
+ rspec-expectations (3.13.0)
177
+ diff-lcs (>= 1.2.0, < 2.0)
178
+ rspec-support (~> 3.13.0)
179
+ rspec-mocks (3.13.0)
180
+ diff-lcs (>= 1.2.0, < 2.0)
181
+ rspec-support (~> 3.13.0)
182
+ rspec-support (3.13.1)
183
+ stringio (3.1.0)
184
+ thor (1.3.1)
185
+ timeout (0.4.1)
186
+ tzinfo (2.0.6)
187
+ concurrent-ruby (~> 1.0)
188
+ webrick (1.8.1)
189
+ websocket-driver (0.7.6)
190
+ websocket-extensions (>= 0.1.0)
191
+ websocket-extensions (0.1.5)
192
+ zeitwerk (2.6.13)
193
+
194
+ PLATFORMS
195
+ x86_64-darwin-22
196
+
197
+ DEPENDENCIES
198
+ activestorage-memory!
199
+ rails (~> 7.0, >= 7.0.0)
200
+ rake (~> 13.0)
201
+ rspec (~> 3.0)
202
+
203
+ BUNDLED WITH
204
+ 2.4.10
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 kykt35
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,39 @@
1
+ # ActiveStorage::Memory
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/active_storage/memory`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'activestorage-memory'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install activestorage-memory
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kykt35/activestorage-memory.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/active_storage/memory/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'activestorage-memory'
7
+ spec.version = ActiveStorage::Memory::VERSION
8
+ spec.authors = ['kykt35']
9
+ spec.email = ['kykt35@gmail.com']
10
+
11
+ spec.summary = 'Rails ActiveStorage in-memory service adopter.'
12
+ spec.homepage = 'https://github.com/kykt35/activestorage-memory'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/kykt35/activestorage-memory'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/kykt35/activestorage-memory'
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ # Uncomment to register a new dependency of your gem
30
+ spec.add_development_dependency 'rails', '~> 7.0', '>= 7.0.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ # spec.add_dependency "example-gem", "~> 1.0"
33
+
34
+ # For more information and examples about making a new gem, checkout our
35
+ # guide at: https://bundler.io/guides/creating_gem.html
36
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'active_storage/memory'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ 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,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveStorage
4
+ module Memory
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "memory/version"
4
+
5
+ module Activestorage
6
+ module Memory
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ end
10
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveStorage
4
+ # ActiveStorage in-memory service
5
+ class Service::MemoryService < ActiveStorage::Service
6
+ attr_reader :store
7
+
8
+ def initialize(**config)
9
+ super
10
+ @store = {}
11
+ @config = config
12
+ end
13
+
14
+ def upload(key, io, **)
15
+ instrument(:upload, key: key) do
16
+ store[key] = io.read
17
+ end
18
+ end
19
+
20
+ def download(key)
21
+ instrument(:streaming_download, key: key) do
22
+ io = StringIO.new(store.fetch(key))
23
+ io.set_encoding(io.string.encoding)
24
+ io
25
+ rescue KeyError
26
+ raise ActiveStorage::FileNotFoundError
27
+ end
28
+ end
29
+
30
+ def delete(key)
31
+ instrument(:delete, key: key) do
32
+ store.delete(key)
33
+ rescue KeyError
34
+ # Ignore key errors
35
+ end
36
+ end
37
+
38
+ def exist?(key)
39
+ instrument(:exist, key: key) do |payload|
40
+ answer = store.key?(key)
41
+ payload[:exist] = answer
42
+ answer
43
+ end
44
+ end
45
+
46
+ def url(key)
47
+ instrument(:url, key: key) do
48
+ # FIXME: - this should be a URL that can be used to directly download the file
49
+ "memory://#{key}"
50
+ end
51
+ end
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activestorage-memory
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kykt35
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 7.0.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '7.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 7.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ description:
48
+ email:
49
+ - kykt35@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - ".github/workflows/main.yml"
55
+ - ".gitignore"
56
+ - ".rspec"
57
+ - Gemfile
58
+ - Gemfile.lock
59
+ - LICENSE.txt
60
+ - README.md
61
+ - Rakefile
62
+ - activestorage-memory.gemspec
63
+ - bin/console
64
+ - bin/setup
65
+ - lib/active_storage/memory.rb
66
+ - lib/active_storage/memory/version.rb
67
+ - lib/active_storage/service/memory_service.rb
68
+ homepage: https://github.com/kykt35/activestorage-memory
69
+ licenses:
70
+ - MIT
71
+ metadata:
72
+ homepage_uri: https://github.com/kykt35/activestorage-memory
73
+ source_code_uri: https://github.com/kykt35/activestorage-memory
74
+ changelog_uri: https://github.com/kykt35/activestorage-memory
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 2.7.0
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.4.10
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Rails ActiveStorage in-memory service adopter.
94
+ test_files: []