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.



22
23
24
# File 'lib/web_resource_bundler.rb', line 22

def filters
  @filters
end

.loggerObject (readonly)

Returns the value of attribute logger.



22
23
24
# File 'lib/web_resource_bundler.rb', line 22

def logger
  @logger
end

Class Method Details

.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



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

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



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

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



25
26
27
28
29
30
31
# File 'lib/web_resource_bundler.rb', line 25

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