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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e107bb63fce06c5a6b8a7586d1611a5c895d0e9024d8673d91f81b0dd0317457
4
- data.tar.gz: 577d1773371f445ad842febe0461d154452eb80072e5c42c95449d3ef0849d0f
3
+ metadata.gz: 368f88420ff308175a8b21b0e8f50134ff428b610b980bc622b2bc376d6224ef
4
+ data.tar.gz: c3e86db5681154bb1b94bed65acf8c26ac92bf93d28019d7dc933bc16dbe52ef
5
5
  SHA512:
6
- metadata.gz: b866434ab12f26823a89081dfa19b2d508d97fbddd8920ec7630fc525dd653b7c8b3e9fafd15c4239fd71023a34a2e73c07bf6d49940a2d3832d5638e168701a
7
- data.tar.gz: f7481afb25a4b285975ff5a009c9fa358de68a57ef724aa6a377ecc92d31ac5ffd1a09f0083becaf8da2ad624e5dcaab29f7c1d153b7dc98f0acb0343dd8542b
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) || raise(VariantNotFound)
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"
@@ -2,6 +2,7 @@ module NamedVariant
2
2
  class Railtie < ::Rails::Railtie
3
3
  ActiveSupport.on_load(:active_record) do
4
4
  ActiveRecord::Base.extend ::NamedVariant::ActiveRecordExtension
5
+ ActiveStorage::Attachment.prepend ::NamedVariant::VariantExtension
5
6
  end
6
7
 
7
8
  config.after_initialize do
@@ -1,3 +1,3 @@
1
1
  module NamedVariant
2
- VERSION = "0.1.2".freeze
2
+ VERSION = "0.1.3".freeze
3
3
  end
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.2
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-08-23 00:00:00.000000000 Z
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: mini_magick
42
+ name: image_processing
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="