Sha256: a6bca9973e061392436326f1d1c0690e1bda3ce4ba8b42656c6e21771c466b55

Contents?: true

Size: 879 Bytes

Versions: 16

Compression:

Stored size: 879 Bytes

Contents

class CMS::Type
  attr_accessor :name, :attributes, :options, :references
  include ActiveModel::Naming # using include instead of extend on purpose
  def parents ; [] end # quacks like a Module

  def initialize name, attributes, options = {}
    @name = name
    @attributes = attributes
    @options = options.symbolize_keys.merge(timestamps: true, indexes: true)
    @references = []
  end

  def accessible_attributes
    attributes
  end

  def attributes_with_index
    attributes.select { |a| a.has_index? || (a.reference? && options[:indexes]) }
  end

  def orderable_attributes
    attributes.select(&:orderable?)
  end

  def file_attributes
    attributes.select(&:file?)
  end

  def orderable?
    !!order_attribute
  end

  def order_attribute
    orderable_attributes.first
  end

  def to_s
    name
  end

  def subject
    options[:subject] || name
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
honey-cms-0.3.8 lib/cms/type.rb
honey-cms-0.3.7 lib/cms/type.rb
honey-cms-0.3.5 lib/cms/type.rb
honey-cms-0.3.4 lib/cms/type.rb
honey-cms-0.3.3 lib/cms/type.rb
honey-cms-0.3.2 lib/cms/type.rb
honey-cms-0.3.1 lib/cms/type.rb
honey-cms-0.3.0 lib/cms/type.rb
honey-cms-0.2.4 lib/cms/type.rb
honey-cms-0.2.3 lib/cms/type.rb
honey-cms-0.2.2 lib/cms/type.rb
honey-cms-0.2.1 lib/cms/type.rb
honey-cms-0.2.0 lib/cms/type.rb
honey-cms-0.1.2 lib/cms/type.rb
honey-cms-0.1.1 lib/cms/type.rb
honey-cms-0.1.0 lib/cms/type.rb