Class: Banis::ModDev::Develement

Inherits:
Object
  • Object
show all
Includes:
Entagging, FsAttachable, ModelFact::ModelHelper, StateStep, TR::CondUtils
Defined in:
lib/banis/mod_dev/develement.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Develement

Returns a new instance of Develement.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/banis/mod_dev/develement.rb', line 54

def initialize(opts = {})

  opts = {} if opts.nil?
  if not opts[:instance].nil?
    _mdl = opts[:instance]
    set_model_instance(_mdl)

  else
    _mdl = ModelFact.new_instance(_model_key)
    _mdl.did = SecureRandom.uuid
    _mdl.send("dev_project_id=", opts[:dev_project_id]) if not_empty?(opts[:dev_project_id])
    _mdl.send("title=", opts[:title]) if not_empty?(opts[:title])
    _mdl.send("notes=", opts[:notes]) if not_empty?(opts[:notes])
    _mdl.send("parent_id=", opts[:parent_id]) if not_empty?(opts[:parent_id])
    _mdl.send("tags=", opts[:tags]) if not_empty?(opts[:tags])
    set_model_instance(_mdl)
    
    init_default_status
  end

  ensure_attributes_defined

  self.class.init_model

  @children = []
 
end

Class Method Details

.init_modelObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/banis/mod_dev/develement.rb', line 39

def self.init_model
  self.record_translator do |val|
    case val
    when Array, ActiveRecord::Relation
      val.collect { |e| Develement.new(instance: e) }
    else
      if not val.nil?
        Develement.new(instance: val)
      else
        val
      end
    end
  end
end

Instance Method Details

#add_sub_develement(opts = {}) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/banis/mod_dev/develement.rb', line 82

def add_sub_develement(opts = {})
  opts = {} if opts.nil?
  opts[:parent_id] = model.did
  d = Develement.new(opts) 
  @children << d
  d
end

#saveObject



98
99
100
101
102
103
104
105
106
107
# File 'lib/banis/mod_dev/develement.rb', line 98

def save

  model.save

  @children.each do |c|
    c.parent_id = model.did if is_empty?(c.parent_id)
    c.save
  end

end

#sub_develementsObject



90
91
92
93
94
95
96
# File 'lib/banis/mod_dev/develement.rb', line 90

def sub_develements
  if model.new_record?
    @children
  else
    ModelFact.instance(Develement._model_key).find_record(parent_id: model.did)
  end
end