Class: Ecm::Cms::ImportPartialsService::PartialInFileSystem

Inherits:
Object
  • Object
show all
Defined in:
app/services/ecm/cms/import_partials_service.rb

Instance Method Summary collapse

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

#basenameObject



13
14
15
# File 'app/services/ecm/cms/import_partials_service.rb', line 13

def basename
  @basename ||= File.basename(relative_filename).split('.').first
end

#bodyObject



36
37
38
# File 'app/services/ecm/cms/import_partials_service.rb', line 36

def body
  File.read(@filename)
end

#formatObject



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

#handlerObject



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

#humanObject



51
52
53
# File 'app/services/ecm/cms/import_partials_service.rb', line 51

def human
  "#{relative_filename} (#{body.size} bytes)"
end

#localeObject



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

#pathnameObject



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_hashObject



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