Class: Biovision::Stories::ComponentStory
- Inherits:
-
Object
- Object
- Biovision::Stories::ComponentStory
- Defined in:
- app/lib/biovision/stories/component_story.rb
Overview
Base component story
Instance Attribute Summary collapse
-
#component_handler ⇒ Object
Returns the value of attribute component_handler.
-
#entity ⇒ Object
Returns the value of attribute entity.
Instance Method Summary collapse
-
#entity_id=(value) ⇒ Object
Set entity identified by value.
-
#initialize(handler, entity = nil) ⇒ ComponentStory
constructor
A new instance of ComponentStory.
-
#model_class ⇒ Object
Get associated model class.
- #perform(parameters) ⇒ Object
Constructor Details
#initialize(handler, entity = nil) ⇒ ComponentStory
Returns a new instance of ComponentStory.
11 12 13 14 15 16 17 18 19 20 |
# File 'app/lib/biovision/stories/component_story.rb', line 11 def initialize(handler, entity = nil) self.component_handler = handler return if entity.blank? if entity.is_a?(ApplicationRecord) self.entity = entity else self.entity_id = entity.to_s end end |
Instance Attribute Details
#component_handler ⇒ Object
Returns the value of attribute component_handler.
7 8 9 |
# File 'app/lib/biovision/stories/component_story.rb', line 7 def component_handler @component_handler end |
#entity ⇒ Object
Returns the value of attribute entity.
7 8 9 |
# File 'app/lib/biovision/stories/component_story.rb', line 7 def entity @entity end |
Instance Method Details
#entity_id=(value) ⇒ Object
Set entity identified by value
This method can be implemented in child classes
44 45 46 47 48 49 50 51 52 |
# File 'app/lib/biovision/stories/component_story.rb', line 44 def entity_id=(value) return if model_class.nil? if model_class.respond_to?(:[]) self.entity = model_class[value] elsif model_class.respond_to?(:find_by) self.entity = model_class.find_by(id: value) end end |
#model_class ⇒ Object
Get associated model class
This method should be implemented in children if story name does not match model name. The result is used in #entity_id=
27 28 29 30 |
# File 'app/lib/biovision/stories/component_story.rb', line 27 def model_class model_name = to_s.demodulize.to_s.underscore.gsub('_story', '') model_name.classify.safe_constantize end |
#perform(parameters) ⇒ Object
33 34 35 36 37 |
# File 'app/lib/biovision/stories/component_story.rb', line 33 def perform(parameters) @parameters = parameters # implement in children and return hash { result: 'Nothing was processed.' } end |