Sha256: 544ee813681cd8bdc2c2c5ba0ddfc661cce73e52369ba07d3027ee4e5ace240f
Contents?: true
Size: 1.93 KB
Versions: 4
Compression:
Stored size: 1.93 KB
Contents
# -*- coding: UTF-8 -*- require 'active_record' module BuildTool # A feature bundles modules and makes it possible to enable/disable them together. class Feature < ActiveRecord::Base validates_uniqueness_of :name, :scope => :parent_id # A short description for the feature attr_accessor :description # A long description for the feature attr_accessor :long_description # The default state of the feature attr_accessor :default_active # The modules associated with this feature attr_reader :modules # The environments associated with this feature attr_reader :environments # Custom initialization after_initialize :my_initialize def my_initialize @description = nil @long_description = nil @modules = [] @environments = [] @default_active = true end # Is the feature active? def active? state = active.nil? ? default_active : active if parent_id.nil? state else parent.active? && state end end # Return a character showing the features active state. def active_char if active? ANSI::Code.green { "A" } else "I" end end # Is the feature active by default? def default_active? default_active end # Return a unique name for the feature. # # The name is scoped with the parents name. def path if parent.nil? name else "%s/%s" % [ parent.name, name ] end end def to_s "Feature #{name} ( #{self.active} / #{self.default_active} )" end belongs_to :parent, :class_name => 'BuildTool::Feature' end end
Version data entries
4 entries across 4 versions & 1 rubygems