Class: ActiveKit::Bedrock::Bedrocker
- Inherits:
-
Object
- Object
- ActiveKit::Bedrock::Bedrocker
show all
- Defined in:
- lib/active_kit/bedrock/bedrocker.rb
Instance Method Summary
collapse
Constructor Details
#initialize(current_component:, current_class:) ⇒ Bedrocker
Returns a new instance of Bedrocker.
4
5
6
7
8
|
# File 'lib/active_kit/bedrock/bedrocker.rb', line 4
def initialize(current_component:, current_class:)
@current_component = current_component
@current_class = current_class
@describers = {}
end
|
Instance Method Details
#create_attribute(name, options) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/active_kit/bedrock/bedrocker.rb', line 25
def create_attribute(name, options)
options.deep_symbolize_keys!
create_default_describer unless @describers.present?
describer_names = Array(options.delete(:describers))
describer_names = @describers.keys if describer_names.blank?
describer_names.each do |describer_name|
if describer_options = @describers.dig(describer_name)
describer_options[:attributes].store(name, options)
end
end
describer_names
end
|
#create_describer(name, options) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/active_kit/bedrock/bedrocker.rb', line 10
def create_describer(name, options)
name = name.to_sym
options.deep_symbolize_keys!
unless find_describer_by(name: name)
options.store(:attributes, {})
@describers.store(name, options)
@current_class.class_eval <<-CODE, __FILE__, __LINE__ + 1
def self.#{name}(**params)
#{@current_component}er.run_describer_method("#{name}", params)
end
CODE
end
end
|
#describer_method(describer, params) ⇒ Object
47
48
49
|
# File 'lib/active_kit/bedrock/bedrocker.rb', line 47
def describer_method(describer, params)
raise NotImplementedError
end
|
#for(describer_name) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/active_kit/bedrock/bedrocker.rb', line 51
def for(describer_name)
describer_name = @describers.keys[0] if describer_name.nil?
raise "Could not find any describer name in '#{@current_class.name}'." if describer_name.blank?
describer_name = describer_name.to_sym
raise "Could not find describer '#{describer_name}' in '#{@current_class.name}'." unless @describers.dig(describer_name)
componenting = @describers.dig(describer_name, :componenting)
return componenting if componenting
@describers[describer_name][:componenting] = "ActiveKit::#{@current_component.to_s.titleize}::#{@current_component.to_s.titleize}ing".constantize.new(describer: find_describer_by(name: describer_name), current_class: @current_class)
@describers[describer_name][:componenting]
end
|
#get_describer_names ⇒ Object
64
65
66
|
# File 'lib/active_kit/bedrock/bedrocker.rb', line 64
def get_describer_names
@describers.keys.map(&:to_s)
end
|
#run_describer_method(describer_name, params) ⇒ Object
42
43
44
45
|
# File 'lib/active_kit/bedrock/bedrocker.rb', line 42
def run_describer_method(describer_name, params)
raise "Could not find describer while creating describer method." unless describer = find_describer_by(name: describer_name.to_sym)
describer_method(describer, params)
end
|