Class: ArchiveStorage::MountConfig
- Inherits:
-
Object
- Object
- ArchiveStorage::MountConfig
- Defined in:
- lib/archive_storage/mount_config.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#mounted_as ⇒ Object
readonly
Returns the value of attribute mounted_as.
-
#policy ⇒ Object
readonly
Returns the value of attribute policy.
-
#uploader ⇒ Object
readonly
Returns the value of attribute uploader.
Instance Method Summary collapse
-
#initialize(model, mounted_as, uploader: nil, policy: nil) ⇒ MountConfig
constructor
A new instance of MountConfig.
- #matches_model?(value, mounted_as_value = nil) ⇒ Boolean
- #matches_uploader?(value) ⇒ Boolean
- #model_class ⇒ Object
- #model_name ⇒ Object
- #uploader_class ⇒ Object
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
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/archive_storage/mount_config.rb', line 5 def model @model end |
#mounted_as ⇒ Object (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 |
#policy ⇒ Object (readonly)
Returns the value of attribute policy.
5 6 7 |
# File 'lib/archive_storage/mount_config.rb', line 5 def policy @policy end |
#uploader ⇒ Object (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
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
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_class ⇒ Object
14 15 16 |
# File 'lib/archive_storage/mount_config.rb', line 14 def model_class constantize(model) end |
#model_name ⇒ Object
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_class ⇒ Object
22 23 24 |
# File 'lib/archive_storage/mount_config.rb', line 22 def uploader_class constantize(uploader) if uploader end |