Class: Alephant::Renderer::ViewMapper
- Inherits:
-
Object
- Object
- Alephant::Renderer::ViewMapper
- Defined in:
- lib/alephant/renderer/view_mapper.rb
Constant Summary collapse
- DEFAULT_LOCATION =
'components'.freeze
Instance Method Summary collapse
- #base_path ⇒ Object
- #base_path=(path) ⇒ Object
- #generate(data) ⇒ Object
-
#initialize(renderer_id, view_base_path = nil) ⇒ ViewMapper
constructor
A new instance of ViewMapper.
Constructor Details
#initialize(renderer_id, view_base_path = nil) ⇒ ViewMapper
Returns a new instance of ViewMapper.
9 10 11 |
# File 'lib/alephant/renderer/view_mapper.rb', line 9 def initialize(renderer_id, view_base_path = nil) self.base_path = "#{view_base_path}/#{renderer_id}" unless view_base_path.nil? end |
Instance Method Details
#base_path ⇒ Object
13 14 15 |
# File 'lib/alephant/renderer/view_mapper.rb', line 13 def base_path @base_path || DEFAULT_LOCATION end |
#base_path=(path) ⇒ Object
17 18 19 |
# File 'lib/alephant/renderer/view_mapper.rb', line 17 def base_path=(path) @base_path = File.directory?(path) ? path : raise(Error::InvalidBasePath.new(path)) end |
#generate(data) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/alephant/renderer/view_mapper.rb', line 21 def generate(data) model_locations.reduce({}) do |obj, file| model_id = model_id_for(file) obj[model_id] = model(model_id, data) obj end end |