Class: Igniter::Embed::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/igniter/embed/config.rb

Defined Under Namespace

Classes: ContractRegistration

Constant Summary collapse

UNSET =
Object.new.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:) ⇒ Config

Returns a new instance of Config.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/igniter/embed/config.rb', line 14

def initialize(name:)
  @name = name.to_sym
  @cache = true
  @root = nil
  @owner = nil
  @packs = []
  @contract_registrations = []
  @contractable_configs = []
  @discovery_enabled = false
  @discovery_pattern = "**/*_contract.rb"
  @capture_exceptions = false
  @executor_name = :inline
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



10
11
12
# File 'lib/igniter/embed/config.rb', line 10

def cache
  @cache
end

#capture_exceptionsObject

Returns the value of attribute capture_exceptions.



10
11
12
# File 'lib/igniter/embed/config.rb', line 10

def capture_exceptions
  @capture_exceptions
end

#contract_registrationsObject (readonly)

Returns the value of attribute contract_registrations.



8
9
10
# File 'lib/igniter/embed/config.rb', line 8

def contract_registrations
  @contract_registrations
end

#contractable_configsObject (readonly)

Returns the value of attribute contractable_configs.



8
9
10
# File 'lib/igniter/embed/config.rb', line 8

def contractable_configs
  @contractable_configs
end

#discovery_patternObject (readonly)

Returns the value of attribute discovery_pattern.



8
9
10
# File 'lib/igniter/embed/config.rb', line 8

def discovery_pattern
  @discovery_pattern
end

#executor_nameObject

Returns the value of attribute executor_name.



10
11
12
# File 'lib/igniter/embed/config.rb', line 10

def executor_name
  @executor_name
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/igniter/embed/config.rb', line 8

def name
  @name
end

#packsObject (readonly)

Returns the value of attribute packs.



8
9
10
# File 'lib/igniter/embed/config.rb', line 8

def packs
  @packs
end

Instance Method Details

#cache?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/igniter/embed/config.rb', line 98

def cache?
  !!cache
end

#capture_exceptions?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/igniter/embed/config.rb', line 106

def capture_exceptions?
  !!capture_exceptions
end

#contract(definition, as: nil) ⇒ Object



44
45
46
47
# File 'lib/igniter/embed/config.rb', line 44

def contract(definition, as: nil)
  contract_registrations << ContractRegistration.new(definition: definition, name: as)
  self
end

#contractable(config) ⇒ Object



49
50
51
52
53
54
# File 'lib/igniter/embed/config.rb', line 49

def contractable(config)
  raise DuplicateContractError, "contractable #{config.name} is already configured" if contractable_registered?(config.name)

  contractable_configs << config
  self
end

#contractable_config(name) ⇒ Object



56
57
58
59
# File 'lib/igniter/embed/config.rb', line 56

def contractable_config(name)
  key = name.to_sym
  contractable_configs.find { |contractable_config| contractable_config.name == key }
end

#contracts(&block) ⇒ Object



61
62
63
64
65
# File 'lib/igniter/embed/config.rb', line 61

def contracts(&block)
  builder = ContractsBuilder.new(config: self)
  evaluate_builder_block(builder, &block) if block
  self
end

#discover!(pattern: "**/*_contract.rb") ⇒ Object



92
93
94
95
96
# File 'lib/igniter/embed/config.rb', line 92

def discover!(pattern: "**/*_contract.rb")
  @discovery_enabled = true
  @discovery_pattern = pattern
  self
end

#discovery_enabled?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/igniter/embed/config.rb', line 102

def discovery_enabled?
  !!@discovery_enabled
end

#owner(value = UNSET) ⇒ Object



33
34
35
36
37
38
# File 'lib/igniter/embed/config.rb', line 33

def owner(value = UNSET)
  return @owner if value.equal?(UNSET)

  @owner = value
  self
end

#owner=(value) ⇒ Object



40
41
42
# File 'lib/igniter/embed/config.rb', line 40

def owner=(value)
  owner(value)
end

#pack(pack) ⇒ Object



28
29
30
31
# File 'lib/igniter/embed/config.rb', line 28

def pack(pack)
  packs << pack
  self
end

#path(value = nil) ⇒ Object



78
79
80
81
82
# File 'lib/igniter/embed/config.rb', line 78

def path(value = nil)
  return root if value.nil?

  root(resolve_path(value))
end

#path=(value) ⇒ Object



84
85
86
# File 'lib/igniter/embed/config.rb', line 84

def path=(value)
  path(value)
end

#root(path = nil) ⇒ Object



67
68
69
70
71
72
# File 'lib/igniter/embed/config.rb', line 67

def root(path = nil)
  return @root if path.nil?

  @root = File.expand_path(path.to_s)
  self
end

#root=(path) ⇒ Object



74
75
76
# File 'lib/igniter/embed/config.rb', line 74

def root=(path)
  root(path)
end

#sugar_expansionObject



88
89
90
# File 'lib/igniter/embed/config.rb', line 88

def sugar_expansion
  SugarExpansion.new(config: self)
end