Class: Interfacets::Server::Assets::Facet

Inherits:
Object
  • Object
show all
Defined in:
lib/interfacets/server/assets/facet.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Facet

Returns a new instance of Facet.



12
13
14
# File 'lib/interfacets/server/assets/facet.rb', line 12

def initialize(klass)
  @klass = klass
end

Instance Attribute Details

#klass ⇒ Object (readonly)

Returns the value of attribute klass.



11
12
13
# File 'lib/interfacets/server/assets/facet.rb', line 11

def klass
  @klass
end

Class Method Details

.register(klass:, assets:) ⇒ Object



7
8
9
# File 'lib/interfacets/server/assets/facet.rb', line 7

def self.register(klass:, assets:)
  assets[klass.name] = new(klass).code
end

Instance Method Details

#code ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/interfacets/server/assets/facet.rb', line 16

def code
  # nest it all so names resolve
  *mods, klass_name = klass.name.split("::")

  headers = []
  footers = []

  current_mod = ""
  mods.each do |mod_name|
    current_mod += "::#{mod_name}"
    type = current_mod.constantize.is_a?(Class) ? :class : :module
    headers << "#{type} #{mod_name}"
    footers << "end"
  end

  headers << "class #{klass_name}"
  headers << "  include Interfacets::Shared::Facet"
  footers << "end"

  <<~TXT
    #{headers.join("\n")}

      include Interfacets::Shared::Facets::Schema

      view_spec #{write_source(klass.client_config.view.block)}

      entity_spec #{write_source(klass.client_config.api.block)}

      client_spec #{write_source(klass.client_config.entity.block)}
    #{footers.join("\n")}
  TXT
end