Class: ContentTypes

Inherits:
Object
  • Object
show all
Defined in:
lib/bottlerocket/models/content_types.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content_types_yaml) ⇒ ContentTypes

Returns a new instance of ContentTypes.



8
9
10
# File 'lib/bottlerocket/models/content_types.rb', line 8

def initialize(content_types_yaml)
  self.content_types = YAML.load_file(content_types_yaml).collect { |attrs| ContentType.new(attrs) }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(field, *args) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/bottlerocket/models/content_types.rb', line 24

def method_missing(field, *args)
  if find field.to_s.end_with?('=')
    field.to_s = args.first
  else
    find field.to_s
  end
end

Instance Attribute Details

#content_typesObject

Returns the value of attribute content_types.



2
3
4
# File 'lib/bottlerocket/models/content_types.rb', line 2

def content_types
  @content_types
end

Class Method Details

.load(content_types_yaml) ⇒ Object



4
5
6
# File 'lib/bottlerocket/models/content_types.rb', line 4

def self.load(content_types_yaml)
  ContentTypes.new content_types_yaml
end

Instance Method Details

#allObject



12
13
14
# File 'lib/bottlerocket/models/content_types.rb', line 12

def all
  content_types
end

#find(name) ⇒ Object



20
21
22
# File 'lib/bottlerocket/models/content_types.rb', line 20

def find(name)
  content_types.detect { |ct| ct.name == name }
end

#lengthObject



16
17
18
# File 'lib/bottlerocket/models/content_types.rb', line 16

def length
  content_types.length
end