Module: Card::Set::All::Data::DataFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
platypus/tmp/set/gem-defaults/mod004-format/all/data.rb

Instance Method Summary collapse

Instance Method Details

#atomObject



102
103
104
105
106
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/data.rb', line 102

def atom
  nucleus.tap do |h|
    h[:content] = render_content if card.known? && !card.structure
  end
end

#moleculeObject



108
109
110
111
112
113
114
115
116
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/data.rb', line 108

def molecule
  atom.merge items: _render_items,
             links: _render_links,
             ancestors: _render_ancestors,
             html_url: path,
             type: nest(card.type_card, view: :nucleus),
             created_at: card.created_at,
             updated_at: card.updated_at
end

#nucleusObject

NOTE: moving these to methods prevents potential caching problems, because other views manipulate their hashes.



93
94
95
96
97
98
99
100
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/data.rb', line 93

def nucleus
  { id: card.id,
    name: card.name,
    type: card.type_name,
    url: path(format: :json) }.tap do |h|
    h[:codename] = card.codename if card.codename
  end
end

#view: ancestorsObject



64
65
66
67
68
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/data.rb', line 64

view :ancestors do
  card.name.ancestors.map do |name|
    nest name, view: :nucleus
  end
end

#view: atomObject

TODO: add simple values for fields



56
57
58
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/data.rb', line 56

view :atom, unknown: true do
  atom
end

#view: castObject

minimum needed to re-fetch card



71
72
73
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/data.rb', line 71

view :cast do
  card.cast
end

#view: contentObject



47
48
49
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/data.rb', line 47

view :content do
  card.content
end

#view: coreObject



43
44
45
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/data.rb', line 43

view :core, unknown: true do
  card.known? ? render_content : nil
end

#view: itemsObject

NOCACHE because sometimes item_cards is dynamic. could be safely cached for non-dynamic lists



77
78
79
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/data.rb', line 77

view :items, cache: :never do
  listing item_cards, view: (voo_items_view || :atom)
end


81
82
83
84
85
86
87
88
89
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/data.rb', line 81

view :links do
  card.link_chunks.map do |chunk|
    if chunk.referee_name
      path mark: chunk.referee_name, format: :json
    else
      link_to_resource chunk.link_target
    end
  end
end

#view: moleculeObject



60
61
62
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/data.rb', line 60

view :molecule do
  molecule
end

#view: nucleusObject



51
52
53
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/data.rb', line 51

view :nucleus do
  nucleus
end

#view: podObject



39
40
41
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/data.rb', line 39

view :pod do
  card.pod_hash
end