class Burgundy::Item

Attributes

item[R]

Public Class Methods

attributes(*args) click to toggle source
# File lib/burgundy/item.rb, line 16
def self.attributes(*args)
  @attributes ||= {}

  if args.any?
    @attributes = {}
    @attributes = args.pop if args.last.is_a?(Hash)
    @attributes.merge!(args.zip(args).to_h)
  end

  @attributes
end
inherited(child) click to toggle source
Calls superclass method
# File lib/burgundy/item.rb, line 7
def self.inherited(child)
  super
  child.attributes(attributes)
end
new(item = nil) click to toggle source
# File lib/burgundy/item.rb, line 28
def initialize(item = nil) # rubocop:disable Lint/MissingSuper
  @item = item || Guard.new(self)
  __setobj__(@item)
end
wrap(collection, *, **) click to toggle source
# File lib/burgundy/item.rb, line 12
def self.wrap(collection, *, **)
  Collection.new(collection, self, *, **)
end

Public Instance Methods

as_json(*) click to toggle source
# File lib/burgundy/item.rb, line 39
def as_json(*)
  attributes
end
attributes() click to toggle source
# File lib/burgundy/item.rb, line 33
def attributes
  self.class.attributes.each_with_object({}) do |(from, to), target|
    target[to] = send(from)
  end
end
Also aliased as: to_hash, to_h
to_h()
Alias for: attributes
to_hash()
Alias for: attributes
to_json(*) click to toggle source
# File lib/burgundy/item.rb, line 43
def to_json(*)
  as_json.to_json
end