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 = nil) ⇒ Item
Returns a new instance of Item.
27
28
29
30
|
# File 'lib/burgundy/item.rb', line 27
def initialize(item = nil)
@item = item || Guard.new(self)
__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
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/burgundy/item.rb', line 15
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
|
.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
38
39
40
|
# File 'lib/burgundy/item.rb', line 38
def as_json(*)
attributes
end
|
#attributes ⇒ Object
Also known as:
to_hash, to_h
32
33
34
35
36
|
# File 'lib/burgundy/item.rb', line 32
def attributes
self.class.attributes.each_with_object({}) do |(from, to), target|
target[to] = send(from)
end
end
|
#to_json ⇒ Object
42
43
44
|
# File 'lib/burgundy/item.rb', line 42
def to_json(*)
as_json.to_json
end
|