Class: Stratagem::Model::Component::Base
- Includes:
- ParseUtil
- Defined in:
- lib/stratagem/model/components/base.rb
Direct Known Subclasses
Constant Summary
Constants included from ParseUtil
ParseUtil::RUBY_OUTPUT_REGEX, ParseUtil::RUBY_REGEX
Instance Attribute Summary collapse
-
#app_model ⇒ Object
Returns the value of attribute app_model.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#parse_tree ⇒ Object
readonly
Returns the value of attribute parse_tree.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
-
.load_all(path) ⇒ Object
loads all classes contained within a given filename.
- .logger ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(path, parse_tree, klass) ⇒ Base
constructor
A new instance of Base.
- #logger ⇒ Object
- #name ⇒ Object
Methods included from ParseUtil
find_classes, #gsub_ruby_blocks, qualified_class_name, #ruby_blocks, #ruby_output_blocks
Constructor Details
#initialize(path, parse_tree, klass) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 |
# File 'lib/stratagem/model/components/base.rb', line 8 def initialize(path, parse_tree, klass) @path = path.gsub(/.*?\/app/, 'app') @parse_tree = parse_tree @klass = klass end |
Instance Attribute Details
#app_model ⇒ Object
Returns the value of attribute app_model.
6 7 8 |
# File 'lib/stratagem/model/components/base.rb', line 6 def app_model @app_model end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
5 6 7 |
# File 'lib/stratagem/model/components/base.rb', line 5 def klass @klass end |
#parse_tree ⇒ Object (readonly)
Returns the value of attribute parse_tree.
5 6 7 |
# File 'lib/stratagem/model/components/base.rb', line 5 def parse_tree @parse_tree end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/stratagem/model/components/base.rb', line 5 def path @path end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
5 6 7 |
# File 'lib/stratagem/model/components/base.rb', line 5 def source @source end |
Class Method Details
.load_all(path) ⇒ Object
loads all classes contained within a given filename
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/stratagem/model/components/base.rb', line 28 def self.load_all(path) if (path =~ /\.rb$/) source = File.read(path) begin parse_tree = RedParse.new(source).parse puts "parsed.." Stratagem::Model::ParseUtil.find_classes(parse_tree).map {|klass| self.new(path, parse_tree, klass) } rescue logger.error($!) [] end end end |
Instance Method Details
#==(other) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/stratagem/model/components/base.rb', line 44 def ==(other) if (other.kind_of?(String)) self.path == other elsif (other.kind_of?(self.class)) self.path == other.path else raise "unknown comparison to #{other.class.name}" end end |
#logger ⇒ Object
14 15 16 |
# File 'lib/stratagem/model/components/base.rb', line 14 def logger Stratagem.logger end |
#name ⇒ Object
22 23 24 25 |
# File 'lib/stratagem/model/components/base.rb', line 22 def name classname = @klass ? @klass.name : self.class.name.gsub(/.*[^A-Z0-9a-z]/, '') "#{path}$#{classname}" end |