Sha256: 076841564dfb967d4e40feff713ca0f850568f6421a127bc6970a1855e85fb22

Contents?: true

Size: 1.6 KB

Versions: 14

Compression:

Stored size: 1.6 KB

Contents

require 'rubygems'
require 'rake' # for ext()
require 'fileutils'
require 'constants'


# :flags:
#   :release:
#     :compile:
#       :*:          # add '-foo' to compilation of all files not main.c
#         - -foo
#       :main:       # add '-Wall' to compilation of main.c
#         - -Wall
#   :test:
#     :link:
#       :test_main:  # add '--bar --baz' to linking of test_main.exe
#         - --bar
#         - --baz


class Flaginator

  constructor :configurator

  def flag_down( operation, context, file )
    # create configurator accessor method
    accessor = ('flags_' + context.to_s).to_sym
    
    # create simple filename key from whatever filename provided
    file_key = File.basename( file ).ext('').to_sym
    
    # if no entry in configuration for flags for this context, bail out
    return [] if not @configurator.respond_to?( accessor )
    
    # get flags sub hash associated with this context
    flags = @configurator.send( accessor )

    # if operation not represented in flags hash, bail out
    return [] if not flags.include?( operation )
    
    # redefine flags to sub hash associated with the operation
    flags = flags[operation]
    
    # if our file is in the flags hash, extract the array of flags
    if (flags.include?( file_key )) then return flags[file_key]
    # if our file isn't in the flags hash, but there is default for all other files, extract array of flags
    elsif (flags.include?( :* )) then return flags[:*]
    end

    # fall through: flags were specified but none applying to present file
    return []
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ceedling-0.13.0 lib/flaginator.rb
ceedling-0.13.0.rc1 lib/flaginator.rb
ceedling-0.12.2 new_project_template/vendor/ceedling/lib/flaginator.rb
ceedling-0.12.1 new_project_template/vendor/ceedling/lib/flaginator.rb
ceedling-0.12.0 new_project_template/vendor/ceedling/lib/flaginator.rb
ceedling-0.11.2 new_project_template/vendor/ceedling/lib/flaginator.rb
ceedling-0.11.1 new_project_template/vendor/ceedling/lib/flaginator.rb
ceedling-0.11.0 new_project_template/vendor/ceedling/lib/flaginator.rb
ceedling-0.10.0 new_project_template/vendor/ceedling/lib/flaginator.rb
ceedling-0.9.4 new_project_template/vendor/ceedling/lib/flaginator.rb
ceedling-0.9.2 new_project_template/vendor/ceedling/lib/flaginator.rb
ceedling-0.9.0 new_project_template/vendor/ceedling/lib/flaginator.rb
ceedling-0.0.18 new_project_template/vendor/ceedling/lib/flaginator.rb
ceedling-0.0.17 new_project_template/vendor/ceedling/lib/flaginator.rb