Module: Eskimo::Core::Props

Defined in:
lib/eskimo/core/props.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/eskimo/core/props.rb', line 4

def self.included(base)
  fail "#{name} must be prepended"
end

.prepended(base) ⇒ Object



8
9
10
11
12
# File 'lib/eskimo/core/props.rb', line 8

def self.prepended(base)
  if base.include?(Eskimo::Core::Slots)
    fail "#{name} must be prepended before Eskmo::Core::Slots"
  end
end

Instance Method Details

#initialize(**props, &children) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/eskimo/core/props.rb', line 14

def initialize(**props, &children)
  @props = props
  @children = children

  # can't find a cleaner way to check if parent constructor is defined
  # ref (they also can't seem to find a better way):
  # <https://apidock.com/rails/ActiveRecord/Coders/ColumnSerializer/check_arity_of_constructor>
  begin
    super
  rescue ArgumentError => e
    raise unless e.to_s.include?("expected 0")
  end
end

#render(**kwargs) ⇒ Object



28
29
30
# File 'lib/eskimo/core/props.rb', line 28

def render(**kwargs)
  super(**kwargs.merge(@props), &@children)
end