Class: Gluey::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/gluey/base/environment.rb

Direct Known Subclasses

Warehouse, Workshop

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**opts, &block) ⇒ Environment

Returns a new instance of Environment.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gluey/base/environment.rb', line 8

def initialize(**opts, &block)
  opts = {
      base_url: nil,
      path_prefix: '/assets'
  }.merge! opts

  opts.each do |k, value|
    next unless k.is_a? Symbol
    instance_variable_set "@#{k}", value
  end
  instance_exec &block if block

  root || raise('Root directory not defined!')
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



5
6
7
# File 'lib/gluey/base/environment.rb', line 5

def base_url
  @base_url
end

#mark_versionsObject

Returns the value of attribute mark_versions.



6
7
8
# File 'lib/gluey/base/environment.rb', line 6

def mark_versions
  @mark_versions
end

#path_prefixObject (readonly)

Returns the value of attribute path_prefix.



5
6
7
# File 'lib/gluey/base/environment.rb', line 5

def path_prefix
  @path_prefix
end

#rootObject (readonly)

Returns the value of attribute root.



5
6
7
# File 'lib/gluey/base/environment.rb', line 5

def root
  @root
end

Instance Method Details

#[](material, path, mark = nil) ⇒ Object Also known as: find_asset_file



27
28
29
# File 'lib/gluey/base/environment.rb', line 27

def [](material, path, mark=nil)
  fetch(material, path, mark)[0]
end

#asset_url(material, path) ⇒ Object



23
24
25
# File 'lib/gluey/base/environment.rb', line 23

def asset_url(material, path)
  "#{base_url}#{path_prefix}/#{material}/#{real_path material, path}"
end