Class: Stratagem::Model::Containers::Base

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/stratagem/model/containers/base.rb

Direct Known Subclasses

Plugin, Route

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_model) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
# File 'lib/stratagem/model/containers/base.rb', line 7

def initialize(app_model)
  @app_model = app_model
  @components = Set.new()
  @parse_trees = {}
  @invalid = []
  @missing = {}
end

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.



5
6
7
# File 'lib/stratagem/model/containers/base.rb', line 5

def components
  @components
end

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/stratagem/model/containers/base.rb', line 5

def errors
  @errors
end

#invalidObject (readonly)

Returns the value of attribute invalid.



5
6
7
# File 'lib/stratagem/model/containers/base.rb', line 5

def invalid
  @invalid
end

#missingObject (readonly)

Returns the value of attribute missing.



5
6
7
# File 'lib/stratagem/model/containers/base.rb', line 5

def missing
  @missing
end

#parse_treesObject (readonly)

Returns the value of attribute parse_trees.



5
6
7
# File 'lib/stratagem/model/containers/base.rb', line 5

def parse_trees
  @parse_trees
end

Instance Method Details

#-(other) ⇒ Object



34
35
36
# File 'lib/stratagem/model/containers/base.rb', line 34

def -(other)
  @components-other
end

#<<(component) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/stratagem/model/containers/base.rb', line 46

def << (component)
  if (component.kind_of?(Array))
    component.each {|e| 
      @components << e 
      e.app_model = @app_model if e.methods_include?(:app_model=)
    }
  elsif (component.kind_of?(Exception))
    errors << component
  else
    @components << component
    component.app_model = @app_model if component.methods_include?(:app_model=)
  end
end

#clearObject



26
27
28
# File 'lib/stratagem/model/containers/base.rb', line 26

def clear
  @components.clear
end

#eachObject



38
39
40
# File 'lib/stratagem/model/containers/base.rb', line 38

def each
  @components.each {|e| yield e }
end

#export(options = nil) ⇒ Object



15
16
17
18
19
20
# File 'lib/stratagem/model/containers/base.rb', line 15

def export(options=nil)
  @invalid.each {|i| i.invalid = true }
  components = @components.to_a.map {|c| c.export }.compact
  components += @invalid.to_a.map {|c| c.export }.compact
  components
end

#findObject



22
23
24
# File 'lib/stratagem/model/containers/base.rb', line 22

def find
  @components.find{|component| yield component } 
end

#mapObject



42
43
44
# File 'lib/stratagem/model/containers/base.rb', line 42

def map
  @components.map {|e| yield e }
end

#sizeObject



30
31
32
# File 'lib/stratagem/model/containers/base.rb', line 30

def size
  @components.size
end