Class: Igniter::Extensions::Contracts::Creator::Scaffold

Inherits:
Object
  • Object
show all
Defined in:
lib/igniter/extensions/contracts/creator/scaffold.rb

Constant Summary collapse

SUPPORTED_KINDS =
%i[feature operational bundle].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, kind:, namespace:, profile:, scope:) ⇒ Scaffold

Returns a new instance of Scaffold.



12
13
14
15
16
17
18
19
# File 'lib/igniter/extensions/contracts/creator/scaffold.rb', line 12

def initialize(name:, kind:, namespace:, profile:, scope:)
  @name = normalize_name(name)
  @kind = normalize_kind(kind)
  @namespace = normalize_namespace(namespace)
  @profile = profile
  @scope = scope
  freeze
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



10
11
12
# File 'lib/igniter/extensions/contracts/creator/scaffold.rb', line 10

def kind
  @kind
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/igniter/extensions/contracts/creator/scaffold.rb', line 10

def name
  @name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



10
11
12
# File 'lib/igniter/extensions/contracts/creator/scaffold.rb', line 10

def namespace
  @namespace
end

#profileObject (readonly)

Returns the value of attribute profile.



10
11
12
# File 'lib/igniter/extensions/contracts/creator/scaffold.rb', line 10

def profile
  @profile
end

#scopeObject (readonly)

Returns the value of attribute scope.



10
11
12
# File 'lib/igniter/extensions/contracts/creator/scaffold.rb', line 10

def scope
  @scope
end

Instance Method Details

#example_file_pathObject



41
42
43
# File 'lib/igniter/extensions/contracts/creator/scaffold.rb', line 41

def example_file_path
  "#{scope.example_root}/#{name}_pack.rb"
end

#filesObject



49
50
51
52
53
54
55
56
# File 'lib/igniter/extensions/contracts/creator/scaffold.rb', line 49

def files
  {
    pack_file_path => pack_template,
    spec_file_path => spec_template,
    example_file_path => example_template,
    readme_file_path => readme_template
  }
end

#namespace_pathObject



29
30
31
# File 'lib/igniter/extensions/contracts/creator/scaffold.rb', line 29

def namespace_path
  namespace.split("::").map { |part| underscore(part) }.join("/")
end

#pack_class_nameObject



21
22
23
# File 'lib/igniter/extensions/contracts/creator/scaffold.rb', line 21

def pack_class_name
  "#{camelize(name)}Pack"
end

#pack_constantObject



25
26
27
# File 'lib/igniter/extensions/contracts/creator/scaffold.rb', line 25

def pack_constant
  "#{namespace}::#{pack_class_name}"
end

#pack_file_pathObject



33
34
35
# File 'lib/igniter/extensions/contracts/creator/scaffold.rb', line 33

def pack_file_path
  "#{scope.root}/#{namespace_path}/#{name}_pack.rb"
end

#readme_file_pathObject



45
46
47
# File 'lib/igniter/extensions/contracts/creator/scaffold.rb', line 45

def readme_file_path
  scope.readme_path
end

#spec_file_pathObject



37
38
39
# File 'lib/igniter/extensions/contracts/creator/scaffold.rb', line 37

def spec_file_path
  "#{scope.spec_root}/#{namespace_path}/#{name}_pack_spec.rb"
end

#summaryObject



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/igniter/extensions/contracts/creator/scaffold.rb', line 58

def summary
  {
    name: name,
    kind: kind,
    namespace: namespace,
    profile: profile.to_h,
    scope: scope.to_h,
    pack_constant: pack_constant,
    files: files.keys
  }
end

#to_hObject



70
71
72
# File 'lib/igniter/extensions/contracts/creator/scaffold.rb', line 70

def to_h
  summary.merge(files: files)
end