Class: Pyper::Pipes::Content::Store
- Inherits:
-
Object
- Object
- Pyper::Pipes::Content::Store
- Defined in:
- lib/pyper/pipes/content/store.rb
Overview
A pipe for storing content to an object store. Uses the StorageStrategy gem.
Instance Attribute Summary collapse
-
#storage_field ⇒ Object
readonly
Returns the value of attribute storage_field.
-
#storage_strategy_builder ⇒ Object
readonly
Returns the value of attribute storage_strategy_builder.
Instance Method Summary collapse
-
#initialize(storage_field, &storage_strategy_builder) ⇒ Store
constructor
A new instance of Store.
-
#pipe(attributes, status = {}) ⇒ Hash
Stores content using the specified storage strategy.
Constructor Details
#initialize(storage_field, &storage_strategy_builder) ⇒ Store
Returns a new instance of Store.
9 10 11 12 |
# File 'lib/pyper/pipes/content/store.rb', line 9 def initialize(storage_field, &storage_strategy_builder) @storage_field = storage_field @storage_strategy_builder = storage_strategy_builder end |
Instance Attribute Details
#storage_field ⇒ Object (readonly)
Returns the value of attribute storage_field.
5 6 7 |
# File 'lib/pyper/pipes/content/store.rb', line 5 def storage_field @storage_field end |
#storage_strategy_builder ⇒ Object (readonly)
Returns the value of attribute storage_strategy_builder.
5 6 7 |
# File 'lib/pyper/pipes/content/store.rb', line 5 def storage_strategy_builder @storage_strategy_builder end |
Instance Method Details
#pipe(attributes, status = {}) ⇒ Hash
Stores content using the specified storage strategy
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pyper/pipes/content/store.rb', line 18 def pipe(attributes, status = {}) strategy = storage_strategy_builder.call(attributes) content = attributes.delete(storage_field) raise ArgumentError.new("#{storage_field} must be present in ContentStorage") unless content case content when NilClass then # do nothing -- there's no content to write when String then strategy.write(content) else strategy.write_from(content) end attributes.merge!(strategy.) attributes end |