Class: Buildkite::Builder::Data
- Inherits:
-
Object
- Object
- Buildkite::Builder::Data
- Defined in:
- lib/buildkite/builder/data.rb
Instance Method Summary collapse
-
#initialize ⇒ Data
constructor
A new instance of Data.
- #to_definition ⇒ Object
Constructor Details
#initialize ⇒ Data
Returns a new instance of Data.
4 5 6 |
# File 'lib/buildkite/builder/data.rb', line 4 def initialize @data = Hash.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/buildkite/builder/data.rb', line 20 def method_missing(name, *args, &block) if name.end_with?('=') name = name.to_s.delete_suffix('=').to_sym if respond_to_missing?(name) raise ArgumentError, "Data already contains key '#{name}'" else return @data[name] = args.first end elsif respond_to_missing?(name) return @data[name] end super end |
Instance Method Details
#to_definition ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/buildkite/builder/data.rb', line 8 def to_definition @data.each_with_object({}) do |(key, value), hash| value = value.respond_to?(:to_definition) ? value.to_definition : value next if value.nil? || value.empty? hash[key] = value end end |