Added v 0.2.3 snapshot.
[twitter4r-core.git] / lib / twitter / meta.rb
blob3f9968af213938a8cc16c8bc5ff48fa2b3e9fabf
1 # meta.rb contains <tt>Twitter::Meta</tt> and related classes that
2 # help define the metadata of the <tt>Twitter4R</tt> project.
4 require('rubygems')
5 require('erb')
7 class Twitter::Meta #:nodoc:
8   attr_accessor :root_dir
9   attr_reader :gem_spec, :project_files, :spec_files
11   # Initializer for Twitter::Meta class.  Takes <tt>root_dir</tt> as parameter.
12   def initialize(root_dir)
13     @root_dir = root_dir
14   end
16   # Returns package information defined in <tt>root_dir</tt>/pkg-info.yml
17   def pkg_info
18     yaml_file = File.join(@root_dir, 'pkg-info.yml')
19     ryaml = ERB.new(File.read(yaml_file), 0)
20     s = ryaml.result(binding)
21     YAML.load(s)
22   end
23   
24   # Returns RubyGems spec information
25   def spec_info
26     self.pkg_info['spec'] if self.pkg_info
27   end
28   
29   # Returns list of project files
30   def project_files
31     @project_files ||= Dir.glob(File.join(@root_dir, 'lib/**/*.rb'))
32     @project_files
33   end
34   
35   # Returns list of specification files
36   def spec_files
37     @spec_files ||= Dir.glob(File.join(@root_dir, 'spec/**/*.rb'))
38     @spec_files
39   end
40   
41   # Returns RubyGem specification for Twitter4R project
42   def gem_spec
43     @gem_spec ||= Gem::Specification.new do |spec|
44       self.spec_info.each do |key, val|
45         if val.is_a?(Hash)
46           val.each do |k, v|
47             spec.send(key, k, v)
48           end
49         else
50           spec.send("#{key}=", val)
51         end
52       end
53     end
54     @gem_spec
55   end
56 end