class AssetsInclude::Base
Attributes
asset_hosts[RW]
binary[RW]
bundled[RW]
cache[R]
cache_boosters[RW]
config[RW]
root[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/assets_include/base.rb, line 9 def initialize(options = {}) @cache = Cache.new @config = default_assets_location @bundled = production? @cache_boosters = true options.each do |key, value| public_send("#{key}=", value) end end
Public Instance Methods
group(locator, options = {})
click to toggle source
# File lib/assets_include/base.rb, line 20 def group(locator, options = {}) assets(locator, options) end
inline(locator)
click to toggle source
# File lib/assets_include/base.rb, line 28 def inline(locator) assets(locator, inline: true) end
list(locator)
click to toggle source
# File lib/assets_include/base.rb, line 24 def list(locator) assets(locator, list: true).strip.split(',') end
reset()
click to toggle source
# File lib/assets_include/base.rb, line 32 def reset cache.empty end
Private Instance Methods
asset_hosts_switch()
click to toggle source
# File lib/assets_include/base.rb, line 114 def asset_hosts_switch asset_hosts ? "-a #{asset_hosts}" : nil end
assets(locator, options)
click to toggle source
# File lib/assets_include/base.rb, line 40 def assets(locator, options) cache.empty unless bundled cache.add("#{locator}-#{options.to_s.hash}") do IO.popen(command(locator, options).join(' ')).read end end
binary_locations()
click to toggle source
# File lib/assets_include/base.rb, line 78 def binary_locations [ File.join(implicit_root, '..', 'node_modules', '.bin', 'assetsinc'), File.join(implicit_root, 'node_modules', '.bin', 'assetsinc'), 'assetsinc' ] end
bundled_switch()
click to toggle source
# File lib/assets_include/base.rb, line 98 def bundled_switch bundled ? '-b' : nil end
cache_boosters_switch()
click to toggle source
# File lib/assets_include/base.rb, line 102 def cache_boosters_switch cache_boosters ? '-s' : nil end
command(locator, options = {})
click to toggle source
# File lib/assets_include/base.rb, line 56 def command(locator, options = {}) parts = [] parts << includer_binary parts << root_switch parts << config_switch parts << bundled_switch parts << cache_boosters_switch parts << list_switch(options) parts << inline_switch(options) parts << asset_hosts_switch parts << loading_mode_switch(options) parts << locator parts.compact end
config_switch()
click to toggle source
# File lib/assets_include/base.rb, line 94 def config_switch "-c #{config}" end
default_assets_location()
click to toggle source
# File lib/assets_include/base.rb, line 48 def default_assets_location File.join(Dir.pwd, 'assets.yml') end
implicit_root()
click to toggle source
# File lib/assets_include/base.rb, line 86 def implicit_root root || File.join(Dir.pwd, 'public') end
includer_binary()
click to toggle source
# File lib/assets_include/base.rb, line 71 def includer_binary @binary ||= binary_locations.find { |path| IO.popen("which #{path}") $?.to_i == 0 } end
inline_switch(options = {})
click to toggle source
# File lib/assets_include/base.rb, line 110 def inline_switch(options = {}) options[:inline] ? '-i' : nil end
list_switch(options = {})
click to toggle source
# File lib/assets_include/base.rb, line 106 def list_switch(options = {}) options[:list] ? '-l' : nil end
loading_mode_switch(options = {})
click to toggle source
# File lib/assets_include/base.rb, line 118 def loading_mode_switch(options = {}) options[:loading_mode] ? "-m #{options[:loading_mode]}" : nil end
production?()
click to toggle source
# File lib/assets_include/base.rb, line 52 def production? ENV['RACK_ENV'] == 'production' end
root_switch()
click to toggle source
# File lib/assets_include/base.rb, line 90 def root_switch root ? "-r #{root}" : nil end