Class: Ecm::Cms::ImportPartialsService::PartialInFileSystem
- Inherits:
-
Object
- Object
- Ecm::Cms::ImportPartialsService::PartialInFileSystem
- Defined in:
- app/services/ecm/cms/import_partials_service.rb
Instance Method Summary collapse
- #basename ⇒ Object
- #body ⇒ Object
- #format ⇒ Object
- #handler ⇒ Object
- #human ⇒ Object
-
#initialize(filename, view_path) ⇒ PartialInFileSystem
constructor
A new instance of PartialInFileSystem.
- #locale ⇒ Object
- #pathname ⇒ Object
- #to_partial_attributes_hash ⇒ Object
Constructor Details
#initialize(filename, view_path) ⇒ PartialInFileSystem
Returns a new instance of PartialInFileSystem.
4 5 6 7 |
# File 'app/services/ecm/cms/import_partials_service.rb', line 4 def initialize(filename, view_path) @filename = filename @view_path = view_path end |
Instance Method Details
#basename ⇒ Object
13 14 15 |
# File 'app/services/ecm/cms/import_partials_service.rb', line 13 def basename @basename ||= File.basename(relative_filename).split('.').first end |
#body ⇒ Object
36 37 38 |
# File 'app/services/ecm/cms/import_partials_service.rb', line 36 def body File.read(@filename) end |
#format ⇒ Object
24 25 26 27 |
# File 'app/services/ecm/cms/import_partials_service.rb', line 24 def format format = File.basename(relative_filename).split('.')[-2] @format ||= format if Mime::SET.symbols.map(&:to_s).include?(format) end |
#handler ⇒ Object
29 30 31 32 33 34 |
# File 'app/services/ecm/cms/import_partials_service.rb', line 29 def handler handler = File.basename(relative_filename).split('.').last if ActionView::Template::Handlers.extensions.map(&:to_s).include?(handler) @handler ||= handler end end |
#human ⇒ Object
51 52 53 |
# File 'app/services/ecm/cms/import_partials_service.rb', line 51 def human "#{relative_filename} (#{body.size} bytes)" end |
#locale ⇒ Object
17 18 19 20 21 22 |
# File 'app/services/ecm/cms/import_partials_service.rb', line 17 def locale locale = File.basename(relative_filename).split('.')[-3] if I18n.available_locales.map(&:to_s).include?(locale) @locale ||= locale end end |
#pathname ⇒ Object
9 10 11 |
# File 'app/services/ecm/cms/import_partials_service.rb', line 9 def pathname @pathname ||= "#{File.dirname(relative_filename)}/" end |
#to_partial_attributes_hash ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'app/services/ecm/cms/import_partials_service.rb', line 40 def to_partial_attributes_hash { pathname: pathname, basename: basename, locale: locale, format: format, handler: handler, body: body } end |