Class: Yarrow::Content::ContentType

Inherits:
Object
  • Object
show all
Defined in:
lib/yarrow/content/content_type.rb

Constant Summary collapse

DEFAULT_EXTENSIONS =
[".md", ".yml", ".htm"]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(properties) ⇒ ContentType

Returns a new instance of ContentType.



10
11
12
13
14
15
16
# File 'lib/yarrow/content/content_type.rb', line 10

def initialize(properties)
  unless properties.respond_to?(:collection) || properties.respond_to?(:entity)
    raise "Must provide a collection name or entity name"
  end

  @properties = properties
end

Class Method Details

.from_name(name) ⇒ Object



6
7
8
# File 'lib/yarrow/content/content_type.rb', line 6

def self.from_name(name)
  new(Yarrow::Configuration.new(collection: name.to_sym))
end

Instance Method Details

#collectionObject



18
19
20
21
# File 'lib/yarrow/content/content_type.rb', line 18

def collection
  return @properties.collection if @properties.respond_to?(:collection)
  ActiveSupport::Inflector.pluralize(@properties.entity).to_sym
end

#entityObject



23
24
25
26
# File 'lib/yarrow/content/content_type.rb', line 23

def entity
  return @properties.entity if @properties.respond_to?(:entity)
  ActiveSupport::Inflector.singularize(@properties.collection).to_sym
end

#extensionsObject



28
29
30
31
# File 'lib/yarrow/content/content_type.rb', line 28

def extensions
  return @properties.extensions if @properties.respond_to?(:extensions)
  DEFAULT_EXTENSIONS
end

#match_pathObject



33
34
35
# File 'lib/yarrow/content/content_type.rb', line 33

def match_path
  "."
end