class Katapult::WebUI

Constants

RAILS_ACTIONS
UnknownActionError
UnknownModelError

Attributes

actions[RW]

Public Class Methods

new(*args) click to toggle source
Calls superclass method Katapult::Element::new
# File lib/katapult/elements/web_ui.rb, line 18
def initialize(*args)
  self.actions = []

  super
end

Public Instance Methods

action(name, options = {}) click to toggle source

DSL

# File lib/katapult/elements/web_ui.rb, line 25
def action(name, options = {})
  actions << Action.new(:new, options) if name.to_s == 'create'
  actions << Action.new(:edit, options) if name.to_s == 'update'

  actions << Action.new(name, options)
end
crud() click to toggle source

DSL

# File lib/katapult/elements/web_ui.rb, line 33
def crud
  %i(index show create update destroy).each &method(:action)
end
crud_only?() click to toggle source
# File lib/katapult/elements/web_ui.rb, line 37
def crud_only?
  actions.map(&:name).sort == RAILS_ACTIONS.sort
end
custom_actions() click to toggle source
# File lib/katapult/elements/web_ui.rb, line 52
def custom_actions
  actions.reject { |a| RAILS_ACTIONS.include? a.name }
end
find_action(action_name) click to toggle source
# File lib/katapult/elements/web_ui.rb, line 56
def find_action(action_name)
  actions.find { |a| a.name == action_name.to_s }
end
model() click to toggle source
# File lib/katapult/elements/web_ui.rb, line 41
def model
  model_name = @model || self.name
  application_model.get_model! model_name
end
model_name(kind = nil) click to toggle source
# File lib/katapult/elements/web_ui.rb, line 77
def model_name(kind = nil)
  model.name(kind)
end
params() click to toggle source
# File lib/katapult/elements/web_ui.rb, line 46
def params
  model.attrs.map do |attr|
    attr.name :symbol
  end
end
path(action, object_name = nil) click to toggle source
# File lib/katapult/elements/web_ui.rb, line 60
def path(action, object_name = nil)
  unless action.is_a?(Action)
    not_found_message = "Unknown action '#{action}'"
    action = find_action(action) or raise UnknownActionError, not_found_message
  end

  member_path = "#{model.name(:variable)}_path"
  collection_path = "#{model.name(:variables)}_path"

  path = ''
  path << action.name << '_' unless %w[index show destroy].include?(action.name)
  path << (action.member? ? member_path : collection_path)
  path << "(#{object_name})" if object_name

  path
end
render(options = {}) click to toggle source
# File lib/katapult/elements/web_ui.rb, line 81
def render(options = {})
  Generators::WebUIGenerator.new(self, options).invoke_all
end