named_variant 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/named_variant.rb +14 -15
- data/lib/named_variant/railtie.rb +1 -0
- data/lib/named_variant/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 368f88420ff308175a8b21b0e8f50134ff428b610b980bc622b2bc376d6224ef
|
4
|
+
data.tar.gz: c3e86db5681154bb1b94bed65acf8c26ac92bf93d28019d7dc933bc16dbe52ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50422446c29f354b76c9cbb452771954d4172b1478d878c4c9d1f94664af7eb5a12c588801b0f7908d223aa25419b6deb190f9148866804ece9571188ca6fae2
|
7
|
+
data.tar.gz: 5014ba51e8e8864a0ece7b7dbb2d8e165f73e1b9a7311f9e68ce55b9d386f0d6ea9092c4bb3f9e9323a736d90f6c05eed0da58ebc8471668c8267ebfaeff8c63
|
data/lib/named_variant.rb
CHANGED
@@ -1,15 +1,25 @@
|
|
1
|
-
require "named_variant/railtie"
|
2
|
-
|
3
1
|
module NamedVariant
|
4
2
|
mattr_reader :named_variants, default: {}
|
5
3
|
|
4
|
+
def self.find_named_variant_for!(klass: nil, sym:)
|
5
|
+
# NOTE: name params
|
6
|
+
named_variants["#{klass}/#{sym}"] || named_variants[sym.to_s] || raise(VariantNotFound, "class: #{klass}, sym: #{sym}")
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.add_variant(name, opts)
|
10
|
+
named_variants[name.to_s] = Variant.new(opts)
|
11
|
+
end
|
12
|
+
|
13
|
+
class VariantNotFound < StandardError
|
14
|
+
end
|
15
|
+
|
6
16
|
module VariantExtension
|
7
17
|
# prepend ActiveStorage::Blob::Representable#variant
|
8
18
|
# https://github.com/rails/rails/blob/3c823271af52a61e825123def170fe2187057577/activestorage/app/models/active_storage/blob/representable.rb#L28
|
9
19
|
def variant(args)
|
10
20
|
if args.is_a?(Symbol)
|
11
21
|
# self is ActiveStorage::Attached::One
|
12
|
-
named_variant = ::NamedVariant.find_named_variant_for(klass: self.record.class, sym: args)
|
22
|
+
named_variant = ::NamedVariant.find_named_variant_for!(klass: self.record.class, sym: args)
|
13
23
|
return super(named_variant.to_h)
|
14
24
|
end
|
15
25
|
|
@@ -22,18 +32,7 @@ module NamedVariant
|
|
22
32
|
::NamedVariant.add_variant("#{self}/#{name}", opts) ## key looks like: User/xsmall
|
23
33
|
end
|
24
34
|
end
|
25
|
-
|
26
|
-
def self.find_named_variant_for(klass: nil, sym:)
|
27
|
-
# NOTE: name params
|
28
|
-
named_variants["#{klass}/#{sym}"] || named_variants[sym.to_s]
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.add_variant(name, opts)
|
32
|
-
named_variants[name.to_s] = Variant.new(opts)
|
33
|
-
end
|
34
|
-
|
35
|
-
class VariantNotFound < StandardError
|
36
|
-
end
|
37
35
|
end
|
38
36
|
|
39
37
|
require "named_variant/variant"
|
38
|
+
require "named_variant/railtie"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: named_variant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yukito Ito
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activestorage
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: image_processing
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|