Module: Buildkite::Pipelines::Attributes
- Included in:
- Steps::Abstract
- Defined in:
- lib/buildkite/pipelines/attributes.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #append(attr, value) ⇒ Object
- #get(attr) ⇒ Object
- #has?(attr) ⇒ Boolean
- #permits?(attr) ⇒ Boolean
- #permitted_attributes ⇒ Object
- #prepend(attr, value) ⇒ Object
- #set(attr, value) ⇒ Object
- #to_h ⇒ Object
- #unset(attr) ⇒ Object
Class Method Details
.included(base) ⇒ Object
8 9 10 |
# File 'lib/buildkite/pipelines/attributes.rb', line 8 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#append(attr, value) ⇒ Object
29 30 31 32 33 |
# File 'lib/buildkite/pipelines/attributes.rb', line 29 def append(attr, value) ensure_array_value(attr) get(attr).push(*[value].flatten) value end |
#get(attr) ⇒ Object
12 13 14 |
# File 'lib/buildkite/pipelines/attributes.rb', line 12 def get(attr) attributes[validate(attr)] end |
#has?(attr) ⇒ Boolean
20 21 22 23 |
# File 'lib/buildkite/pipelines/attributes.rb', line 20 def has?(attr) # Don't validate for has? calls. attributes.key?(attr.to_s) end |
#permits?(attr) ⇒ Boolean
25 26 27 |
# File 'lib/buildkite/pipelines/attributes.rb', line 25 def permits?(attr) self.class.permits?(attr) end |
#permitted_attributes ⇒ Object
41 42 43 |
# File 'lib/buildkite/pipelines/attributes.rb', line 41 def permitted_attributes self.class.permitted_attributes end |
#prepend(attr, value) ⇒ Object
35 36 37 38 39 |
# File 'lib/buildkite/pipelines/attributes.rb', line 35 def prepend(attr, value) ensure_array_value(attr) get(attr).unshift(*[value].flatten) value end |
#set(attr, value) ⇒ Object
16 17 18 |
# File 'lib/buildkite/pipelines/attributes.rb', line 16 def set(attr, value) attributes[validate(attr)] = value end |
#to_h ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/buildkite/pipelines/attributes.rb', line 49 def to_h permitted_attributes.each_with_object({}) do |attr, hash| next unless has?(attr) hash[attr] = get(attr).respond_to?(:to_definition) ? get(attr).to_definition : get(attr) end end |
#unset(attr) ⇒ Object
45 46 47 |
# File 'lib/buildkite/pipelines/attributes.rb', line 45 def unset(attr) attributes.delete(validate(attr)) end |