Class: Cog::Seed
- Inherits:
-
Object
- Object
- Cog::Seed
- Includes:
- Generator
- Defined in:
- lib/cog/seed.rb,
lib/cog/seed/var.rb,
lib/cog/seed/feature.rb
Overview
Template for a class in a target language
Defined Under Namespace
Instance Attribute Summary collapse
-
#header_path ⇒ String?
readonly
Path to the header file.
-
#in_scope ⇒ String?
readonly
Name of the scope in which classes generated by this seed will be found.
-
#name ⇒ String
readonly
Name of the class.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Sort by name.
-
#features ⇒ Array<Feature>
A sorted list of features.
-
#guard ⇒ String
Begin the include guard.
- #in_header? ⇒ Boolean
-
#initialize(name) ⇒ Seed
constructor
A new instance of Seed.
-
#stamp_class(path, opt = {}) ⇒ Object
Render the class in the currently active language.
Methods included from Generator
Methods included from Generator::LanguageMethods
#end_all_scopes, #include_guard_begin, #named_scope_begin, #scope_begin, #scope_end, #use_named_scope, #warning
Methods included from Generator::Filters
Methods included from Generator::FileMethods
#copy_file_if_missing, #files_are_same?, #get_template, #touch_directory, #touch_file
Constructor Details
#initialize(name) ⇒ Seed
Returns a new instance of Seed.
22 23 24 25 |
# File 'lib/cog/seed.rb', line 22 def initialize(name) @name = name.to_s.camelize.to_ident @features = [] # [Feature] end |
Instance Attribute Details
#header_path ⇒ String? (readonly)
Returns path to the header file.
15 16 17 |
# File 'lib/cog/seed.rb', line 15 def header_path @header_path end |
#in_scope ⇒ String? (readonly)
Returns name of the scope in which classes generated by this seed will be found.
18 19 20 |
# File 'lib/cog/seed.rb', line 18 def in_scope @in_scope end |
#name ⇒ String (readonly)
Returns name of the class.
12 13 14 |
# File 'lib/cog/seed.rb', line 12 def name @name end |
Instance Method Details
#<=>(other) ⇒ Object
Sort by name
63 64 65 |
# File 'lib/cog/seed.rb', line 63 def <=>(other) @name <=> other end |
#features ⇒ Array<Feature>
Returns a sorted list of features.
34 35 36 |
# File 'lib/cog/seed.rb', line 34 def features @features.sort end |
#guard ⇒ String
Returns begin the include guard.
28 29 30 31 |
# 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? ⇒ Boolean
58 59 60 |
# File 'lib/cog/seed.rb', line 58 def in_header? @in_header end |
#stamp_class(path, opt = {}) ⇒ Object
Render the class in the currently active language
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# 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 |