Class: WebResourceBundler::Bundler

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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.filtersObject (readonly)

Returns the value of attribute filters.



25
26
27
# File 'lib/web_resource_bundler.rb', line 25

def filters
  @filters
end

.loggerObject (readonly)

Returns the value of attribute logger.



25
26
27
# File 'lib/web_resource_bundler.rb', line 25

def logger
  @logger
end

Class Method Details

.logger_error(message) ⇒ Object



86
87
88
# File 'lib/web_resource_bundler.rb', line 86

def logger_error(message)
  logger.error("[web_resource_bundler]: #{message}")
end

.logger_info(message) ⇒ Object



82
83
84
# File 'lib/web_resource_bundler.rb', line 82

def logger_info(message)
  logger.info("[web_resource_bundler]: #{message}")
end

.process(block, domain, protocol) ⇒ Object

main method to process html text block filters settings changed with request specific data html block parsed, and resulted bundle file names calculated we don’t want to read files from disk on each request if bundle is not up to date block_data populated with files content all filters applied and resulted block_data returnd all exceptions resqued and logged so that no exceptions are raised in rails app



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/web_resource_bundler.rb', line 57

def process(block, domain, protocol)
  return nil unless Settings.correct? 
  begin
    block_data = BlockParser.parse(block)
    filters    = filters_array(@filters)
    set_filters_request_specific_data!(filters, domain, protocol)
    if filters.any? && !bundle_upto_date?(block_data, @filters)
      read_resources!(block_data)
      block_data.apply_filters(filters)
      write_files_on_disk(block_data)
      logger_info("files written on disk")
      return block_data
    end
    block_data.apply_filters(filters)
    block_data
  rescue Exception => e
    logger_error("Error occured: " + e.to_s)
    nil
  end
end

.set_settings(settings) ⇒ Object

this method should be used to turn onoff filters on particular specific request



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/web_resource_bundler.rb', line 37

def set_settings(settings)
  begin
    return false unless Settings.correct?(settings)
    Settings.set(settings)
    set_filters(@filters, @file_manager)
    @file_manager.set_settings(settings) 
    true
  rescue Exception => e
    logger_error("Error occured while trying to change settings")
    false
  end
end

.setup(rails_root, rails_env) ⇒ Object

this method should called in initializer



28
29
30
31
32
33
# File 'lib/web_resource_bundler.rb', line 28

def setup(rails_root, rails_env)
  settings = Settings.create_settings(rails_root, rails_env)
  return false unless Settings.correct? 
  @file_manager = FileManager.new(settings)
  @filters      = set_filters({}, @file_manager)
end