Skip to content

Commit 81ee605

Browse files
committed
configuration options in Thread.current, #7
1 parent 0df73e9 commit 81ee605

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

lib/letter_avatar.rb

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
require "letter_avatar/version"
2+
require "letter_avatar/configuration"
23
require "letter_avatar/avatar"
34
require "letter_avatar/avatar_helper"
45

56
module LetterAvatar
6-
7-
mattr_accessor :cache_base_path
8-
@@cache_base_path = nil
9-
10-
mattr_accessor :colors_palette
11-
@@colors_palette = :google
12-
13-
mattr_accessor :weight
14-
@@weight = 300
15-
16-
mattr_accessor :annotate_position
17-
@@annotate_position = '-0+5'
7+
extend LetterAvatar::Configuration
188

199
def self.setup(&block)
2010
yield(self)

lib/letter_avatar/colors.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module LetterAvatar
22
module Colors
33

4+
PALETTES = [:google, :iwanthue]
5+
46
def self.for(username)
57
public_send("with_#{LetterAvatar.colors_palette}", username) rescue with_google(username)
68
end

lib/letter_avatar/configuration.rb

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require "letter_avatar/colors"
2+
3+
module LetterAvatar
4+
module Configuration
5+
6+
def cache_base_path
7+
Thread.current[:cache_base_path]
8+
end
9+
10+
def cache_base_path=(v)
11+
Thread.current[:cache_base_path] = v
12+
end
13+
14+
def colors_palette
15+
Thread.current[:colors_palette] ||= :google
16+
end
17+
18+
def colors_palette=(v)
19+
Thread.current[:colors_palette] = v if v.in?(Colors::PALETTES)
20+
end
21+
22+
def weight
23+
Thread.current[:weight] ||= 300
24+
end
25+
26+
def weight=(v)
27+
Thread.current[:weight] = v
28+
end
29+
30+
def annotate_position
31+
Thread.current[:annotate_position] ||= '-0+5'
32+
end
33+
34+
def annotate_position=(v)
35+
Thread.current[:annotate_position] = v
36+
end
37+
38+
end
39+
end

0 commit comments

Comments
 (0)