class Nacelle::CellsSerializer

Public Instance Methods

as_json(*) click to toggle source
# File lib/nacelle/cells_serializer.rb, line 2
def as_json(*)
  { cells: cell_classes.flat_map(&method(:serialize)) }
end

Private Instance Methods

cell_classes() click to toggle source
# File lib/nacelle/cells_serializer.rb, line 21
def cell_classes
  @all ||= begin
    require_all_cells
    Nacelle::Cell.subclasses
  end
end
require_all_cells() click to toggle source
# File lib/nacelle/cells_serializer.rb, line 28
def require_all_cells
  # TODO pull in cells from engines, too
  cell_files = Dir[::Rails.root.join('app/cells/*.rb')]
  cell_files.each(&method(:require))
end
serialize(klass) click to toggle source
# File lib/nacelle/cells_serializer.rb, line 8
def serialize klass
  cell = klass.to_s.sub("Cell", "").underscore
  cell_name = cell.humanize

  klass.action_methods.map do |action|
    action_name = action.to_s.humanize
    {
      id:   "#{cell}/#{action}",
      name: "#{cell_name} #{action_name}",
    }
  end
end