module Kamaze::DockerImage::Concern::ReadableAttrs
Provides “readable_attrs“ method
Readable attributes have an instance variable and an accessor, boolean accessors are also supported.
As a result, class including this module obtains a Hash representation.
Public Instance Methods
readable_attrs()
click to toggle source
Get readable attributes
@return [Array<Symbol>]
# File lib/kamaze/docker_image/concern/readable_attrs.rb, line 21 def readable_attrs instance_variables.clone.map do |attr| k = attr.to_s.gsub(/^@/, '').to_sym methods = ([k, "#{k}?".to_sym] & public_methods) methods.empty? ? nil : k end.compact.sort end
to_h()
click to toggle source
# File lib/kamaze/docker_image/concern/readable_attrs.rb, line 31 def to_h readable_attrs_values.to_h end
Protected Instance Methods
readable_attrs_values()
click to toggle source
Get readable attributes with values
@return [Array<Array>]
# File lib/kamaze/docker_image/concern/readable_attrs.rb, line 40 def readable_attrs_values readable_attrs.map do |k| # booleanaccessor will override "real" accessor ([k, "#{k}?".to_sym] & public_methods) .map { |m| [k, self.public_send(m)] } .first end.compact end