Class: Perron::Data
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Perron::Data
- Defined in:
- lib/perron/data.rb,
lib/perron/data/proxy.rb
Defined Under Namespace
Classes: Proxy
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(identifier) ⇒ Data
constructor
A new instance of Data.
Constructor Details
#initialize(identifier) ⇒ Data
7 8 9 10 11 12 13 |
# File 'lib/perron/data.rb', line 7 def initialize(identifier) @identifier = identifier @file_path = self.class.path_for!(identifier) @records = records super(records) end |
Class Method Details
.directory?(identifier) ⇒ Boolean
32 |
# File 'lib/perron/data.rb', line 32 def directory?(identifier) = Dir.exist?(Rails.root.join("app", "content", "data", identifier)) |
.path_for(identifier) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/perron/data.rb', line 16 def path_for(identifier) path = Pathname.new(identifier) return path.to_s if path.file? && path.absolute? base_path = Rails.root.join("app", "content", "data") SUPPORTED_EXTENSIONS.lazy.map { base_path.join("#{identifier}#{it}") }.find(&:exist?)&.to_s end |
.path_for!(identifier) ⇒ Object
26 27 28 29 30 |
# File 'lib/perron/data.rb', line 26 def path_for!(identifier) path_for(identifier).tap do |path| raise Errors::FileNotFoundError, "No data file found for `#{identifier}`" unless path end end |