Class: ArchiveStorage::MountConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/archive_storage/mount_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, mounted_as, uploader: nil, policy: nil) ⇒ MountConfig

Returns a new instance of MountConfig.



7
8
9
10
11
12
# File 'lib/archive_storage/mount_config.rb', line 7

def initialize(model, mounted_as, uploader: nil, policy: nil)
  @model = model
  @mounted_as = mounted_as.to_sym
  @uploader = uploader
  @policy = policy
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/archive_storage/mount_config.rb', line 5

def model
  @model
end

#mounted_asObject (readonly)

Returns the value of attribute mounted_as.



5
6
7
# File 'lib/archive_storage/mount_config.rb', line 5

def mounted_as
  @mounted_as
end

#policyObject (readonly)

Returns the value of attribute policy.



5
6
7
# File 'lib/archive_storage/mount_config.rb', line 5

def policy
  @policy
end

#uploaderObject (readonly)

Returns the value of attribute uploader.



5
6
7
# File 'lib/archive_storage/mount_config.rb', line 5

def uploader
  @uploader
end

Instance Method Details

#matches_model?(value, mounted_as_value = nil) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
# File 'lib/archive_storage/mount_config.rb', line 26

def matches_model?(value, mounted_as_value = nil)
  model_matches = model_name == (value.respond_to?(:name) ? value.name : value.to_s)
  mount_matches = mounted_as_value.nil? || mounted_as == mounted_as_value.to_sym

  model_matches && mount_matches
end

#matches_uploader?(value) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
# File 'lib/archive_storage/mount_config.rb', line 33

def matches_uploader?(value)
  return true if value.nil?

  expected = uploader_class || value
  expected.to_s == value.to_s ||
    (expected.respond_to?(:name) && expected.name == value.to_s)
end

#model_classObject



14
15
16
# File 'lib/archive_storage/mount_config.rb', line 14

def model_class
  constantize(model)
end

#model_nameObject



18
19
20
# File 'lib/archive_storage/mount_config.rb', line 18

def model_name
  model.respond_to?(:name) ? model.name : model.to_s
end

#uploader_classObject



22
23
24
# File 'lib/archive_storage/mount_config.rb', line 22

def uploader_class
  constantize(uploader) if uploader
end