Class: Cloudruler::Ruler::Content
- Inherits:
-
Object
- Object
- Cloudruler::Ruler::Content
- 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
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#mappings ⇒ Object
readonly
Returns the value of attribute mappings.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
-
#transform ⇒ Object
readonly
Returns the value of attribute transform.
Class Method Summary collapse
- .parse(ruler, raw_content, options) ⇒ Object
- .parse_annotation(annotation) ⇒ Object
- .parse_content(ruler, content) ⇒ Object
Instance Method Summary collapse
-
#initialize(ruler, annotations, content_hash, options) ⇒ Content
constructor
A new instance of Content.
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, ) 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, )) end end |
Instance Attribute Details
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
53 54 55 |
# File 'lib/cloudruler/ruler/content.rb', line 53 def conditions @conditions end |
#mappings ⇒ Object (readonly)
Returns the value of attribute mappings.
53 54 55 |
# File 'lib/cloudruler/ruler/content.rb', line 53 def mappings @mappings end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
53 54 55 |
# File 'lib/cloudruler/ruler/content.rb', line 53 def @metadata end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
53 54 55 |
# File 'lib/cloudruler/ruler/content.rb', line 53 def outputs @outputs end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
53 54 55 |
# File 'lib/cloudruler/ruler/content.rb', line 53 def parameters @parameters end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
53 54 55 |
# File 'lib/cloudruler/ruler/content.rb', line 53 def resources @resources end |
#transform ⇒ Object (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, ) 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, ) 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 |