module Bizarroids::Slider

Constants

DEFAULT_SLIDE_ATTRIBUTES
VERSION

Public Class Methods

[](key)
Alias for: get
get(key) click to toggle source
# File lib/bizarroids/slider.rb, line 20
def self.get key
  Collection.actual.find_by!(key: key).slides
end
Also aliased as: []
setup() { |self| ... } click to toggle source
# File lib/bizarroids/slider.rb, line 52
def self.setup
  yield self
end
table_name_prefix() click to toggle source

name prefix for ActiveRecord

# File lib/bizarroids/slider.rb, line 14
def self.table_name_prefix
  'bizarroids_slider_'
end

Private Class Methods

collection(key, attrs={}) click to toggle source
# File lib/bizarroids/slider.rb, line 58
def self.collection key, attrs={}
  key = key.to_sym
  attrs = attrs.dup

  if keys.include? key
    raise ConfigError.new "Collection ':#{key}' already exists"
  end

  collections[key] = attrs
  keys << key

  # skip creating if table is not exists
  return unless ActiveRecord::Base.connection.table_exists? Collection.table_name

  attrs[:position] = keys.index(key)

  collection = Collection.find_by key: key

  if collection.present?
    collection.update_attributes attrs.slice(*update_attr_names)
  else
    collection = Collection.create! attrs.merge(key: key).slice(*valid_attr_names)
  end

  collection
end
update_attr_names() click to toggle source
# File lib/bizarroids/slider.rb, line 89
def self.update_attr_names
  valid_attr_names - %i(key)
end
valid_attr_names() click to toggle source
# File lib/bizarroids/slider.rb, line 85
def self.valid_attr_names
  %i(key name description position)
end