Class: Fluent::Plugin::Output::PlaceholderValidator
- Inherits:
-
Object
- Object
- Fluent::Plugin::Output::PlaceholderValidator
- Defined in:
- lib/fluent/plugin/output.rb
Instance Attribute Summary collapse
-
#argument ⇒ Object
readonly
Returns the value of attribute argument.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name, str, type, arg) ⇒ PlaceholderValidator
constructor
A new instance of PlaceholderValidator.
- #keys? ⇒ Boolean
- #tag? ⇒ Boolean
- #time? ⇒ Boolean
- #validate! ⇒ Object
- #validate_keys! ⇒ Object
- #validate_tag! ⇒ Object
- #validate_time! ⇒ Object
Constructor Details
#initialize(name, str, type, arg) ⇒ PlaceholderValidator
Returns a new instance of PlaceholderValidator.
673 674 675 676 677 678 679 |
# File 'lib/fluent/plugin/output.rb', line 673 def initialize(name, str, type, arg) @name = name @string = str @type = type raise ArgumentError, "invalid type:#{type}" if @type != :time && @type != :tag && @type != :keys @argument = arg end |
Instance Attribute Details
#argument ⇒ Object (readonly)
Returns the value of attribute argument.
671 672 673 |
# File 'lib/fluent/plugin/output.rb', line 671 def argument @argument end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
671 672 673 |
# File 'lib/fluent/plugin/output.rb', line 671 def name @name end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
671 672 673 |
# File 'lib/fluent/plugin/output.rb', line 671 def string @string end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
671 672 673 |
# File 'lib/fluent/plugin/output.rb', line 671 def type @type end |
Instance Method Details
#keys? ⇒ Boolean
689 690 691 |
# File 'lib/fluent/plugin/output.rb', line 689 def keys? @type == :keys end |
#tag? ⇒ Boolean
685 686 687 |
# File 'lib/fluent/plugin/output.rb', line 685 def tag? @type == :tag end |
#time? ⇒ Boolean
681 682 683 |
# File 'lib/fluent/plugin/output.rb', line 681 def time? @type == :time end |
#validate! ⇒ Object
693 694 695 696 697 698 699 |
# File 'lib/fluent/plugin/output.rb', line 693 def validate! case @type when :time then validate_time! when :tag then validate_tag! when :keys then validate_keys! end end |
#validate_keys! ⇒ Object
728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/fluent/plugin/output.rb', line 728 def validate_keys! keys = @argument[:keys] chunk_keys = @argument[:chunkkeys] if (chunk_keys - keys).size > 0 not_specified = (chunk_keys - keys).sort raise Fluent::ConfigError, "Parameter '#{name}: #{string}' doesn't have enough placeholders for keys #{not_specified.join(',')}" end if (keys - chunk_keys).size > 0 not_satisfied = (keys - chunk_keys).sort raise Fluent::ConfigError, "Parameter '#{name}: #{string}' has placeholders, but chunk keys doesn't have keys #{not_satisfied.join(',')}" end end |
#validate_tag! ⇒ Object
717 718 719 720 721 722 723 724 725 726 |
# File 'lib/fluent/plugin/output.rb', line 717 def validate_tag! parts = @argument[:parts] tagkey = @argument[:tagkey] if tagkey && parts.empty? raise Fluent::ConfigError, "Parameter '#{name}: #{string}' doesn't have tag placeholder" end if !tagkey && !parts.empty? raise Fluent::ConfigError, "Parameter '#{name}: #{string}' has tag placeholders, but chunk key 'tag' is not configured" end end |
#validate_time! ⇒ Object
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 |
# File 'lib/fluent/plugin/output.rb', line 701 def validate_time! sec = @argument[:sec] title = @argument[:title] example = @argument[:example] timekey = @argument[:timekey] if !sec && timekey raise Fluent::ConfigError, "Parameter '#{name}: #{string}' doesn't have timestamp placeholders for timekey #{timekey.to_i}" end if sec && !timekey raise Fluent::ConfigError, "Parameter '#{name}: #{string}' has timestamp placeholders, but chunk key 'time' is not configured" end if sec && timekey && timekey < sec raise Fluent::ConfigError, "Parameter '#{name}: #{string}' doesn't have timestamp placeholder for #{title}('#{example}') for timekey #{timekey.to_i}" end end |