Class: BuildTool::Setting

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/build-tool/model/setting.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defaultObject

The default value for this setting



23
24
25
# File 'lib/build-tool/model/setting.rb', line 23

def default
  @default
end

#descriptionObject

The description for this setting



20
21
22
# File 'lib/build-tool/model/setting.rb', line 20

def description
  @description
end

#seenObject

If the setting has been seen



26
27
28
# File 'lib/build-tool/model/setting.rb', line 26

def seen
  @seen
end

Class Method Details

.export(settings, only = []) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/build-tool/model/setting.rb', line 43

def export( settings, only = [] )
    only = settings.keys if only.empty?
    values = []
    only.sort.each do |name|
        # Skip internal settings.
        next if name.start_with?( 'BUILD_TOOL.' )
        # Check for unknown settings.
        if not settings.has_key?( name )
            logger.warn( 'Unknown setting %s skipped' % name )
            next
        end
        s = settings[name]
        values << s.to_hash()
    end
    return values
end

.import(settings, new) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/build-tool/model/setting.rb', line 60

def import( settings, new )
    new.each do |v|
        if not settings.has_key?( v[:name] )
            logger.warn( 'Unknown setting %s skipped' % name )
            next
        end
        s = settings[v[:name]]
        if s.value != v[:value]
            s.value = v[:value]
            Logging.logger.root.info( 'Setting %s to "%s"' % [ s.name, s.value ] )
            s.save!
        end
    end
end

Instance Method Details

#my_initializeObject



13
14
15
16
17
# File 'lib/build-tool/model/setting.rb', line 13

def my_initialize()
    @description = nil
    @default     = ""
    @seen = false
end

#to_hashObject



34
35
36
37
38
39
# File 'lib/build-tool/model/setting.rb', line 34

def to_hash()
    return {
        :name => name,
        :value => value,
        :description => description }
end

#to_sObject



80
81
82
# File 'lib/build-tool/model/setting.rb', line 80

def to_s()
    self.value.to_s
end

#valueObject



28
29
30
31
32
# File 'lib/build-tool/model/setting.rb', line 28

def value()
    rv = read_attribute( :value )
    return @default if rv.nil?
    rv
end