class Cog::Seed
Template for a class in a target language
Attributes
header_path[R]
@return [String,nil] path to the header file
in_scope[R]
@return [String,nil] name of the scope in which classes generated by this seed will be found
name[R]
@return [String] name of the class
Public Class Methods
new(name)
click to toggle source
@api developer @param name [String] name of the class
# File lib/cog/seed.rb, line 22 def initialize(name) @name = name.to_s.camelize.to_ident @features = [] # [Feature] end
Public Instance Methods
<=>(other)
click to toggle source
Sort by name
# File lib/cog/seed.rb, line 63 def <=>(other) @name <=> other end
features()
click to toggle source
@return [Array<Feature>] a sorted list of features
# File lib/cog/seed.rb, line 34 def features @features.sort end
guard()
click to toggle source
@return [String] begin the include guard
# File lib/cog/seed.rb, line 28 def guard x = [@in_scope, @name].compact.collect &:upcase include_guard_begin "__COG_SPROUT__#{x.join '_'}_H__" end
in_header?()
click to toggle source
# File lib/cog/seed.rb, line 58 def in_header? @in_header end
stamp_class(path, opt={})
click to toggle source
Render the class in the currently active language @param path [String] file system path without the extension, relative to the project root. The extension will be determined based on the currently active language @option opt [String] :language key for the language to use. The language must define a seed extension
# File lib/cog/seed.rb, line 41 def stamp_class(path, opt={}) Cog.activate_language opt[:language] do l = Cog.active_language raise Errors::ActiveLanguageDoesNotSupportSeeds.new :language => l if l.nil? || l.seed_extension.nil? @in_header = false @header_path = if l.seed_header "#{path}.#{l.seed_header}" end stamp "cog/#{l.key}/seed.#{l.seed_extension}", "#{path}.#{l.seed_extension}" if l.seed_header @in_header = true stamp "cog/#{l.key}/seed.#{l.seed_header}", @header_path end end end