Class: DeadSimpleCMS::Attribute::Type::File

Inherits:
Base
  • Object
show all
Defined in:
lib/dead_simple_cms/attribute/type/all.rb

Overview

Public: File attributes are stored at some publicly accessible url.

Direct Known Subclasses

Image

Constant Summary

Constants inherited from Base

Base::VALID_INPUT_TYPES

Instance Attribute Summary collapse

Attributes inherited from Base

#group_hierarchy, #input_type, #required, #section

Instance Method Summary collapse

Methods inherited from Base

#default, #hint, #inspect, #length, #root_group?, #section_identifier, #value, #value=

Constructor Details

#initialize(identifier, options = {}) ⇒ File

Returns a new instance of File.



85
86
87
88
89
# File 'lib/dead_simple_cms/attribute/type/all.rb', line 85

def initialize(identifier, options={})
  @data     = options[:data]
  @file_ext = options[:file_ext] || "dat"
  super
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



79
80
81
# File 'lib/dead_simple_cms/attribute/type/all.rb', line 79

def data
  @data
end

#file_extObject

Returns the value of attribute file_ext.



79
80
81
# File 'lib/dead_simple_cms/attribute/type/all.rb', line 79

def file_ext
  @file_ext
end

Instance Method Details

#upload!Object

Public: Takes the current #value, detects if its an object to upload and replaces the #value with the url to be stored in the CMS.

Raises:

  • (NotImplementedError)


93
94
95
96
97
98
99
100
# File 'lib/dead_simple_cms/attribute/type/all.rb', line 93

def upload!
  raise NotImplementedError, "Please define an uploader class (see DeadSimpleCMS::FileUploader::Base)" unless uploader_class
  return unless data

  s3_uploader = uploader_class.new(self)
  s3_uploader.upload!
  self.value = s3_uploader.url
end