class Saxophone::SAXConfig::ElementConfig

Attributes

as[R]
collection[R]
data_class[R]
default[R]
name[R]
setter[R]

Public Class Methods

new(name, options) click to toggle source
# File lib/saxophone/config/sax_element.rb, line 6
def initialize(name, options)
  @name = name.to_s
  @with = options.fetch(:with, {})

  @value = if options.has_key?(:value)
    options[:value].to_s
  else
    nil
  end

  @as = options[:as]
  @collection = options[:collection]
  @default = options[:default]

  @setter = if @collection
    "add_#{options[:as]}"
  else
    "#{@as}="
  end

  @data_class = options[:class]
  @required = options[:required]
end

Public Instance Methods

attrs_match?(attrs) click to toggle source
# File lib/saxophone/config/sax_element.rb, line 50
def attrs_match?(attrs)
  @with.all? do |key, value|
    value === attrs[key.to_s]
  end
end
collection?() click to toggle source
# File lib/saxophone/config/sax_element.rb, line 60
def collection?
  !!@collection
end
column() click to toggle source
# File lib/saxophone/config/sax_element.rb, line 38
def column
  @as || @name.to_sym
end
has_value_and_attrs_match?(attrs) click to toggle source
# File lib/saxophone/config/sax_element.rb, line 56
def has_value_and_attrs_match?(attrs)
  !@value.nil? && attrs_match?(attrs)
end
required?() click to toggle source
# File lib/saxophone/config/sax_element.rb, line 42
def required?
  !!@required
end
to_s() click to toggle source
# File lib/saxophone/config/sax_element.rb, line 34
def to_s
  "name: #{@name} dataclass: #{@data_class} setter: #{@setter} required: #{@required} value: #{@value} as:#{@as} collection: #{@collection} with: #{@with}"
end
value_configured?() click to toggle source
# File lib/saxophone/config/sax_element.rb, line 30
def value_configured?
  !@value.nil?
end
value_from_attrs(attrs) click to toggle source
# File lib/saxophone/config/sax_element.rb, line 46
def value_from_attrs(attrs)
  attrs.fetch(@value, nil)
end