Module: Card::Env::Location

Extended by:
Location
Included in:
Location, Success, Format, CardController, CarrierWave::FileCardUploader
Defined in:
card/lib/card/env/location.rb

Instance Method Summary collapse

Instance Method Details

#card_path(rel_path) ⇒ Object

card_path makes a relative path site-absolute (if not already) card_url makes it a full url (if not already)



7
8
9
10
11
12
13
14
15
16
17
# File 'card/lib/card/env/location.rb', line 7

def card_path rel_path
  unless rel_path.is_a? String
    Rails.logger.warn "Pass only strings to card_path. "\
                      "(#{rel_path} = #{rel_path.class})"
  end
  if rel_path.match? %r{^(https?:)?/}
    rel_path
  else
    "#{Card.config.relative_url_root}/#{rel_path}"
  end
end

#card_url(rel) ⇒ Object



19
20
21
# File 'card/lib/card/env/location.rb', line 19

def card_url rel
  rel.match?(/^https?:/) ? rel : "#{protocol_and_host}#{card_path rel}"
end

#cardname_from_url(url) ⇒ Object



27
28
29
30
31
32
# File 'card/lib/card/env/location.rb', line 27

def cardname_from_url url
  return unless (cardname = cardname_from_url_regexp)

  m = url.match cardname
  m ? Card::Name[m[:mark]] : nil
end

#protocol_and_hostObject



23
24
25
# File 'card/lib/card/env/location.rb', line 23

def protocol_and_host
  Card.config.protocol_and_host || "#{Env[:protocol]}#{Env[:host]}"
end