social_nets_db 0.0.2 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eabb84b295197013fafa923bf04513f36f8acfff737fd97c24fd0f1b921c1f54
4
- data.tar.gz: c98281d4146a3e6709f740208e5c567dcd3463ab12d34b938cac562cf61b5df8
3
+ metadata.gz: b16ceb6656a59c747798848c9a99d8fd53c5db5fa903b1d2df388534a122cdc3
4
+ data.tar.gz: 4f2f515a1e9bf204a33cd01d274df52953db1d24e2a951cf70cbe7c7c4ad50a6
5
5
  SHA512:
6
- metadata.gz: a18eabf16fee2fcbd8d44660378e862844b38503191e61e156fdad135ab861b05dc204a1bcaae78c55884e0d86a0e9e9c1bd4bd035446e38fab365cab719dbd8
7
- data.tar.gz: 59fa5aad009839516180338a0920626222d0d93c7bfadd5d2df42e6d56a49960a0fb19062def33c494179a5d05507cbca71812a4eaf135ec051b0f0c0f7bd4d1
6
+ metadata.gz: 3441ffff109b6b15a45a85be1100b235422f3dbd3ded19e099a7b3e18811a94226d06393e239052edbb7023b716b1c06c26063dc66ce4e5701f6f048e5f5cea1
7
+ data.tar.gz: 76791b05f97311c578435150d61c1780c3980ead21ac60c2cc938a22135bbeef36778f18120759ff2e51283568c783b1fe1897e3b1928a045460ef65dda161a7
data/CHANGELOG.md CHANGED
@@ -1,6 +1,22 @@
1
1
  # Changelog
2
2
 
3
- ## [0.0.1] - 2021-12-02
3
+ ## [0.0.6] - 2021-12-03
4
+
5
+ - Corrects data source of accessor methods
6
+
7
+ ## [0.0.5] - 2021-12-03
8
+
9
+ - Corrects an error in `uids`
10
+
11
+ ## [0.0.4] - 2021-12-03
12
+
13
+ - Corrects an error in `values_for_select`
14
+
15
+ ## [0.0.3] - 2021-12-03
16
+
17
+ - Corrects an error with email / website
18
+
19
+ ## [0.0.2] - 2021-12-02
4
20
 
5
21
  - Renames `:font_awesome` into `:font_awesome_4` because FA v5 and v6 may have different UIDs.
