Class: Cog::DSL::SeedDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/cog/dsl/seed_dsl.rb

Overview

DSL for defining cog seeds

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ SeedDSL

Returns a new instance of SeedDSL.



12
13
14
# File 'lib/cog/dsl/seed_dsl.rb', line 12

def initialize(name)
  @seed = Cog::Seed.new name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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

Instance Attribute Details

#seedCog::Seed (readonly)

Returns the seed which is defined by this DSL object.

Returns:

  • (Cog::Seed)

    the seed which is defined by this DSL object



9
10
11
# File 'lib/cog/dsl/seed_dsl.rb', line 9

def seed
  @seed
end

Instance Method Details

#constructor(&block) ⇒ Object



24
25
26
# File 'lib/cog/dsl/seed_dsl.rb', line 24

def constructor(&block)
  feature :constructor, &block
end

#destructor(&block) ⇒ Object



28
29
30
# File 'lib/cog/dsl/seed_dsl.rb', line 28

def destructor(&block)
  feature :destructor, &block
end

#feature(name, opt = {}) {|f| ... } ⇒ nil

Define a new feature for this seed

Parameters:

  • name (String)

    name of the feature

  • opt (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opt):

  • :access (Symbol) — default: :private

    one of ‘:public`, `:protected`, or `private`

  • :abstract (Boolean) — default: false

    is this an abstract feature? If so, no implementation will be generated

  • :virtual (Boolean) — default: false

    is this a virtual feature? Virtual features can be replaced in subclasses

Yield Parameters:

  • f (FeatureDSL)

    use this to further specify the feature

Returns:

  • (nil)


57
58
59
60
61
62
63
# 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) ⇒ nil

Place classes generated by this seed in the given scope

Parameters:

  • name (String)

    name of the scope

Returns:

  • (nil)


19
20
21
22
# File 'lib/cog/dsl/seed_dsl.rb', line 19

def in_scope(name)
  seed_eval { @in_scope = name.to_s }
  nil
end