class Pakyow::Presenter::Component

Reusable functionality for a view component.

Attributes

connection[R]

Public Class Methods

new(connection:, config: {}) click to toggle source
# File lib/pakyow/presenter/component.rb, line 24
def initialize(connection:, config: {})
  @connection, @config = connection, config
end
parse(string) click to toggle source
# File lib/pakyow/presenter/component.rb, line 43
def parse(string)
  component, config_string = string.split("(")

  {
    name: component.strip.to_sym,
    config: parse_config(config_string)
  }
end
parse_config(string) click to toggle source
# File lib/pakyow/presenter/component.rb, line 52
def parse_config(string)
  if string
    string.strip[0..-2].split(",").each_with_object({}) { |config_string_part, values|
      key, value = config_string_part.split(":")

      value = if value
        value.strip
      else
        true
      end

      values[key.strip.to_sym] = value
    }
  else
    {}
  end
end
presenter(&block) click to toggle source
# File lib/pakyow/presenter/component.rb, line 33
def presenter(&block)
  @__presenter_class = Class.new(@__presenter_class) do
    class_eval(&block)
  end

  Support::ObjectMaker.define_object_on_target_with_constant_name(
    @__presenter_class, self, :Presenter
  )
end

Public Instance Methods

perform() click to toggle source
# File lib/pakyow/presenter/component.rb, line 28
def perform
  # intentionally empty
end