module ContentsCore::Blocks
Public Instance Methods
cache_key()
click to toggle source
# File lib/contents_core/blocks.rb, line 31 def cache_key self.cc_blocks.published.select( :updated_at ).order( updated_at: :desc ).first.try( :updated_at ).to_i end
create_block( type = :text, params = {} )
click to toggle source
# File lib/contents_core/blocks.rb, line 10 def create_block( type = :text, params = {} ) ContentsCore::create_block_in_parent( self, type, params ) end
current_blocks( version = 0 )
click to toggle source
# File lib/contents_core/blocks.rb, line 14 def current_blocks( version = 0 ) # return @current_blocks if @current_blocks version = 0 unless ContentsCore.editing # no admin = only current version Rails.cache.fetch( "#{cache_key}/current_blocks/#{version}", expires_in: 12.hours ) do self.cc_blocks.where( version: version.to_i ).with_nested.published end end
get_block( name, version = 0 )
click to toggle source
# File lib/contents_core/blocks.rb, line 22 def get_block( name, version = 0 ) current_blocks( version ).each do |block| return block if block.name == name end nil end