oss-ar 0.0.1 → 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 +4 -4
- data/lib/oss-activerecord/attachment.rb +1 -0
- data/lib/oss-activerecord/version.rb +1 -1
- data/lib/oss-activerecord.rb +1 -7
- metadata +16 -7
- data/.rspec +0 -3
- data/Gemfile +0 -21
- data/Gemfile.lock +0 -93
- data/README.md +0 -171
- data/Rakefile +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22fb8bd93da07f822d96b4f40458ca5607bc3f66a2cbfd5718689921b40a2bb2
|
4
|
+
data.tar.gz: 916d873fdc394dafe551c93aaf442adf81c08a96bc57c95d93e43d93295cb9ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d181d757a2dc241f8d36e492c8b6da2b0c36c819459f2a6f7d17b0c2fa17d77a6ebcc2139c424ddbb9a8b9f32c20ca50bb880877cb92f262174d15065b4e269f
|
7
|
+
data.tar.gz: 6526516e5afabdcdf110817c8ee358e1d7c41bea31c26aa322c91e5affe4eebb4375aa5831578377bc7141717ab7b5abd8a007a2190b55f1babc77e3ff703f2c
|
data/lib/oss-activerecord.rb
CHANGED
@@ -1,11 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'sorbet-runtime'
|
4
|
+
require_relative 'oss-activerecord/version'
|
4
5
|
require_relative "oss-activerecord/attachment"
|
5
|
-
|
6
|
-
module Meta
|
7
|
-
module OSS
|
8
|
-
class Error < StandardError; end
|
9
|
-
# Your code goes here...
|
10
|
-
end
|
11
|
-
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oss-ar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yetrun
|
@@ -9,7 +9,21 @@ autorequire:
|
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
11
|
date: 2024-05-06 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sorbet-runtime
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.5'
|
13
27
|
description:
|
14
28
|
email:
|
15
29
|
- yetrun@foxmail.com
|
@@ -17,11 +31,6 @@ executables: []
|
|
17
31
|
extensions: []
|
18
32
|
extra_rdoc_files: []
|
19
33
|
files:
|
20
|
-
- ".rspec"
|
21
|
-
- Gemfile
|
22
|
-
- Gemfile.lock
|
23
|
-
- README.md
|
24
|
-
- Rakefile
|
25
34
|
- lib/oss-activerecord.rb
|
26
35
|
- lib/oss-activerecord/attachment.rb
|
27
36
|
- lib/oss-activerecord/version.rb
|
data/.rspec
DELETED
data/Gemfile
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in oss-activerecord.gemspec
|
6
|
-
gemspec
|
7
|
-
|
8
|
-
group :development do
|
9
|
-
gem "rake", "~> 13.0"
|
10
|
-
end
|
11
|
-
|
12
|
-
group :test do
|
13
|
-
gem "rspec", "~> 3.0"
|
14
|
-
end
|
15
|
-
|
16
|
-
gem "activerecord", "~> 7.1"
|
17
|
-
gem "sqlite3", "~> 1.4"
|
18
|
-
gem "sorbet-runtime", "~> 0.5.11357"
|
19
|
-
|
20
|
-
gem "aliyun-sdk", "~> 0.8.0"
|
21
|
-
gem "qiniu", "~> 6.9"
|
data/Gemfile.lock
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
oss-ar (0.0.1)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
activemodel (7.1.3.2)
|
10
|
-
activesupport (= 7.1.3.2)
|
11
|
-
activerecord (7.1.3.2)
|
12
|
-
activemodel (= 7.1.3.2)
|
13
|
-
activesupport (= 7.1.3.2)
|
14
|
-
timeout (>= 0.4.0)
|
15
|
-
activesupport (7.1.3.2)
|
16
|
-
base64
|
17
|
-
bigdecimal
|
18
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
-
connection_pool (>= 2.2.5)
|
20
|
-
drb
|
21
|
-
i18n (>= 1.6, < 2)
|
22
|
-
minitest (>= 5.1)
|
23
|
-
mutex_m
|
24
|
-
tzinfo (~> 2.0)
|
25
|
-
aliyun-sdk (0.8.0)
|
26
|
-
nokogiri (~> 1.6)
|
27
|
-
rest-client (~> 2.0)
|
28
|
-
base64 (0.2.0)
|
29
|
-
bigdecimal (3.1.7)
|
30
|
-
concurrent-ruby (1.2.3)
|
31
|
-
connection_pool (2.4.1)
|
32
|
-
diff-lcs (1.5.1)
|
33
|
-
domain_name (0.6.20240107)
|
34
|
-
drb (2.2.1)
|
35
|
-
http-accept (1.7.0)
|
36
|
-
http-cookie (1.0.5)
|
37
|
-
domain_name (~> 0.5)
|
38
|
-
i18n (1.14.4)
|
39
|
-
concurrent-ruby (~> 1.0)
|
40
|
-
mime-types (3.5.2)
|
41
|
-
mime-types-data (~> 3.2015)
|
42
|
-
mime-types-data (3.2024.0305)
|
43
|
-
minitest (5.22.3)
|
44
|
-
mutex_m (0.2.0)
|
45
|
-
netrc (0.11.0)
|
46
|
-
nokogiri (1.16.4-x86_64-darwin)
|
47
|
-
racc (~> 1.4)
|
48
|
-
qiniu (6.9.1)
|
49
|
-
mime-types (~> 3.1)
|
50
|
-
rest-client (~> 2.0)
|
51
|
-
rexml (~> 3.2)
|
52
|
-
racc (1.7.3)
|
53
|
-
rake (13.2.1)
|
54
|
-
rest-client (2.1.0)
|
55
|
-
http-accept (>= 1.7.0, < 2.0)
|
56
|
-
http-cookie (>= 1.0.2, < 2.0)
|
57
|
-
mime-types (>= 1.16, < 4.0)
|
58
|
-
netrc (~> 0.8)
|
59
|
-
rexml (3.2.6)
|
60
|
-
rspec (3.13.0)
|
61
|
-
rspec-core (~> 3.13.0)
|
62
|
-
rspec-expectations (~> 3.13.0)
|
63
|
-
rspec-mocks (~> 3.13.0)
|
64
|
-
rspec-core (3.13.0)
|
65
|
-
rspec-support (~> 3.13.0)
|
66
|
-
rspec-expectations (3.13.0)
|
67
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
68
|
-
rspec-support (~> 3.13.0)
|
69
|
-
rspec-mocks (3.13.0)
|
70
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
71
|
-
rspec-support (~> 3.13.0)
|
72
|
-
rspec-support (3.13.1)
|
73
|
-
sorbet-runtime (0.5.11357)
|
74
|
-
sqlite3 (1.7.3-x86_64-darwin)
|
75
|
-
timeout (0.4.1)
|
76
|
-
tzinfo (2.0.6)
|
77
|
-
concurrent-ruby (~> 1.0)
|
78
|
-
|
79
|
-
PLATFORMS
|
80
|
-
x86_64-darwin-22
|
81
|
-
|
82
|
-
DEPENDENCIES
|
83
|
-
activerecord (~> 7.1)
|
84
|
-
aliyun-sdk (~> 0.8.0)
|
85
|
-
oss-ar!
|
86
|
-
qiniu (~> 6.9)
|
87
|
-
rake (~> 13.0)
|
88
|
-
rspec (~> 3.0)
|
89
|
-
sorbet-runtime (~> 0.5.11357)
|
90
|
-
sqlite3 (~> 1.4)
|
91
|
-
|
92
|
-
BUNDLED WITH
|
93
|
-
2.4.6
|
data/README.md
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
# oss-activerecord
|
2
|
-
|
3
|
-
一种用于将国内的云存储服务与 ActiveRecord 集成的解决方案。
|
4
|
-
|
5
|
-
## 写在最前
|
6
|
-
|
7
|
-
该 gem 主要包括两个部分:
|
8
|
-
|
9
|
-
1. 一个 OSS 服务的适配器,将不同的 OSS 服务抽象为统一的接口,方便在不同的 OSS 服务商之间切换。
|
10
|
-
2. 一个 OSS::Attachment 数据表,将 OSS 上传的对象纳入在一个表中管理,方便日后的迁移。
|
11
|
-
|
12
|
-
## 安装
|
13
|
-
|
14
|
-
在 Gemfile 中添加:
|
15
|
-
|
16
|
-
```ruby
|
17
|
-
gem 'oss-activerecord'
|
18
|
-
```
|
19
|
-
|
20
|
-
然后执行:
|
21
|
-
|
22
|
-
```bash
|
23
|
-
$ bundle
|
24
|
-
```
|
25
|
-
|
26
|
-
最后在 Ruby 项目中引入:
|
27
|
-
|
28
|
-
```ruby
|
29
|
-
require 'oss-activerecord'
|
30
|
-
```
|
31
|
-
|
32
|
-
## OSS Adapter
|
33
|
-
|
34
|
-
没有为 OSS Adapter 提供一个统一的类,而是提供不同的云厂商的适配器,你可以根据自己的需求选择合适的适配器。(这么做是因为 Ruby 语言不需要)
|
35
|
-
|
36
|
-
目前已支持的 OSS 服务商有:
|
37
|
-
|
38
|
-
- 阿里云 OSS:`OSS::Adapters::AliyunAdapter`
|
39
|
-
- 七牛云 OSS:`OSS::Adapters::QiniuAdapter`
|
40
|
-
|
41
|
-
### 创建 adapter
|
42
|
-
|
43
|
-
创建遵从相同的接口签名,以阿里云 OSS 为例:
|
44
|
-
|
45
|
-
```ruby
|
46
|
-
gem "aliyun-sdk"
|
47
|
-
|
48
|
-
require 'oss/adapters/aliyun_adapter'
|
49
|
-
adapter = OSS::Adapters::AliyunAdapter.new(
|
50
|
-
access_key: 'your-access-key-id',
|
51
|
-
secret_key: 'your-access-key-secret',
|
52
|
-
endpoint: 'your-endpoint',
|
53
|
-
bucket: 'your-bucket'
|
54
|
-
)
|
55
|
-
```
|
56
|
-
|
57
|
-
以七牛云 OSS 为例:
|
58
|
-
|
59
|
-
```ruby
|
60
|
-
gem "qiniu"
|
61
|
-
|
62
|
-
require 'oss/adapters/qiniu_adapter'
|
63
|
-
adapter = OSS::Adapters::QiniuAdapter.new(
|
64
|
-
access_key: 'your-access-key',
|
65
|
-
secret_key: 'your-secret-key',
|
66
|
-
endpoint: 'your-endpoint',
|
67
|
-
bucket: 'your-bucket'
|
68
|
-
)
|
69
|
-
```
|
70
|
-
|
71
|
-
### 上传文件
|
72
|
-
|
73
|
-
```ruby
|
74
|
-
adapter.upload('path/to/file', 'object-key')
|
75
|
-
```
|
76
|
-
|
77
|
-
### 返回签名 URL
|
78
|
-
|
79
|
-
```ruby
|
80
|
-
adapter.signed_url('object-key')
|
81
|
-
```
|
82
|
-
|
83
|
-
## `OSS::Attachment`
|
84
|
-
|
85
|
-
该模块主要是将所有与云存储对象相关的属性都关联一个表,方便统一管理和日后的迁移。同时,为了维护项目本身的兼容性,也为了适应更常见的需求,该模块将表关联的操作透明化。
|
86
|
-
|
87
|
-
### 创建表
|
88
|
-
|
89
|
-
在使用该模块之前,要求系统中已经存在一个 `oss_attachments` 表,类似的迁移脚本:
|
90
|
-
|
91
|
-
```ruby
|
92
|
-
create_table :attachments do |t|
|
93
|
-
t.string :object_key, comment: 'OSS 对象的 key'
|
94
|
-
t.references :attachable, polymorphic: true, comment: '关联的对象'
|
95
|
-
t.string :context, comment: '属性上下文'
|
96
|
-
end
|
97
|
-
```
|
98
|
-
|
99
|
-
### 关联模型
|
100
|
-
|
101
|
-
以 `User` 模型为例:
|
102
|
-
|
103
|
-
```ruby
|
104
|
-
class User < ActiveRecord::Base
|
105
|
-
extend OSS::Attachment::Attachable
|
106
|
-
|
107
|
-
has_one_attached :avatar, :avatar_url
|
108
|
-
end
|
109
|
-
```
|
110
|
-
|
111
|
-
该动作创建了一个 `avatar` 关联,同时创建了一个 `avatar_url` 的属性用于兼容性操作。
|
112
|
-
|
113
|
-
### 使用属性 URL
|
114
|
-
|
115
|
-
```ruby
|
116
|
-
user = User.new
|
117
|
-
|
118
|
-
# 保存 URL
|
119
|
-
user.avatar_url = 'object_key' # or full url、full url with signature
|
120
|
-
user.save! # 这一步才会写入数据库
|
121
|
-
|
122
|
-
# 读取 URL
|
123
|
-
user.avatar_url # get full url
|
124
|
-
```
|
125
|
-
|
126
|
-
### has_many_attached
|
127
|
-
|
128
|
-
除了 `has_one_attached` 之外,还支持 `has_many_attached`:
|
129
|
-
|
130
|
-
```ruby
|
131
|
-
class User < ActiveRecord::Base
|
132
|
-
extend OSS::Attachment::Attachable
|
133
|
-
|
134
|
-
has_many_attached :photos, :photo_urls
|
135
|
-
end
|
136
|
-
```
|
137
|
-
|
138
|
-
此时可以使用 `photo_urls` 进行操作。
|
139
|
-
|
140
|
-
```ruby
|
141
|
-
user = User.new
|
142
|
-
|
143
|
-
# 保存 URL
|
144
|
-
user.photo_urls = ['object_key1', 'object_key2'] # or full urls、full urls with signature
|
145
|
-
user.save! # 这一步才会写入数据库
|
146
|
-
|
147
|
-
# 读取 URL
|
148
|
-
user.photo_urls # get full urls
|
149
|
-
```
|
150
|
-
|
151
|
-
## 开发
|
152
|
-
|
153
|
-
```bash
|
154
|
-
git clone 本仓库
|
155
|
-
|
156
|
-
# 安装依赖项目
|
157
|
-
bundle
|
158
|
-
|
159
|
-
# 运行单元测试
|
160
|
-
bundle exec rspec
|
161
|
-
|
162
|
-
# 生成 gem
|
163
|
-
gem build oss-activerecord.gemspec
|
164
|
-
|
165
|
-
# 推送 gem
|
166
|
-
gem push oss-activerecord-x.x.x.gem
|
167
|
-
```
|
168
|
-
|
169
|
-
## 贡献
|
170
|
-
|
171
|
-
问题报告和 pull requests 在 GitHub 上:https://github.com/[USERNAME]/meta-oss.
|