Class: Paneron::Register::Raw::Item
- Inherits:
-
Object
- Object
- Paneron::Register::Raw::Item
- Defined in:
- lib/paneron/register/raw/item.rb
Instance Attribute Summary collapse
-
#extension ⇒ Object
readonly
Returns the value of attribute extension.
-
#item_class_path ⇒ Object
readonly
Returns the value of attribute item_class_path.
-
#item_id ⇒ Object
readonly
Returns the value of attribute item_id.
-
#item_path ⇒ Object
readonly
Returns the value of attribute item_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(item_class_path, item_id, extension = "yaml") ⇒ Item
constructor
A new instance of Item.
- #to_h ⇒ Object
- #to_lutaml ⇒ Object
Constructor Details
#initialize(item_class_path, item_id, extension = "yaml") ⇒ Item
Returns a new instance of Item.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/paneron/register/raw/item.rb', line 14 def initialize( item_class_path, item_id, extension = "yaml" ) item_path = File.join(item_class_path, "#{item_id}.#{extension}") self.class.validate_item_path(item_path) @item_class_path = item_class_path @item_id = item_id @item_path = item_path @extension = extension @to_h = nil end |
Instance Attribute Details
#extension ⇒ Object (readonly)
Returns the value of attribute extension.
9 10 11 |
# File 'lib/paneron/register/raw/item.rb', line 9 def extension @extension end |
#item_class_path ⇒ Object (readonly)
Returns the value of attribute item_class_path.
9 10 11 |
# File 'lib/paneron/register/raw/item.rb', line 9 def item_class_path @item_class_path end |
#item_id ⇒ Object (readonly)
Returns the value of attribute item_id.
9 10 11 |
# File 'lib/paneron/register/raw/item.rb', line 9 def item_id @item_id end |
#item_path ⇒ Object (readonly)
Returns the value of attribute item_path.
9 10 11 |
# File 'lib/paneron/register/raw/item.rb', line 9 def item_path @item_path end |
Class Method Details
.validate_item_path(path) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/paneron/register/raw/item.rb', line 28 def self.validate_item_path(path) unless File.exist?(path) raise Paneron::Register::Error, "Item path does not exist" end unless File.file?(path) raise Paneron::Register::Error, "Item path is not a file" end end |
Instance Method Details
#to_h ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/paneron/register/raw/item.rb', line 48 def to_h @to_h ||= YAML.safe_load_file( File.join(item_path), permitted_classes: [Time], ) end |