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

#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(&block) ⇒ Object



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

def define(&block)
  instance_eval(&block)
end

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



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

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

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

#layer_namesObject



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

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

#legal?(context, dependncy) ⇒ Boolean

rubocop:disable Metrics/AbcSize

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
# File 'lib/axr/app.rb', line 34

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?
  return true if ctx.familiar_with.map(&:to_s).include?(dependncy.to_s)

  ctx.level < dep.level
end