Class: NitroKit::SchemaBuilder::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/nitro_kit/schema_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Builder

Returns a new instance of Builder.

Yields:

  • (_self)

Yield Parameters:



6
7
8
9
# File 'lib/nitro_kit/schema_builder.rb', line 6

def initialize
  @schema = {}
  yield self
end

Instance Method Details

#[](key) ⇒ Object



34
35
36
# File 'lib/nitro_kit/schema_builder.rb', line 34

def [](key)
  @schema[key]
end

#add(name, components: nil, helpers: nil, js: [], modules: [], gems: []) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/nitro_kit/schema_builder.rb', line 11

def add(
  name,
  components: nil,
  helpers: nil,
  js: [],
  modules: [],
  gems: []
)
  # Default is one component, one helper with same name
  components ||= [name]
  helpers ||= [name]

  @schema[name] = Component.new(
    [
      components.map { |c| "app/components/nitro_kit/#{c}.rb" },
      helpers.map { |c| "app/helpers/nitro_kit/#{c}_helper.rb" },
      js.map { |c| "app/javascript/controllers/nk/#{c}_controller.js" }
    ].flatten,
    modules,
    gems
  )
end

#allObject



38
39
40
# File 'lib/nitro_kit/schema_builder.rb', line 38

def all
  @schema.keys.map(&:to_s)
end