Class: Isomorfeus::AssetManager::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/isomorfeus/asset_manager/asset.rb

Direct Known Subclasses

BrowserAsset, NodeAsset

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target = :browser) ⇒ Asset

Returns a new instance of Asset.



16
17
18
19
20
21
22
23
24
# File 'lib/isomorfeus/asset_manager/asset.rb', line 16

def initialize(target = :browser)
  @target = target
  @mutex = Mutex.new
  @bundled = false
  @bundle_ruby_modules = {}
  @hash = { css: {}, js: {}}
  @js_imports = []
  @ruby_imports = []
end

Instance Attribute Details

#bundle_ruby_modulesObject (readonly)

Returns the value of attribute bundle_ruby_modules.



13
14
15
# File 'lib/isomorfeus/asset_manager/asset.rb', line 13

def bundle_ruby_modules
  @bundle_ruby_modules
end

#hashObject (readonly)

Returns the value of attribute hash.



13
14
15
# File 'lib/isomorfeus/asset_manager/asset.rb', line 13

def hash
  @hash
end

#js_importsObject (readonly)

Returns the value of attribute js_imports.



14
15
16
# File 'lib/isomorfeus/asset_manager/asset.rb', line 14

def js_imports
  @js_imports
end

#mtimeObject (readonly)

Returns the value of attribute mtime.



14
15
16
# File 'lib/isomorfeus/asset_manager/asset.rb', line 14

def mtime
  @mtime
end

#mutexObject (readonly)

Returns the value of attribute mutex.



14
15
16
# File 'lib/isomorfeus/asset_manager/asset.rb', line 14

def mutex
  @mutex
end

#ruby_importsObject (readonly)

Returns the value of attribute ruby_imports.



14
15
16
# File 'lib/isomorfeus/asset_manager/asset.rb', line 14

def ruby_imports
  @ruby_imports
end

#targetObject (readonly)

Returns the value of attribute target.



13
14
15
# File 'lib/isomorfeus/asset_manager/asset.rb', line 13

def target
  @target
end

Class Method Details

._original_newObject



5
# File 'lib/isomorfeus/asset_manager/asset.rb', line 5

alias_method :_original_new, :new

.new(target = :browser) ⇒ Object



6
7
8
9
10
# File 'lib/isomorfeus/asset_manager/asset.rb', line 6

def new(target = :browser)
  return BrowserAsset.new if target == :browser
  return NodeAsset.new if target == :node
  raise "unknown target #{traget}"
end

Instance Method Details

#add_js_import(*args) ⇒ Object Also known as: add_css_import



34
35
36
# File 'lib/isomorfeus/asset_manager/asset.rb', line 34

def add_js_import(*args)
  @js_imports << Isomorfeus::AssetManager::JsImport.new(*args)
end

#add_ruby_import(*args) ⇒ Object



39
40
41
# File 'lib/isomorfeus/asset_manager/asset.rb', line 39

def add_ruby_import(*args)
  @ruby_imports << Isomorfeus::AssetManager::RubyImport.new(*args)
end

#browser?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/isomorfeus/asset_manager/asset.rb', line 26

def browser?
  target == :browser
end

#bundleObject



43
44
45
# File 'lib/isomorfeus/asset_manager/asset.rb', line 43

def bundle
  @hash[:js][:js][:raw]
end

#bundled!Object



51
52
53
# File 'lib/isomorfeus/asset_manager/asset.rb', line 51

def bundled!
  @bundled = true
end

#bundled?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/isomorfeus/asset_manager/asset.rb', line 47

def bundled?
  @bundled
end

#node?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/isomorfeus/asset_manager/asset.rb', line 30

def node?
  target == :node
end

#touchObject



59
60
61
# File 'lib/isomorfeus/asset_manager/asset.rb', line 59

def touch
  @mtime = (Time.now.to_f * (10 ** 9)).to_i
end

#unbundle!Object



55
56
57
# File 'lib/isomorfeus/asset_manager/asset.rb', line 55

def unbundle!
  @bundled = false
end