Class: Gloo::WebSvr::AssetInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo/web_svr/asset_info.rb

Constant Summary collapse

@@index_by_published =

Class Variables

{}
@@index_by_pn =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engine, full_path, name, pn) ⇒ AssetInfo

Set up an asset information object.



33
34
35
36
37
38
39
40
# File 'lib/gloo/web_svr/asset_info.rb', line 33

def initialize( engine, full_path, name, pn )
  @engine = engine
  @log = @engine.log

  @full_path = full_path
  @name = name
  @pn = pn
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



23
24
25
# File 'lib/gloo/web_svr/asset_info.rb', line 23

def hash
  @hash
end

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/gloo/web_svr/asset_info.rb', line 23

def name
  @name
end

#pnObject (readonly)

Returns the value of attribute pn.



23
24
25
# File 'lib/gloo/web_svr/asset_info.rb', line 23

def pn
  @pn
end

#published_nameObject (readonly)

Returns the value of attribute published_name.



23
24
25
# File 'lib/gloo/web_svr/asset_info.rb', line 23

def published_name
  @published_name
end

#published_pnObject (readonly)

Returns the value of attribute published_pn.



23
24
25
# File 'lib/gloo/web_svr/asset_info.rb', line 23

def published_pn
  @published_pn
end

Class Method Details

.find_info_for(pn) ⇒ Object

Find the asset info for the given published name.



94
95
96
# File 'lib/gloo/web_svr/asset_info.rb', line 94

def self.find_info_for pn
  return @@index_by_published[ pn ]
end

.find_published_name_for(pn) ⇒ Object

Find the asset info for the given published name.



85
86
87
88
89
# File 'lib/gloo/web_svr/asset_info.rb', line 85

def self.find_published_name_for pn
  return nil unless pn

  return @@index_by_pn[ pn ]&.published_pn
end

.index(info) ⇒ Object

Index the the given asset info record.



75
76
77
78
79
80
# File 'lib/gloo/web_svr/asset_info.rb', line 75

def self.index info
  return unless info

  @@index_by_pn[ info.pn ] = info
  @@index_by_published[ info.published_pn ] = info
end

.list_all(engine) ⇒ Object

List All assets.



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/gloo/web_svr/asset_info.rb', line 101

def self.list_all engine
  data = []
  @@index_by_pn.each do |pn, info|
    data << [ info.name, info.pn, info.published_pn ]
  end
  headers = [ "Name", "Asset Path", "Published" ]

  puts Gloo::App::Platform::RETURN
  title = "Assets in Running Web App"
  engine.platform.table.show headers, data, title
  puts Gloo::App::Platform::RETURN
end

Instance Method Details

#registerObject

Register the asset with indexes, inflating all needed data elements.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/gloo/web_svr/asset_info.rb', line 50

def register
  @log.debug "*** REGISTERING ASSET: #{@name}"
  @log.debug "*** #{@full_path} "
  @log.debug "*** #PN: #{@pn} name: #{@name}"

  @hash = Gloo::Objs::FileHandle.hash_for_file( @full_path )

  # Build published name
  ext = File.extname( @pn )           # Gets just the extension
  n = @name[ 0..-ext.length - 1 ]
  pn = @pn[ 0..-ext.length - 1 ]

  @published_name = "#{n}-#{@hash}#{ext}"
  @published_pn = "#{pn}-#{@hash}#{ext}"

  @log.debug "*** Published Name: #{@published_name}"
  @log.debug "*** Published Path: #{@published_pn}"

  # Add to indexes
  AssetInfo.index self
end