Class: AxR::App
Constant Summary collapse
- LayerConflictError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#default_options ⇒ Object
readonly
Returns the value of attribute default_options.
-
#layers ⇒ Object
readonly
Returns the value of attribute layers.
Instance Method Summary collapse
- #define(default_options = {}, &block) ⇒ Object
-
#initialize ⇒ App
constructor
A new instance of App.
- #layer(layer_name, options = {}) ⇒ Object
- #layer_names ⇒ Object
-
#legal?(context, dependncy) ⇒ Boolean
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity.
Constructor Details
#initialize ⇒ App
Returns a new instance of App.
15 16 17 |
# File 'lib/axr/app.rb', line 15 def initialize @layers = [] end |
Instance Attribute Details
#default_options ⇒ Object (readonly)
Returns the value of attribute default_options.
13 14 15 |
# File 'lib/axr/app.rb', line 13 def @default_options end |
#layers ⇒ Object (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( = {}, &block) @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, = {}) check_name_conflict!(layer_name) layers << AxR::Layer.new(layer_name, layers.size, .merge()) end |
#layer_names ⇒ Object
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
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 |