Class: Alephant::Publisher::ViewMapper
- Inherits:
-
Object
- Object
- Alephant::Publisher::ViewMapper
- Includes:
- Logger
- Defined in:
- lib/alephant/publisher/view_mapper.rb
Constant Summary collapse
- DEFAULT_LOCATION =
'components'
Instance Method Summary collapse
- #base_path ⇒ Object
- #base_path=(path) ⇒ Object
- #generate(data) ⇒ Object
-
#initialize(component_id, view_base_path = nil) ⇒ ViewMapper
constructor
A new instance of ViewMapper.
Constructor Details
#initialize(component_id, view_base_path = nil) ⇒ ViewMapper
Returns a new instance of ViewMapper.
10 11 12 13 |
# File 'lib/alephant/publisher/view_mapper.rb', line 10 def initialize(component_id, view_base_path=nil) self.base_path = "#{view_base_path}/#{component_id}" unless view_base_path.nil? @component_id = component_id end |
Instance Method Details
#base_path ⇒ Object
15 16 17 |
# File 'lib/alephant/publisher/view_mapper.rb', line 15 def base_path @base_path || DEFAULT_LOCATION end |
#base_path=(path) ⇒ Object
19 20 21 |
# File 'lib/alephant/publisher/view_mapper.rb', line 19 def base_path=(path) @base_path = File.directory?(path) ? path : (raise "Invalid path: '#{path}'") end |
#generate(data) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/alephant/publisher/view_mapper.rb', line 23 def generate(data) model_locations.reduce({}) do |obj, file| obj.tap do |o| model_id = model_id_for file o[model_id] = model(model_id, data) end end end |