class Cog::DSL::SeedDSL

DSL for defining cog seeds

Attributes

seed[R]

@api developer @return [Cog::Seed] the seed which is defined by this DSL object

Public Class Methods

new(name) click to toggle source

@api developer

# File lib/cog/dsl/seed_dsl.rb, line 12
def initialize(name)
  @seed = Cog::Seed.new name
end

Public Instance Methods

constructor(&block) click to toggle source
# File lib/cog/dsl/seed_dsl.rb, line 24
def constructor(&block)
  feature :constructor, &block
end
destructor(&block) click to toggle source
# File lib/cog/dsl/seed_dsl.rb, line 28
def destructor(&block)
  feature :destructor, &block
end
feature(name, opt={}, &block) click to toggle source

Define a new feature for this seed @param name [String] name of the feature @option opt [Symbol] :access (:private) one of `:public`, `:protected`, or `private` @option opt [Boolean] :abstract (false) is this an abstract feature? If so, no implementation will be generated @option opt [Boolean] :virtual (false) is this a virtual feature? Virtual features can be replaced in subclasses @yieldparam f [FeatureDSL] use this to further specify the feature @return [nil]

# File lib/cog/dsl/seed_dsl.rb, line 57
def feature(name, opt={}, &block)
  dsl = FeatureDSL.new @seed, name, opt
  block.call dsl unless block.nil?
  f = dsl.feature
  seed_eval { @features << f }
  nil
end
in_scope(name) click to toggle source

Place classes generated by this seed in the given scope @param name [String] name of the scope @return [nil]

# File lib/cog/dsl/seed_dsl.rb, line 19
def in_scope(name)
  seed_eval { @in_scope = name.to_s }
  nil
end
method_missing(meth, *args, &block) click to toggle source

@api developer

Calls superclass method
# File lib/cog/dsl/seed_dsl.rb, line 33
def method_missing(meth, *args, &block)
  meth = meth.to_s
  if meth.end_with? '_feature'
    opt = args.last.is_a?(Hash) ? args.pop : {}
    if /(?:\b|_)(public|protected|private)(?:\b|_)/ =~ meth
      opt[:access] = $1.to_sym
    end
    if /(?:\b|_)(abstract|virtual)(?:\b|_)/ =~ meth
      opt[$1.to_sym] = true
    end
    args << opt
    feature(*args, &block)
  else
    super
  end
end

Private Instance Methods

seed_eval(&block) click to toggle source
# File lib/cog/dsl/seed_dsl.rb, line 67
def seed_eval(&block)
  @seed.instance_eval &block
end