lib/skippy/project.rb in skippy-0.2.0.a vs lib/skippy/project.rb in skippy-0.3.0.a
- old
+ new
@@ -32,12 +32,12 @@
Skippy::Project.new(Dir.pwd)
end
# @return [Skippy::Project]
def self.current_or_fail
- project = self.current
- raise ProjectNotFoundError unless project.exist?
+ project = current
+ raise ProjectNotFoundError, project.filename unless project.exist?
project
end
# Initialize a project for the provided path. If the path is within a project
# path the base path of the project will be found. Otherwise it's assumed that
@@ -50,16 +50,28 @@
@config = Skippy::Config.load(filename, defaults)
@libraries = Skippy::LibraryManager.new(self)
@modules = Skippy::ModuleManager.new(self)
end
+ # The basename for the extension's root and support folder.
+ #
+ # @return [String]
+ def basename
+ @config.get(:basename, namespace.short_name)
+ end
+
+ # @param [String] basename
+ def basename=(basename)
+ @config.set(:basename, basename)
+ end
+
# @yield [filename]
# @yieldparam [String] filename the path to custom Skippy command
- def command_files(&block)
+ def command_files
files_pattern = File.join(path, 'skippy', '**', '*.rb')
Dir.glob(files_pattern) { |filename|
- block.call(filename)
+ yield filename
}
end
# Checks if a project exist on disk. If not it's just transient.
def exist?
@@ -78,27 +90,45 @@
@path.join(sub_path)
end
# Commits the project to disk.
def save
+ @config.set(:libraries, libraries.map(&:to_h))
+ @config.set(:modules, modules.map(&:name))
@config.save_as(filename)
end
+ # @return [Pathname]
+ def extension_source
+ path.join('src')
+ end
+
+ # @return [Array<String>]
+ def sources
+ @config.get(:sources, defaults[:sources])
+ end
+
# @return [String]
def to_json
JSON.pretty_generate(@config)
end
private
+ # @return [Hash]
def defaults
{
name: 'Untitled',
description: '',
namespace: Skippy::Namespace.new('Untitled'),
+ basename: Skippy::Namespace.new('Untitled').short_name,
author: 'Unknown',
copyright: "Copyright (c) #{Time.now.year}",
license: 'None',
+ sources: %w(
+ github.com
+ bitbucket.org
+ ),
}
end
# Finds the root of a project based on any path within the project.
#