Class: Cloudruler::Ruler::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudruler/ruler/content.rb,
lib/cloudruler/ruler/content/base.rb,
lib/cloudruler/ruler/content/outputs.rb,
lib/cloudruler/ruler/content/mappings.rb,
lib/cloudruler/ruler/content/metadata.rb,
lib/cloudruler/ruler/content/resources.rb,
lib/cloudruler/ruler/content/transform.rb,
lib/cloudruler/ruler/content/conditions.rb,
lib/cloudruler/ruler/content/parameters.rb

Defined Under Namespace

Classes: Base, Conditions, Mappings, Metadata, Outputs, Resources, Transform

Constant Summary collapse

VALID_SECTION_KEYS =
%w(
  Metadata
  Parameters
  Mappings
  Conditions
  Transform
  Resources
  Outputs
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ruler, annotations, content_hash, options) ⇒ Content

Returns a new instance of Content.



55
56
57
58
59
60
# File 'lib/cloudruler/ruler/content.rb', line 55

def initialize(ruler, annotations, content_hash, options)
  content_hash.each do |k, v|
    next unless VALID_SECTION_KEYS.include?(k)
    instance_variable_set("@#{k.downcase}", self.class.const_get(k).new(ruler, annotations, v, options))
  end
end

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



53
54
55
# File 'lib/cloudruler/ruler/content.rb', line 53

def conditions
  @conditions
end

#mappingsObject (readonly)

Returns the value of attribute mappings.



53
54
55
# File 'lib/cloudruler/ruler/content.rb', line 53

def mappings
  @mappings
end

#metadataObject (readonly)

Returns the value of attribute metadata.



53
54
55
# File 'lib/cloudruler/ruler/content.rb', line 53

def 
  @metadata
end

#outputsObject (readonly)

Returns the value of attribute outputs.



53
54
55
# File 'lib/cloudruler/ruler/content.rb', line 53

def outputs
  @outputs
end

#parametersObject (readonly)

Returns the value of attribute parameters.



53
54
55
# File 'lib/cloudruler/ruler/content.rb', line 53

def parameters
  @parameters
end

#resourcesObject (readonly)

Returns the value of attribute resources.



53
54
55
# File 'lib/cloudruler/ruler/content.rb', line 53

def resources
  @resources
end

#transformObject (readonly)

Returns the value of attribute transform.



53
54
55
# File 'lib/cloudruler/ruler/content.rb', line 53

def transform
  @transform
end

Class Method Details

.parse(ruler, raw_content, options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cloudruler/ruler/content.rb', line 23

def parse(ruler, raw_content, options)
  annotation = ''
  content = ''
  raw_content.each_line do |line|
    if line.start_with?('#')
      annotation << line.sub(/\A#/, '')
    else
      content << line
    end
  end
  parsed_annotation = parse_annotation(annotation)
  parsed_content = parse_content(ruler, content)
  self.new(ruler, parsed_annotation, parsed_content, options)
end

.parse_annotation(annotation) ⇒ Object



38
39
40
# File 'lib/cloudruler/ruler/content.rb', line 38

def parse_annotation(annotation)
  YAML.load(annotation)
end

.parse_content(ruler, content) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/cloudruler/ruler/content.rb', line 42

def parse_content(ruler, content)
  if ruler.yaml?
    YAML.load(content)
  elsif ruler.json?
    JSON.parse(content)
  else
    raise 'invalid ext'
  end
end