class Picatrix::Cruddy

Constants

DEFAULT_CONTROLS

iow if it is addressable it has a self

Attributes

controls[RW]

Public Class Methods

new(edges) click to toggle source
# File lib/picatrix/cruddy.rb, line 8
def initialize(edges)
  @controls = edges.inject({}) do |memo, edge|
    source = edge.keys.first
    target = edge[source][:target]

    next memo if source.upcase == "ROOT"

    memo[target] = appropriate_controls_for(target)
    memo
  end
end

Private Instance Methods

appropriate_controls_for(source) click to toggle source
# File lib/picatrix/cruddy.rb, line 21
def appropriate_controls_for(source)
  by_size = collection?(source) ? :collection : :item
  {
    source => template_map(by_size)
  }
end
collection?(source) click to toggle source
# File lib/picatrix/cruddy.rb, line 43
def collection?(source)
  source.pluralize == source
end
template_map(type) click to toggle source
# File lib/picatrix/cruddy.rb, line 27
def template_map(type)
  {
    # what controls do you want to get back
    # from a given method on a item/collection
    item: {
      get: [:edit, :remove] + DEFAULT_CONTROLS,
      patch: DEFAULT_CONTROLS,
      put: DEFAULT_CONTROLS,
      delete: [:mason_up]
    },
    collection: {
      get: [:create, :filter] + DEFAULT_CONTROLS,
      post: [:mason_self]
    }
  }[type]
end