Sha256: ed16ca2d054657424c2ecd1ea0f4b933ee5afe0cc47af114eb50eeaeb2c3d0f4

Contents?: true

Size: 1.93 KB

Versions: 8

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.path, 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

8 entries across 8 versions & 1 rubygems

Version Path
build-tool-0.6.9 lib/build-tool/model/feature.rb
build-tool-0.6.8 lib/build-tool/model/feature.rb
build-tool-0.6.7 lib/build-tool/model/feature.rb
build-tool-0.6.6 lib/build-tool/model/feature.rb
build-tool-0.6.5 lib/build-tool/model/feature.rb
build-tool-0.6.4 lib/build-tool/model/feature.rb
build-tool-0.6.3 lib/build-tool/model/feature.rb
build-tool-0.6.2 lib/build-tool/model/feature.rb