Class: Pakyow::Presenter::Component

Inherits:
Object
  • Object
show all
Extended by:
Support::ClassState, Support::Makeable
Includes:
Support::Hookable
Defined in:
lib/pakyow/presenter/component.rb

Overview

Reusable functionality for a view component.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection:, config: {}) ⇒ Component

Returns a new instance of Component.



24
25
26
# File 'lib/pakyow/presenter/component.rb', line 24

def initialize(connection:, config: {})
  @connection, @config = connection, config
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



22
23
24
# File 'lib/pakyow/presenter/component.rb', line 22

def connection
  @connection
end

Class Method Details

.parse(string) ⇒ Object



43
44
45
46
47
48
49
50
# 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) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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) ⇒ Object



33
34
35
36
37
38
39
40
41
# 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

Instance Method Details

#performObject



28
29
30
# File 'lib/pakyow/presenter/component.rb', line 28

def perform
  # intentionally empty
end