Class: Marty::Config

Inherits:
Base show all
Defined in:
app/models/marty/config.rb

Defined Under Namespace

Classes: ConfigValidator

Constant Summary

Constants inherited from ActiveRecord::Base

ActiveRecord::Base::COUNT_SIG, ActiveRecord::Base::DISTINCT_SIG, ActiveRecord::Base::FIND_BY_SIG, ActiveRecord::Base::FIRST_SIG, ActiveRecord::Base::GROUP_SIG, ActiveRecord::Base::JOINS_SIG, ActiveRecord::Base::LAST_SIG, ActiveRecord::Base::LIMIT_SIG, ActiveRecord::Base::MCFLY_PT_SIG, ActiveRecord::Base::NOT_SIG, ActiveRecord::Base::ORDER_SIG, ActiveRecord::Base::PLUCK_SIG, ActiveRecord::Base::SELECT_SIG, ActiveRecord::Base::WHERE_SIG

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

get_final_attrs, get_struct_attrs, make_hash, make_openstruct, mcfly_pt

Methods inherited from ActiveRecord::Base

joins, old_joins

Class Method Details

.[](key) ⇒ Object



39
40
41
42
# File 'app/models/marty/config.rb', line 39

def self.[](key)
  entry = find_by_key(key)
  entry and entry.get_value
end

.[]=(key, value) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/marty/config.rb', line 27

def self.[]=(key, value)
  entry = find_by_key(key)
  if !entry
    entry = self.new
    entry.key = key
  end
  entry.set_value(value)
  entry.save!

  value
end

.del(key) ⇒ Object



44
45
46
47
48
49
50
51
# File 'app/models/marty/config.rb', line 44

def self.del(key)
  entry = find_by_key(key)
  if entry
    result = entry.get_value
    entry.destroy
    result
  end
end

Instance Method Details

#get_valueObject



19
20
21
# File 'app/models/marty/config.rb', line 19

def get_value
  self.value[0]
end

#set_value(v) ⇒ Object



23
24
25
# File 'app/models/marty/config.rb', line 23

def set_value(v)
  self.value = [v]
end