Class: Cog::Seed::Feature
- Inherits:
-
Object
- Object
- Cog::Seed::Feature
- Includes:
- Generator
- Defined in:
- lib/cog/seed/feature.rb
Overview
Template for a method in a target language
Instance Attribute Summary collapse
-
#access ⇒ Symbol
readonly
Access modifier.
-
#name ⇒ String
readonly
Name of the method.
-
#params ⇒ Array<Var>
readonly
List of parameters.
-
#return_type ⇒ Symbol
readonly
The return type of the feature.
-
#seed ⇒ Seed
readonly
Seed to which this feature belongs.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Sort by name.
-
#abstract? ⇒ Boolean
Is this an abstract method?.
- #desc ⇒ Object
-
#initialize(seed, name, opt = {}) ⇒ Feature
constructor
A new instance of Feature.
- #keep_name ⇒ Object
-
#returns_a_value? ⇒ Boolean
Does this feature return a value?.
- #stamp_method ⇒ Object
-
#virtual? ⇒ Boolean
Is this a virtual method?.
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(seed, name, opt = {}) ⇒ Feature
Returns a new instance of Feature.
31 32 33 34 35 36 37 38 39 |
# File 'lib/cog/seed/feature.rb', line 31 def initialize(seed, name, opt={}) @seed = seed @name = name.to_s.to_ident @access = (opt[:access] || :private).to_sym @abstract = !!opt[:abstract] @virtual = !!opt[:virtual] @params = [] # [Var] @return_type = :void end |
Instance Attribute Details
#access ⇒ Symbol (readonly)
Returns access modifier. One of ‘:public`, `:protected`, or `:private`.
14 15 16 |
# File 'lib/cog/seed/feature.rb', line 14 def access @access end |
#name ⇒ String (readonly)
Returns name of the method.
17 18 19 |
# File 'lib/cog/seed/feature.rb', line 17 def name @name end |
#params ⇒ Array<Var> (readonly)
Returns list of parameters.
20 21 22 |
# File 'lib/cog/seed/feature.rb', line 20 def params @params end |
#return_type ⇒ Symbol (readonly)
Returns the return type of the feature.
23 24 25 |
# File 'lib/cog/seed/feature.rb', line 23 def return_type @return_type end |
#seed ⇒ Seed (readonly)
Returns seed to which this feature belongs.
11 12 13 |
# File 'lib/cog/seed/feature.rb', line 11 def seed @seed end |
Instance Method Details
#<=>(other) ⇒ Object
Sort by name
71 72 73 |
# File 'lib/cog/seed/feature.rb', line 71 def <=>(other) @name <=> other.name end |
#abstract? ⇒ Boolean
Returns is this an abstract method?.
42 43 44 |
# File 'lib/cog/seed/feature.rb', line 42 def abstract? @abstract end |
#desc ⇒ Object
56 57 58 |
# File 'lib/cog/seed/feature.rb', line 56 def desc @desc || 'Undocumented' end |
#keep_name ⇒ Object
60 61 62 |
# File 'lib/cog/seed/feature.rb', line 60 def keep_name "#{@seed.name}_#{@name}" end |
#returns_a_value? ⇒ Boolean
Returns does this feature return a value?.
52 53 54 |
# File 'lib/cog/seed/feature.rb', line 52 def returns_a_value? @return_type != :void end |
#stamp_method ⇒ Object
64 65 66 67 68 |
# File 'lib/cog/seed/feature.rb', line 64 def stamp_method l = Cog.active_language ext = @seed.in_header? ? l.seed_header : l.seed_extension stamp "cog/#{l.key}/feature.#{ext}" end |
#virtual? ⇒ Boolean
Returns is this a virtual method?.
47 48 49 |
# File 'lib/cog/seed/feature.rb', line 47 def virtual? @abstract || @virtual end |