Class: HTTPong::Scheme

Inherits:
Object
  • Object
show all
Defined in:
lib/httpong/scheme.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Scheme

Returns a new instance of Scheme.



8
9
10
11
12
# File 'lib/httpong/scheme.rb', line 8

def initialize(path)
  @path = path
  reload
  HTTPong.schemes << self
end

Instance Attribute Details

#cson_pathObject (readonly)

Returns the value of attribute cson_path.



5
6
7
# File 'lib/httpong/scheme.rb', line 5

def cson_path
  @cson_path
end

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/httpong/scheme.rb', line 3

def data
  @data
end

#pathObject (readonly) Also known as: json_path

Returns the value of attribute path.



4
5
6
# File 'lib/httpong/scheme.rb', line 4

def path
  @path
end

Instance Method Details

#nameObject



14
15
16
# File 'lib/httpong/scheme.rb', line 14

def name
  @data['name']
end

#reloadObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/httpong/scheme.rb', line 18

def reload
  if path.end_with? 'cson'
    json_path = "#{@path.chomp('cson')}json"
    `cson2json #{@path} > #{json_path}`
    @cson_path = @path
    @json_path = json_path
  else
    @json_path = @path
  end
  file = File.read(@json_path)
  @data = JSON.parse(file)
end

#to_jsonObject



31
32
33
# File 'lib/httpong/scheme.rb', line 31

def to_json
  JSON.generate(@data)
end