Class: Secretary::Gopher

Inherits:
Object
  • Object
show all
Defined in:
lib/secretary/gopher.rb

Overview

Requires one of the following:

  • parse_file

  • load_from_file

As well as one of the following:

  • emit

  • save_into_file_path

You may override the following:

  • validate

  • raw

  • cook

  • parse_file

  • load_from_file

  • emit

  • save_into_file_path

Direct Known Subclasses

YAML

Defined Under Namespace

Classes: YAML

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Gopher

Returns a new instance of Gopher.



30
31
32
# File 'lib/secretary/gopher.rb', line 30

def initialize options={}
	@options = options
end

Class Attribute Details

.file_typeObject (readonly)

Returns the value of attribute file_type.



26
27
28
# File 'lib/secretary/gopher.rb', line 26

def file_type
  @file_type
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



24
25
26
# File 'lib/secretary/gopher.rb', line 24

def options
  @options
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
# File 'lib/secretary/gopher.rb', line 38

def == other
  self.class == other.class
end

#cook(data) ⇒ Object



69
70
71
# File 'lib/secretary/gopher.rb', line 69

def cook data
	data
end

#file_typeObject



34
35
36
# File 'lib/secretary/gopher.rb', line 34

def file_type
  self.class.file_type
end

#load(file_path) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/secretary/gopher.rb', line 42

def load file_path
  if File.exist? file_path
	file_data = load_from_file_path file_path
  else
    raise Secretary::Error::MissingFile.new(file_path)
  end
  unless validate file_data
    raise Secretary::Error::InvalidData.new(file_data)
  end
return cook(file_data)
end

#raw(data) ⇒ Object



65
66
67
# File 'lib/secretary/gopher.rb', line 65

def raw data
	data
end

#save(data, file_path) ⇒ Object



54
55
56
57
58
59
# File 'lib/secretary/gopher.rb', line 54

def save(data, file_path)
  unless validate data then raise ArgumentError,
	"invalid data #{data} is not a kind of #{data_type}"
end
save_into_file_path raw(data), file_path
end

#validate(data) ⇒ Object



61
62
63
# File 'lib/secretary/gopher.rb', line 61

def validate data
	true
end