Class: AxR::App

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/axr/app.rb

Constant Summary collapse

LayerConflictError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApp

Returns a new instance of App.



15
16
17
# File 'lib/axr/app.rb', line 15

def initialize
  @layers = []
end

Instance Attribute Details

#default_optionsObject (readonly)

Returns the value of attribute default_options.



13
14
15
# File 'lib/axr/app.rb', line 13

def default_options
  @default_options
end

#layersObject (readonly)

Returns the value of attribute layers.



13
14
15
# File 'lib/axr/app.rb', line 13

def layers
  @layers
end

Instance Method Details

#define(default_options = {}, &block) ⇒ Object



19
20
21
22
# File 'lib/axr/app.rb', line 19

def define(default_options = {}, &block)
  @default_options = default_options
  instance_eval(&block)
end

#layer(layer_name, options = {}) ⇒ Object



24
25
26
27
28
# File 'lib/axr/app.rb', line 24

def layer(layer_name, options = {})
  check_name_conflict!(layer_name)

  layers << AxR::Layer.new(layer_name, layers.size, default_options.merge(options))
end

#layer_namesObject



30
31
32
# File 'lib/axr/app.rb', line 30

def layer_names
  layers.map(&:name).map(&:to_s)
end

#legal?(context, dependncy) ⇒ Boolean

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
# File 'lib/axr/app.rb', line 37

def legal?(context, dependncy)
  ctx = layers.find { |l| l.name.to_s == context.to_s }
  dep = layers.find { |l| l.name.to_s == dependncy.to_s }

  return false unless ctx && dep
  return false if ctx.isolated? && ctx.familiar_with.empty?
  return true  if ctx.familiar_with.map(&:to_s).include?(dependncy.to_s)

  ctx.level < dep.level
end