Module: Card::Env::Location

Extended by:
Location
Included in:
Location, Success, Format, CarrierWave::FileCardUploader
Defined in:
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 '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 =~ %r{^(https?\:)?/}
    rel_path
  else
    "#{Card.config.relative_url_root}/#{rel_path}"
  end
end

#card_url(rel) ⇒ Object



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

def card_url rel
  rel =~ /^https?\:/ ? rel : "#{protocol_and_host}#{card_path rel}"
end

#cardname_from_url(url) ⇒ Object



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

def cardname_from_url url
  m = url.match cardname_from_url_regexp
  m ? Card::Name[m[:mark]] : nil
end

#protocol_and_hostObject



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

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