Class: S3Direct::StringInterpolator

Inherits:
Object
  • Object
show all
Defined in:
lib/s3direct/string_interpolator.rb

Constant Summary collapse

DELIM =
"/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, pattern) ⇒ StringInterpolator

Returns a new instance of StringInterpolator.



7
8
9
10
# File 'lib/s3direct/string_interpolator.rb', line 7

def initialize(context, pattern)
  @pattern = pattern
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/s3direct/string_interpolator.rb', line 5

def context
  @context
end

#patternObject (readonly)

Returns the value of attribute pattern.



5
6
7
# File 'lib/s3direct/string_interpolator.rb', line 5

def pattern
  @pattern
end

Instance Method Details

#compile_partsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/s3direct/string_interpolator.rb', line 16

def compile_parts
  pattern.split(DELIM).collect do |part|
    if part[0] == ':'
      meth = part[1, part.length - 1]
      result = context.public_send meth
      if result.blank?
        raise ":#{meth} for path '#{pattern}' was blank in #{context.inspect}"
      end
      result.to_s.underscore
    else
      part
    end
  end
end

#to_sObject



12
13
14
# File 'lib/s3direct/string_interpolator.rb', line 12

def to_s
  compile_parts.join(DELIM)
end