Class: Stratagem::Model::Component::Base

Inherits:
Object
  • Object
show all
Includes:
ParseUtil
Defined in:
lib/stratagem/model/components/base.rb

Direct Known Subclasses

Controller, Model, Route, StaticFile, View

Constant Summary

Constants included from ParseUtil

ParseUtil::RUBY_OUTPUT_REGEX, ParseUtil::RUBY_REGEX

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_modelObject

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

#klassObject (readonly)

Returns the value of attribute klass.



5
6
7
# File 'lib/stratagem/model/components/base.rb', line 5

def klass
  @klass
end

#parse_treeObject (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

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/stratagem/model/components/base.rb', line 5

def path
  @path
end

#sourceObject (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

.loggerObject



18
19
20
# File 'lib/stratagem/model/components/base.rb', line 18

def self.logger
  Stratagem.logger
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

#loggerObject



14
15
16
# File 'lib/stratagem/model/components/base.rb', line 14

def logger
  Stratagem.logger
end

#nameObject



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