Class: Secretary::Gopher
- Inherits:
-
Object
- Object
- Secretary::Gopher
- 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
Defined Under Namespace
Classes: YAML
Class Attribute Summary collapse
-
.file_type ⇒ Object
readonly
Returns the value of attribute file_type.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #cook(data) ⇒ Object
- #file_type ⇒ Object
-
#initialize(options = {}) ⇒ Gopher
constructor
A new instance of Gopher.
- #load(file_path) ⇒ Object
- #raw(data) ⇒ Object
- #save(data, file_path) ⇒ Object
- #validate(data) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Gopher
Returns a new instance of Gopher.
30 31 32 |
# File 'lib/secretary/gopher.rb', line 30 def initialize ={} @options = end |
Class Attribute Details
.file_type ⇒ Object (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
#options ⇒ Object (readonly)
Returns the value of attribute options.
24 25 26 |
# File 'lib/secretary/gopher.rb', line 24 def @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_type ⇒ Object
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 |