Class: SirTrevorRails::Block
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- SirTrevorRails::Block
- Defined in:
- lib/sir_trevor_rails/block.rb
Direct Known Subclasses
SirTrevorRails::Blocks::TweetBlock, SirTrevorRails::Blocks::VideoBlock
Constant Summary collapse
- DEFAULT_FORMAT =
:markdown
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.custom_block_types ⇒ Object
Sets a list of custom block types to speed up lookup at runtime.
- .from_hash(hash, parent) ⇒ Object
Instance Method Summary collapse
- #as_json(*attrs) ⇒ Object
- #format ⇒ Object
-
#initialize(hash, parent) ⇒ Block
constructor
A new instance of Block.
- #to_partial_path ⇒ Object
Constructor Details
#initialize(hash, parent) ⇒ Block
Returns a new instance of Block.
21 22 23 24 25 26 |
# File 'lib/sir_trevor_rails/block.rb', line 21 def initialize(hash, parent) @raw_data = hash @parent = parent @type = hash[:type].to_sym super(hash[:data]) end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
28 29 30 |
# File 'lib/sir_trevor_rails/block.rb', line 28 def parent @parent end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
28 29 30 |
# File 'lib/sir_trevor_rails/block.rb', line 28 def type @type end |
Class Method Details
.custom_block_types ⇒ Object
Sets a list of custom block types to speed up lookup at runtime.
17 18 19 |
# File 'lib/sir_trevor_rails/block.rb', line 17 def self.custom_block_types [] end |
.from_hash(hash, parent) ⇒ Object
7 8 9 10 |
# File 'lib/sir_trevor_rails/block.rb', line 7 def self.from_hash(hash, parent) hash = hash.deep_dup.with_indifferent_access self.type_klass(hash).new(hash, parent) end |
Instance Method Details
#as_json(*attrs) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/sir_trevor_rails/block.rb', line 34 def as_json(*attrs) { type: @type.to_s, data: marshal_dump } end |
#format ⇒ Object
12 13 14 |
# File 'lib/sir_trevor_rails/block.rb', line 12 def format send(:[], :format).present? ? send(:[], :format).to_sym : DEFAULT_FORMAT end |
#to_partial_path ⇒ Object
30 31 32 |
# File 'lib/sir_trevor_rails/block.rb', line 30 def to_partial_path "sir_trevor/blocks/" << self.class.name.demodulize.underscore end |