Class: CDQ::CDQModelManager

Inherits:
Object
  • Object
show all
Defined in:
motion/cdq/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ CDQModelManager

Returns a new instance of CDQModelManager.


8
9
10
# File 'motion/cdq/model.rb', line 8

def initialize(opts = {})
  @config = opts[:config] || CDQConfig.default
end

Instance Attribute Details

#currentObject


12
13
14
# File 'motion/cdq/model.rb', line 12

def current
  @current ||= load_model
end

Instance Method Details

#invalid?Boolean

Returns:

  • (Boolean)

16
17
18
# File 'motion/cdq/model.rb', line 16

def invalid?
  !@current && @config.model_url.nil?
end

#log(log_type = nil) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'motion/cdq/model.rb', line 20

def log(log_type = nil)
  out =   "\n\n                MODELS"
  out <<  "\n  Model                    |     count |"              
  line =  "\n - - - - - - - - - - - - - | - - - - - |"
  out << line

  self.current.entities.each do |entity| 
    out << "\n  #{entity.name.ljust(25)}|"
    out << " #{CDQ.cdq(entity.name).count.to_s.rjust(9)} |"
  end

  out << line

  entities = CDQ.cdq.models.current.entities
  if entities && (entity_count = entities.length) && entity_count > 0
    out << "\n#{entity_count} models"
    out << "\n\nYou can log a model like so: #{self.current.entities.first.name}.log"
  end

  if log_type == :string
    out
  else
    NSLog out
  end
end