6
22
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- social_nets_db (0.0.2)
4
+ social_nets_db (0.0.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Social nets DB
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/social_nets_db.svg)](https://badge.fury.io/rb/social_nets_db)
4
+
3
5
  ## Installation
4
6
 
5
7
  ```ruby
@@ -9,27 +11,24 @@ gem "social_nets_db"
9
11
 
10
12
  ## Internals
11
13
 
12
- It stores data about social nets in a Ruby hash like so:
14
+ It stores data about popular social nets, video hostings etc. in a YAML file [`db.yml`](https://github.com/sergeypedan/social-nets-db/blob/master/lib/social_nets_db/db.yml):
13
15
 
14
16
  ```yaml
15
- -
17
+ behance:
16
18
  name: Behance
17
- uid: behance
18
19
  icons:
19
- font_awesome_4: "behance"
20
+ font_awesome_4: behance
20
21
  color: "#1769ff"
21
- url: behance.com
22
+ domain: behance.com
22
23
  tags:
23
- - recruiting
24
24
  - art
25
25
  - design
26
+ - recruiting
26
27
  profile_url:
27
- by_username: https://behance.com/${username}
28
- by_account_id: "https://behance.com/${account_id}"
28
+ by_username: "https://${domain}/${uid}"
29
+ by_account_id: "https://${domain}/${uid}"
29
30
  ```
30
31
 
31
- [Peek into the source](https://github.com/sergeypedan/social-nets-db/blob/master/lib/social_net_db/db.yml).
32
-
33
32
  Everything else is just helpers around this simple DB: finders, accessors & view helpers.
34
33
 
35
34
 
@@ -47,18 +46,20 @@ ruby:
47
46
  { net_uid: "instagram", username: "dhh" },
48
47
  { net_uid: "facebook", username: "d-h-h" },
49
48
  { net_uid: "twitter", username: "d_h_h" },
50
- { net_uid: "upwork", account_id: "401298374012374" }
49
+ { net_uid: "upwork", account_id: "401298374012374" },
50
+ { net_uid: "email", username: "elon@musk.io" },
51
+ { net_uid: "website", username: "musk.io" }
51
52
  ]
52
53
 
53
54
  ul
54
55
  - accounts.each do |account|
55
- - net = SocialNetsDB.find account[:net_uid]
56
+ - net = SocialNetsDB::SocialNet.find account[:net_uid]
56
57
  li
57
- = fa_icon net.icons["font_awesome_4"], style: "color: #{net.color}"
58
+ - fa_icon_uid = net.icons["font_awesome_4"] || "link"
59
+ = fa_icon fa_icon_uid, class: "fw", style: "color: #{net.color}"
58
60
  =< link_to net.name, \
59
61
  net.user_page(username: account[:username], account_id: account[:account_id]), \
60
- target: "_blank", \
61
- rel: "noopener noreferrer"
62
+ target: "_blank", rel: "noopener noreferrer"
62
63
  ```
63
64
 
64
65
  Here the gem:
@@ -66,15 +67,13 @@ Here the gem:
66
67
  - builds the URL to user page
67
68
 
68
69
  ```ruby
69
- net.user_page(username: account[:username])
70
- # "https://facebook.com/dhh"
70
+ net.user_page(username: account[:username]) #=> "https://facebook.com/dhh"
71
71
  ```
72
72
 
73
73
  - gives you the correct name of the social net
74
74
 
75
75
  ```ruby
76
- net.name
77
- # "Facebook"
76
+ net.name #=> "Facebook"
78
77
  ```
79
78
 
80
79
  ### 2. To help building a `<select>` with social nets when storing user's account link
@@ -84,7 +83,7 @@ Here the gem:
84
83
  = f.fields_for :social_net_accounts do |sna|
85
84
  .form-group
86
85
  = sna.label :social_net_uid, class: "control-label"
87
- = sna.select :social_net_uid, SocialNetsDB.values_for_select, {}, class: "form-control"
86
+ = sna.select :social_net_uid, SocialNetsDB::SocialNet.values_for_select, {}, class: "form-control"
88
87
  ```
89
88
 
90
89
  which produces
@@ -109,12 +108,14 @@ See section “[Using with Rails](#use-with-rails)” below for more details.
109
108
 
110
109
  ## API
111
110
 
112
- ### Instance of `SocialNetsDB` class
111
+ ### Find a social net record
113
112
 
114
- Initialize an instance with social net UID.
113
+ Use either one:
115
114
 
116
115
  ```ruby
117
- social_net = SocialNetsDB.find("facebook")
116
+ social_net = SocialNetsDB::SocialNet.find("facebook")
117
+ social_net = SocialNetsDB::SocialNet.find_by(uid: "facebook")
118
+ social_net = SocialNetsDB::SocialNet.find_by_uid("facebook")
118
119
  # => #<SocialNetsDB:0x00007fddc0041b40 @uid="facebook">
119
120
  ```
120
121
 
@@ -131,97 +132,45 @@ SocialNetsDB.uids
131
132
  # "habr",
132
133
  # "github",
133
134
  # "instagram",
134
- # "livejournal",
135
- # "linkedin",
136
- # "medium",
137
- # "my.mail.ru",
138
- # "odnoklassniki",
139
- # "stackoverflow",
140
- # "telegram",
141
- # "twitter",
142
- # "upwork",
143
- # "vkontakte",
144
- # "youtube"
135
+ # ...
145
136
  # ]
146
137
  ```
147
138
 
148
- If you try to initialize with an unsupported UID, and you will also get the list along with an Exception:
149
-
150
- ```ruby
151
- SocialNetsDB.find("diaspora")
152
- # ArgumentError (Social net with UID test is not supported.
153
- #
154
- # Currently supported UIDs are: behance, dribble, facebook, github, instagram, livejournal, linkedin, medium, my.mail.ru, odnoklassniki, stackoverflow, telegram, twitter, vkontakte, youtube)
155
- ```
156
-
157
- ### find_by
158
-
159
- If you don't want to rescue exceptions while initializing, you can use `find_by(uid:)` instead.
160
-
161
- It returns an instance:
162
-
163
- ```ruby
164
- SocialNetsDB.find_by(uid: "facebook")
165
- # => #<SocialNetsDB:0x00007fddc0041b40 @uid="facebook">
166
- ```
167
-
168
- or `nil`:
169
-
170
- ```ruby
171
- SocialNetsDB.find_by(uid: "blabla")
172
- # => nil
173
- ```
174
-
175
139
  ### Data
176
140
 
177
141
  ```ruby
178
- social_net.to_h
179
- # => {
180
- # name: "Facebook",
181
- # uid: "facebook",
182
- # fa_id: "facebook",
183
- # color: "crimson",
184
- # url: "https://facebook.com",
185
- # user_page: {
186
- # by_username: "https://facebook.com/${username}",
187
- # by_account_id: "https://facebook.com/${account_id}",
188
- # methods: [:account_id, :username]
189
- # }
190
- # }
142
+ social_net.to_h #=>
143
+ # {
144
+ # "name" => "Facebook",
145
+ # "icons" => { "font_awesome_4" => "facebook" },
146
+ # "color" => "#3C5A99",
147
+ # "domain" => "facebook.com",
148
+ # "tags" => ["social net"],
149
+ # "profile_url" => {
150
+ # "by_username" => "https://${domain}/${uid}",
151
+ # "by_account_id" => "https://${domain}/${uid}"
152
+ # }
153
+ # }
191
154
  ```
192
155
 
193
156
  ### Property accessors
194
157
 
195
158
  ```ruby
196
- social_net.color #=> "#3C5A99"
197
- social_net.fa_icon_id #=> "facebook"
198
- social_net.name #=> "Facebook"
199
- social_net.uid #=> "facebook"
200
- social_net.url #=> "https://facebook.com"
159
+ social_net.color #=> "#3C5A99"
160
+ social_net.name #=> "Facebook"
161
+ social_net.uid #=> "facebook"
162
+ social_net.domain #=> "facebook.com"
163
+ social_net.url #=> "https://facebook.com"
164
+ social_net.icons #=> { "font_awesome_4" => "facebook" }
201
165
  ```
202
166
 
203
167
  ### FontAwesome icon
204
168
 
205
- Assumes you have [FontAwesome](https://fontawesome.com/v4.7.0/) installed. Just builds the HTML tag.
206
-
207
169
  ```ruby
208
- social_net.fa_icon
209
- #=> <span class="fa fa-facebook" style="color: #3C5A99"></span>
170
+ social_net.icons["font_awesome_4"] #=> "facebook"
210
171
  ```
211
172
 
212
- It accepts a Hash with attributes, like Rails `tag_helper` (but not for `data: {}` — maybe later):
213
-
214
- ```ruby
215
- social_net.fa_icon(class: "fa-fw", id: "my-id", style: "margin-top: 10px")
216
- #=> <span class="fa fa-facebook fa-fw" style="color: #3C5A99; margin-top: 10px;" id="my-id"></span>
217
- ```
218
-
219
- Exporting social net brand color to `styles` attribute can be turned off by passing `color: false` Hash pair among others:
220
-
221
- ```ruby
222
- social_net.fa_icon(color: false, class: "fa-fw", id: "my-id", style: "margin-top: 10px")
223
- #=> <span class="fa fa-facebook fa-fw" style="cmargin-top: 10px;" id="my-id"></span>
224
- ```
173
+ Currently, only FontAwesome v4 icons are store. I plan adding newer version of FA, maybe other icon providers, and also SVGs.
225
174
 
226
175
  ### User's page URL
227
176
 
@@ -230,7 +179,7 @@ social_net.user_page(username: "dhh") #=> "https://facebook.com/dhh
230
179
  social_net.user_page(account_id: "id1234566789") #=> "https://facebook.com/account/id1234566789"
231
180
  ```
232
181
 
233
- If you pass a username, whild the `SocialNet` supports user page URLs only via account ids, the method call will return `nil`.
182
+ If you pass a username, while the `SocialNet` supports user page URLs only via account ids, the method call will return `nil`.
234
183
 
235
184
  You can check which is supported
236
185
 
@@ -250,13 +199,13 @@ This gem is Rails-agnostic, but you can use it in Rails like so:
250
199
  = f.fields_for :social_net_accounts do |sna|
251
200
  .form-group
252
201
  = sna.label :social_net_uid, class: "control-label"
253
- = sna.select :social_net_uid, SocialNetsDB.values_for_select, {}, class: "form-control"
202
+ = sna.select :social_net_uid, SocialNetsDB::SocialNet.values_for_select, {}, class: "form-control"
254
203
  ```
255
204
 
256
205
  because
257
206
 
258
207
  ```ruby
259
- SocialNetsDB.values_for_select
208
+ SocialNetsDB::SocialNet.values_for_select
260
209
  #=> [
261
210
  # ["Behance", "behance"],
262
211
  # ["Dribble", "dribble"],
@@ -284,6 +233,21 @@ model User < ApplicationRecord
284
233
  end
285
234
  ```
286
235
 
236
+ This would be a standard approach:
237
+
238
+ ```ruby
239
+ # model SocialNet < ApplicationRecord
240
+ # has_many :social_net_accounts
241
+ # end
242
+ ```
243
+
244
+ but instead we will use `SocialNetsDB::SocialNet` class instead of an ActiveRecord class:
245
+
246
+ ```ruby
247
+ SocialNetsDB::SocialNet.find("facebook")
248
+ SocialNetsDB::SocialNet.find_by(uid: "facebook")
249
+ ```
250
+
287
251
  ```ruby
288
252
  model SocialNetAccount < ApplicationRecord
289
253
  belongs_to :user
@@ -293,7 +257,7 @@ model SocialNetAccount < ApplicationRecord
293
257
  validates :username, presence: true, if: Proc.new { |record| record.account_id.blank? }
294
258
 
295
259
  def social_net
296
- @social_net ||= SocialNetsDB.find(self.social_net_uid)
260
+ @social_net ||= SocialNetsDB::SocialNet.find(self.social_net_uid)
297
261
  end
298
262
 
299
263
  def user_page
@@ -503,7 +503,7 @@ youtube:
503
503
  by_account_id: "https://${domain}/channel/${uid}"
504
504
 
505
505
  youtube_profile:
506
- name: YouTube
506
+ name: YouTube profile
507
507
  icons:
508
508
  font_awesome_4: "youtube"
509
509
  color: "#ff0000"
@@ -17,11 +17,12 @@ class SocialNetsDB
17
17
 
18
18
  attr_accessor :uid
19
19
 
20
- [:color, :domain, :icons, :name].each do |method_symbol|
21
- define_method(method_symbol) do
22
- to_h[method_symbol.to_s]
23
- end
24
- end
20
+ [:color, :domain, :icons, :name, :tags].each do |method_symbol|
21
+ define_method(method_symbol) do
22
+ fallback_value = method_symbol == :tags ? [] : nil
23
+ @data.fetch(method_symbol.to_s, fallback_value)
24
+ end
25
+ end
25
26
 
26
27
  def to_h
27
28
  self.class.send :raw_data_for, @uid
@@ -38,10 +39,10 @@ class SocialNetsDB
38
39
 
39
40
  if username && page["by_username"]
40
41
  fail ArgumentError, "Either a username or an account id must be provided" unless present_str?(username)
41
- template.sub("${domain}", domain).sub("${uid}", username)
42
+ template.sub("${domain}", domain.to_s).sub("${uid}", username)
42
43
  elsif account_id && page["by_account_id"]
43
44
  fail ArgumentError, "Either a username or an account id must be provided" unless present_str?(account_id)
44
- template.sub("${domain}", domain).sub("${uid}", account_id)
45
+ template.sub("${domain}", domain.to_s).sub("${uid}", account_id)
45
46
  end
46
47
  end
47
48
 
@@ -92,15 +93,15 @@ class SocialNetsDB
92
93
  end
93
94
 
94
95
  def names
95
- RECORDS.map { |uid, data| data[:name] }
96
+ RECORDS.map { |uid, data| data["name"] }
96
97
  end
97
98
 
98
99
  def uids
99
- RECORDS.map { |uid, data| data[:uid].to_s }
100
+ RECORDS.keys.map(&:to_s)
100
101
  end
101
102
 
102
103
  def values_for_select
103
- RECORDS.map { |uid, data| [data[:name], uid] }
104
+ RECORDS.map { |uid, data| [data["name"], uid] }
104
105
  end
105
106
 
106
107
  alias_method :find, :find_by_uid
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class SocialNetsDB
4
- VERSION = "0.0.2".freeze
4
+ VERSION = "0.0.6".freeze
5
5
  end
@@ -8,19 +8,20 @@
8
8
  require_relative "lib/social_nets_db/version"
9
9
 
10
10
  Gem::Specification.new do |spec|
11
- spec.name = "social_nets_db"
12
- spec.version = SocialNetsDB::VERSION
13
- spec.authors = ["Sergey Pedan"]
14
- spec.email = ["sergey.pedan@gmail.com"]
15
- spec.license = "MIT"
16
-
17
- spec.summary = "A non-comprehensive database of social nets packed in a Ruby gem"
18
- spec.description = "#{spec.summary}. We have helpers for color, user page URL, FontAwesome icon, social net domain, some tags for grouping social nets, etc."
19
-
20
- spec.homepage = "https://github.com/sergeypedan/social-nets-db"
21
- spec.metadata = { "changelog_uri" => "https://github.com/sergeypedan/social-nets-db/blob/master/CHANGELOG.md",
22
- "homepage_uri" => spec.homepage,
23
- "source_code_uri" => "https://github.com/sergeypedan/social-nets-db.git"}
11
+ spec.name = "social_nets_db"
12
+ spec.version = SocialNetsDB::VERSION
13
+ spec.authors = ["Sergey Pedan"]
14
+ spec.email = ["sergey.pedan@gmail.com"]
15
+ spec.license = "MIT"
16
+
17
+ spec.summary = "A non-comprehensive database of social nets packed in a Ruby gem"
18
+ spec.description = "#{spec.summary}. We have helpers for color, user page URL, FontAwesome icon, social net domain, some tags for grouping social nets, etc."
19
+
20
+ spec.homepage = "https://sergeypedan.ru/open_source_projects/social-nets-db"
21
+ spec.metadata = { "changelog_uri" => "https://github.com/sergeypedan/social-nets-db/blob/master/CHANGELOG.md",
22
+ "documentation_uri" => "https://www.rubydoc.info/gems/#{spec.name}",
23
+ "homepage_uri" => spec.homepage,
24
+ "source_code_uri" => "https://github.com/sergeypedan/social-nets-db" }
24
25
 
25
26
  spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
26
27
  spec.rdoc_options = ["--charset=UTF-8"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_nets_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Pedan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-02 00:00:00.000000000 Z
11
+ date: 2021-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -146,13 +146,14 @@ files:
146
146
  - lib/social_nets_db/tag_helper.rb
147
147
  - lib/social_nets_db/version.rb
148
148
  - social_nets_db.gemspec
149
- homepage: https://github.com/sergeypedan/social-nets-db
149
+ homepage: https://sergeypedan.ru/open_source_projects/social-nets-db
150
150
  licenses:
151
151
  - MIT
152
152
  metadata:
153
153
  changelog_uri: https://github.com/sergeypedan/social-nets-db/blob/master/CHANGELOG.md
154
- homepage_uri: https://github.com/sergeypedan/social-nets-db
155
- source_code_uri: https://github.com/sergeypedan/social-nets-db.git
154
+ documentation_uri: https://www.rubydoc.info/gems/social_nets_db
155
+ homepage_uri: https://sergeypedan.ru/open_source_projects/social-nets-db
156
+ source_code_uri: https://github.com/sergeypedan/social-nets-db
156
157
  post_install_message:
157
158
  rdoc_options:
158
159
  - "--charset=UTF-8"