Class: BocaGolf::Gist

Inherits:
Object
  • Object
show all
Defined in:
lib/boca_golf/gist.rb

Constant Summary collapse

URI_REGEXP =
URI.regexp(['http', 'https', 'ftp'])

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ Gist

Returns a new instance of Gist.



23
24
25
# File 'lib/boca_golf/gist.rb', line 23

def initialize(code)
  @code = code
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/boca_golf/gist.rb', line 3

def code
  @code
end

Class Method Details

.load_from_file(file) ⇒ Object



19
20
21
# File 'lib/boca_golf/gist.rb', line 19

def self.load_from_file(file)
  new File.read(file)
end

.load_from_location(location) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/boca_golf/gist.rb', line 7

def self.load_from_location(location)
  if location =~ URI_REGEXP
    load_from_url location
  else
    load_from_file location
  end
end

.load_from_url(gist_url) ⇒ Object



15
16
17
# File 'lib/boca_golf/gist.rb', line 15

def self.load_from_url(gist_url)
  new URI.parse(gist_url + ".txt").read
end

Instance Method Details

#safe_moduleObject



27
28
29
30
31
32
# File 'lib/boca_golf/gist.rb', line 27

def safe_module
  Module.new.tap do |m|
    m.send :include, insecure_module
    m.send :include, proxy_module(insecure_module)
  end
end