Class: Burgundy::Item
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Burgundy::Item
show all
- Includes:
- Helpers, RouteHelpers
- Defined in:
- lib/burgundy/item.rb,
lib/burgundy/rails.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#eql?, #routes, #to_param
Methods included from Helpers
#helpers
Constructor Details
#initialize(item) ⇒ Item
Returns a new instance of Item.
32
33
34
35
|
# File 'lib/burgundy/item.rb', line 32
def initialize(item)
@item = item
__setobj__(item)
end
|
Instance Attribute Details
#item ⇒ Object
Returns the value of attribute item.
5
6
7
|
# File 'lib/burgundy/item.rb', line 5
def item
@item
end
|
Class Method Details
.attributes(*args) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/burgundy/item.rb', line 20
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) ⇒ Object
7
8
9
|
# File 'lib/burgundy/item.rb', line 7
def self.inherited(child)
child.attributes(attributes)
end
|
.map(collection) ⇒ Object
15
16
17
18
|
# File 'lib/burgundy/item.rb', line 15
def self.map(collection)
warn "Burgundy::Item.map is deprecated; use Burgundy::Item.wrap instead."
wrap(collection)
end
|
.wrap(collection, *args) ⇒ Object
11
12
13
|
# File 'lib/burgundy/item.rb', line 11
def self.wrap(collection, *args)
Collection.new(collection, self, *args)
end
|
Instance Method Details
#as_json ⇒ Object
43
44
45
|
# File 'lib/burgundy/item.rb', line 43
def as_json(*)
attributes
end
|
#attributes ⇒ Object
Also known as:
to_hash, to_h
37
38
39
40
41
|
# File 'lib/burgundy/item.rb', line 37
def attributes
self.class.attributes.each_with_object({}) do |(from, to), target|
target[to] = send(from)
end
end
|