Class: Yarrow::Content::ContentType

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

Constant Summary collapse

Value =
Yarrow::Schema::Value.new(:collection, :entity, :extensions)
DEFAULT_EXTENSIONS =
[".md", ".yml", ".htm"]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(properties) ⇒ ContentType

Returns a new instance of ContentType.



14
15
16
17
18
19
20
# File 'lib/yarrow/content/content_type.rb', line 14

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



10
11
12
# File 'lib/yarrow/content/content_type.rb', line 10

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

Instance Method Details

#collectionObject



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

def collection
  return @properties.collection if @properties.collection
  Yarrow::Symbols.to_plural(@properties.entity)
end

#entityObject



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

def entity
  return @properties.entity if @properties.entity
  Yarrow::Symbols.to_singular(@properties.collection)
end

#extensionsObject



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

def extensions
  return @properties.extensions if @properties.extensions
  DEFAULT_EXTENSIONS
end

#match_pathObject



37
38
39
# File 'lib/yarrow/content/content_type.rb', line 37

def match_path
  "."
end