Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Commit

Permalink
(#12) Refactor Plugin to be a class and allow removal.
Browse files Browse the repository at this point in the history
  • Loading branch information
nathankleyn authored and janstenpickle committed Sep 26, 2015
1 parent 0f6cce6 commit b46aeb0
Show file tree
Hide file tree
Showing 44 changed files with 668 additions and 476 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.gem
coverage
.shanty
Gemfile.lock
8 changes: 8 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ LineLength:
# problem.
ModuleFunction:
Enabled: False

# FIXME: Only enabling because we are using the singleton pattern still for the
# Env and TaskEnv classes and they store memoized values that need to be
# preserved even after mixing in. Without class vars, this does not work. We
# plan to refactor these singletons out and into class instances that are passed
# around instead as needed.
ClassVars:
Enabled: False
19 changes: 16 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
sudo: false
language: ruby
rvm:
- 2.2.0
notifications:
webhooks: https://hubot-shantytown.rhcloud.com/hubot/travis?room=#shantytow n
- 2.2.3

# We have to install Rust manually, as Travis does not yet allow multiligual
# builds. We install the latest stable Rust build.
before_install:
- mkdir ~/rust-installer
- curl -sL https://static.rust-lang.org/rustup.sh -o ~/rust-installer/rustup.sh
- sh ~/rust-installer/rustup.sh --prefix=~/rust --spec=stable -y --disable-sudo 2> /dev/null
- export PATH=~/rust/bin:$PATH
- export LD_LIBRARY_PATH=~/rust/lib:$LD_LIBRARY_PATH
- rustc --version
- cargo --version
script: bundle exec ./bin/shanty --trace test

notifications:
webhooks: https://hubot-shantytown.rhcloud.com/hubot/travis?room=#shantytown
111 changes: 0 additions & 111 deletions Gemfile.lock

This file was deleted.

1 change: 0 additions & 1 deletion examples/test-static-project-2/Shantyfile

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions examples/test-static-project/Shantyfile

This file was deleted.

File renamed without changes.
46 changes: 29 additions & 17 deletions lib/shanty/env.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
require 'i18n'
require 'logger'
require 'pathname'
require 'yaml'

require 'shanty/project_tree'

module Shanty
#
module Env
Expand All @@ -10,12 +13,17 @@ module Env

CONFIG_FILE = '.shanty.yml'

# This must be defined first due to being a class var that isn't first
# first accessed with ||=.
@@config = nil

def clear!
@logger = nil
@environment = nil
@build_number = nil
@root = nil
@config = nil
@@logger = nil
@@environment = nil
@@build_number = nil
@@root = nil
@@config = nil
@@project_tree = nil
end

def require!
Expand All @@ -27,26 +35,34 @@ def require!
end

def logger
@logger ||= Logger.new(STDOUT)
@@logger ||= Logger.new(STDOUT).tap do |logger|
logger.formatter = proc do |_, datetime, _, msg|
"#{datetime}: #{msg}\n"
end
end
end

def environment
@environment ||= ENV['SHANTY_ENV'] || 'local'
@@environment ||= ENV['SHANTY_ENV'] || 'local'
end

def build_number
@build_number ||= (ENV['SHANTY_BUILD_NUMBER'] || 1).to_i
@@build_number ||= (ENV['SHANTY_BUILD_NUMBER'] || 1).to_i
end

def root
@root ||= find_root
@@root ||= find_root
end

def project_tree
@@project_tree ||= ProjectTree.new(root)
end

def config
return @config unless @config.nil?
return @config = {} unless File.exist?(config_path)
return @@config unless @@config.nil?
return @@config = {} unless File.exist?(config_path)
config = YAML.load_file(config_path) || {}
@config = config[environment] || {}
@@config = config[environment] || {}
end

private
Expand All @@ -66,11 +82,7 @@ def config_path
end

def find_root
if root_dir.nil?
fail "Could not find a #{CONFIG_FILE} file in this or any parent directories. \
Please run `shanty init` in the directory you want to be the root of your project structure."
end

fail I18n.t('missing_root', config_file: CONFIG_FILE) if root_dir.nil?
root_dir
end

Expand Down
9 changes: 5 additions & 4 deletions lib/shanty/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ class Graph
extend Forwardable
include Enumerable

def_delegators :@projects, :<<, :empty?, :length, :each, :values, :[], :inspect, :to_s
def_delegators :@projects, :<<, :empty?, :length, :each, :values, :[],
:inspect, :to_s

# Public: Initialise a Graph.
#
# project_path_trie -
# projects - An array of projects to use. These are expected to be pre-sorted and linked via the ProjectLinker.
# projects - An array of projects to use. These are expected to be
# pre-sorted and linked via the ProjectLinker.
def initialize(project_path_trie, projects)
@project_path_trie = project_path_trie
@projects = projects
Expand All @@ -41,8 +43,7 @@ def by_name(name)
def all_with_tags(*tags)
return [] if tags.empty?
select do |project|
project_tags = project.tags.map(&:to_sym)
tags.map(&:to_sym).all? { |tag| project_tags.include?(tag) }
tags.map(&:to_sym).all? { |tag| project.all_tags.include?(tag) }
end
end

Expand Down
Loading

0 comments on commit b46aeb0

Please sign in to comment.