pointrb 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. data/.gitignore +16 -0
  2. data/.rspec +1 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +2 -1
  5. data/Gemfile.lock +40 -26
  6. data/README.md +1 -86
  7. data/Rakefile +5 -0
  8. data/TODO.md +35 -1
  9. data/bin/pointrb +35 -0
  10. data/cucumber.yml +3 -0
  11. data/features/create_layout.feature +96 -0
  12. data/features/create_new_project.feature +29 -0
  13. data/features/pointrb_setup.feature +22 -0
  14. data/features/step_definitions.rb +96 -0
  15. data/features/support/env.rb +26 -0
  16. data/features/support/helper.rb +62 -0
  17. data/features/test.feature +0 -0
  18. data/gemfiles/Gemfile.default +2 -1
  19. data/lib/bob_the_helper/command/command_result.rb +12 -0
  20. data/lib/bob_the_helper/command.rb +49 -0
  21. data/lib/bob_the_helper/environment.rb +27 -0
  22. data/lib/bob_the_helper/file_system/exceptions.rb +11 -0
  23. data/lib/bob_the_helper/file_system.rb +245 -0
  24. data/lib/bob_the_helper.rb +5 -0
  25. data/lib/pointrb/actions/check_if_pointrb_has_already_been_initialized.rb +15 -0
  26. data/lib/pointrb/actions/check_project_path.rb +15 -0
  27. data/lib/pointrb/actions/create_layout.rb +16 -0
  28. data/lib/pointrb/actions/create_project_wrapper.rb +15 -0
  29. data/lib/pointrb/actions/determine_layout_directory.rb +14 -0
  30. data/lib/pointrb/actions/error_handler_commandline.rb +39 -0
  31. data/lib/pointrb/actions/initialize_pointrb.rb +15 -0
  32. data/lib/pointrb/actions/retrieve_layout_files.rb +16 -0
  33. data/lib/pointrb/actions/retrieve_parsed_layout.rb +17 -0
  34. data/lib/pointrb/actions/set_project_name.rb +15 -0
  35. data/lib/pointrb/actions/show_pointrb_version.rb +14 -0
  36. data/lib/pointrb/api.rb +36 -0
  37. data/lib/pointrb/directory.rb +25 -0
  38. data/lib/pointrb/exceptions.rb +22 -0
  39. data/lib/pointrb/layout.rb +16 -0
  40. data/lib/pointrb/layout_constructor.rb +58 -0
  41. data/lib/pointrb/layout_file.rb +24 -0
  42. data/lib/pointrb/layout_manager.rb +32 -0
  43. data/lib/pointrb/layout_storage_manager.rb +40 -0
  44. data/lib/pointrb/layout_tree.rb +45 -0
  45. data/lib/pointrb/pointrb_file.rb +33 -0
  46. data/lib/pointrb/project.rb +11 -0
  47. data/lib/pointrb/version.rb +1 -1
  48. data/lib/pointrb.rb +32 -0
  49. data/pointrb.gemspec +3 -2
  50. data/script/terminal +1 -0
  51. data/spec/bob_the_helper/command/command_spec.rb +55 -0
  52. data/spec/bob_the_helper/environment/environment_spec.rb +15 -0
  53. data/spec/bob_the_helper/file_system/file_system_spec.rb +279 -0
  54. data/spec/directory/directory_spec.rb +30 -0
  55. data/spec/hooks.rb +5 -0
  56. data/spec/layout/layout_spec.rb +20 -0
  57. data/spec/layout_constructor/layout_constructor_spec.rb +122 -0
  58. data/spec/layout_file/layout_file_spec.rb +49 -0
  59. data/spec/layout_manager/layout_manager_spec.rb +47 -0
  60. data/spec/layout_storage_manager/layout_storage_manager_spec.rb +58 -0
  61. data/spec/layout_tree/layout_tree_spec.rb +70 -0
  62. data/spec/pointrb_file/pointrb_file_spec.rb +34 -0
  63. data/spec/project/project_spec.rb +19 -0
  64. data/spec/spec_helper.rb +9 -13
  65. data/spec/support/capture.rb +19 -0
  66. data/spec/support/env.rb +0 -0
  67. data/spec/support/helper.rb +8 -0
  68. data/spec/support/hooks.rb +5 -0
  69. metadata +104 -5
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ module PointRb
3
+
4
+ class Directory
5
+
6
+ attr_accessor :path, :base_dir
7
+
8
+ def initialize(path,base_dir="")
9
+ @path = path
10
+ @base_dir = base_dir
11
+ end
12
+
13
+ def full_path
14
+ if @path =~ /^\//
15
+ @path
16
+ else
17
+ File.join(@base_dir, @path)
18
+ end
19
+ end
20
+
21
+ def create
22
+ FileUtils.mkdir_p full_path
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ #encoding: utf-8
2
+ module PointRb
3
+ module Exceptions
4
+ # Raised if file does not exist
5
+ class FileNotFound < Exception; end
6
+
7
+ # Raised if requested layout was not
8
+ # available
9
+ class LayoutNotFound < Exception; end
10
+
11
+ # Raised if one has a layout with an
12
+ # invalid syntax
13
+ class SyntaxErrorInLayout < Exception; end
14
+
15
+ # Raised if project path exists
16
+ class ProjectPathExists < Exception; end
17
+
18
+ # Raised if one tries to initialize a system
19
+ # which has already been initialized
20
+ class Exceptions::PointRbWasAlreadInitialized < Exception; end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ #encoding: utf-8
2
+ module PointRb
3
+ # layouts
4
+ class Layout
5
+ attr_accessor :name, :actions
6
+
7
+ def initialize
8
+ @actions = []
9
+ end
10
+
11
+ def create
12
+ @actions.each { |a| a.create }
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,58 @@
1
+ # encoding: utf-8
2
+ module PointRb
3
+ class LayoutConstructor
4
+
5
+ def initialize(project)
6
+ @project = project
7
+ @layout = Layout.new
8
+
9
+ #this is the root directory and will be used by all other
10
+ #child nodes
11
+ root_node = Directory.new(@project.path)
12
+ @tree = LayoutTree.new(root_node)
13
+ end
14
+
15
+ def parse_dsl(content, path)
16
+
17
+ begin
18
+ instance_eval(content, path)
19
+ rescue Exception => e
20
+ file, line_number = filter_file_and_line_number(e.backtrace.first)
21
+ raise Exceptions::SyntaxErrorInLayout, "Syntax error in layout-file \"#{file}\" at line #{line_number}."
22
+ end
23
+
24
+ @layout.actions = @tree.serialize do |node|
25
+ #set base_dir based on parent directory
26
+ node.content.base_dir = node.parent.content.full_path if node.parent
27
+ #return the Directory-object
28
+ node.content
29
+ end
30
+
31
+ @layout
32
+ end
33
+
34
+ private
35
+
36
+ def filter_file_and_line_number(backtrace)
37
+ backtrace.split(':')[0..1]
38
+ end
39
+
40
+ def layout(name, &block)
41
+ @layout.name = name.to_sym
42
+
43
+ block.call
44
+ end
45
+
46
+ def directory(path, &block)
47
+ @tree.add_node Directory.new(path)
48
+ block.call if block
49
+ @tree.up
50
+ end
51
+
52
+ def file(path, &block)
53
+ content = block.call.to_s
54
+ @tree.add_node PointRbFile.new(path, content)
55
+ @tree.up
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,24 @@
1
+ #encoding: utf-8
2
+ module PointRb
3
+ # layouts
4
+ class LayoutFile
5
+
6
+ include Comparable
7
+
8
+ attr_reader :path
9
+
10
+ def initialize(path)
11
+ raise Exceptions::FileNotFound, "You tell me to use '#{path}' as path to the layout. But this file does not exist." unless File.exists? path
12
+
13
+ @path = path
14
+ end
15
+
16
+ def content
17
+ File.read(@path)
18
+ end
19
+
20
+ def <=>(other)
21
+ self.path <=> other.path
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ module PointRb
3
+ class LayoutManager
4
+
5
+ def initialize(layout_files, project)
6
+ @layout_files = layout_files
7
+ @project = project
8
+
9
+ @layout_contructor = LayoutConstructor.new(project)
10
+ @layouts = @layout_files.collect { |f| construct_layout(f.content, f.path) }
11
+ end
12
+
13
+ def retrieve(name)
14
+ result_of_search = @layouts.find { |l| l.name == name }
15
+
16
+ raise Exceptions::LayoutNotFound, "Sorry I'm not able to find the requested layout file (#{name}). Please make sure it's avaiable at the layout directory." unless result_of_search
17
+
18
+ result_of_search
19
+ end
20
+
21
+ private
22
+
23
+ def construct_layout(content, path)
24
+ @layout_contructor.parse_dsl(content, path)
25
+ end
26
+
27
+ #def retrieve_all
28
+ # @layouts
29
+ #end
30
+
31
+ end
32
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ module PointRb
3
+ class LayoutStorageManager
4
+ private
5
+
6
+ include BobTheHelper::FileSystem
7
+
8
+ public
9
+
10
+ def initialize(layout_directory, layout_file=LayoutFile)
11
+ @layout_directory = layout_directory
12
+ @layout_file_klass = layout_file
13
+ @layout_files = retrieve_layout_files('*.layout')
14
+ end
15
+
16
+ def retrieve(path)
17
+ @layout_files.find { |l| l.path == path}
18
+ end
19
+
20
+ def retrieve_all
21
+ @layout_files
22
+ end
23
+
24
+ private
25
+
26
+ def retrieve_layout_files(filter)
27
+ pattern = File.join(working_directory, "#{filter}")
28
+ layout_files = Dir.glob(pattern)
29
+ layout_files.collect { |f| @layout_file_klass.new(f) }
30
+ end
31
+
32
+ def root_directory
33
+ @layout_directory
34
+ end
35
+
36
+ def working_directory
37
+ root_directory
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,45 @@
1
+ #encoding: utf-8
2
+ module PointRb
3
+ class LayoutTree
4
+
5
+ attr_reader :tree, :active_node
6
+
7
+ def initialize(root_node)
8
+ @counter = -1
9
+ @tree = Tree::TreeNode.new(node_id, root_node)
10
+ @active_node = @tree
11
+ @prng = Random.new
12
+ end
13
+
14
+ def add_node(node)
15
+ node = Tree::TreeNode.new(node_id, node)
16
+ @active_node << node
17
+ @active_node = node
18
+ end
19
+
20
+ def up
21
+ @active_node = @active_node.parent
22
+ end
23
+
24
+ def serialize(&block)
25
+ serialized_tree = []
26
+
27
+ #default action during serialize
28
+ block = lambda { |node| node.content } unless block
29
+ @tree.each do |node|
30
+ serialized_tree << block.call(node)
31
+ end
32
+
33
+ serialized_tree
34
+ end
35
+
36
+ private
37
+
38
+ def node_id
39
+ @counter += 1
40
+
41
+ "node#{@counter}"
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,33 @@
1
+ #encoding: utf-8
2
+ module PointRb
3
+ class PointRbFile
4
+
5
+ attr_accessor :path, :base_dir, :content
6
+
7
+ def initialize(path, content)
8
+ @path = path
9
+ @base_dir = ''
10
+ @content = canonize_string(content)
11
+ end
12
+
13
+ def full_path
14
+ if @path =~ /^\//
15
+ @path
16
+ else
17
+ File.join(@base_dir, @path)
18
+ end
19
+ end
20
+
21
+ def create
22
+ File.open(full_path, "wb") do |f|
23
+ f.write content
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def canonize_string(str)
30
+ str.strip_heredoc.gsub(/^\n/, '')
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ #encoding: utf-8
2
+ module PointRb
3
+ class Project
4
+ attr_reader :name, :path
5
+
6
+ def initialize(name)
7
+ @name = name
8
+ @path = File.join(Dir.pwd, name)
9
+ end
10
+ end
11
+ end
@@ -1,4 +1,4 @@
1
1
  # Project initializer
2
2
  module PointRb
3
- VERSION = '0.0.1'
3
+ VERSION = '0.1.0'
4
4
  end
data/lib/pointrb.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'tree'
2
+ require 'fileutils'
3
+ require 'active_support/core_ext/string/strip'
4
+ require 'middleware'
5
+
6
+ require 'bob_the_helper'
7
+
8
+ require 'pointrb/version'
9
+ require 'pointrb/exceptions'
10
+ require 'pointrb/project'
11
+ require 'pointrb/directory'
12
+ require 'pointrb/pointrb_file'
13
+ require 'pointrb/layout_tree'
14
+ require 'pointrb/layout'
15
+ require 'pointrb/layout_file'
16
+ require 'pointrb/layout_storage_manager'
17
+ require 'pointrb/layout_constructor'
18
+ require 'pointrb/layout_manager'
19
+
20
+ require 'pointrb/actions/error_handler_commandline'
21
+ require 'pointrb/actions/create_project_wrapper'
22
+ require 'pointrb/actions/check_project_path'
23
+ require 'pointrb/actions/determine_layout_directory'
24
+ require 'pointrb/actions/retrieve_layout_files'
25
+ require 'pointrb/actions/retrieve_parsed_layout'
26
+ require 'pointrb/actions/create_layout'
27
+ require 'pointrb/actions/check_if_pointrb_has_already_been_initialized'
28
+ require 'pointrb/actions/initialize_pointrb'
29
+ require 'pointrb/actions/show_pointrb_version'
30
+ require 'pointrb/api'
31
+
32
+ module PointRb; end
data/pointrb.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.version = PointRb::VERSION
9
9
  gem.authors = ["Max Meyer"]
10
10
  gem.email = ["dev@fedux.org"]
11
- gem.description = %q{Initialize project diretory base on templates}
11
+ gem.description = %q{Initialize project directory base on templates}
12
12
  gem.summary = <<-EOF
13
13
  PointRb is a project initializer which helps you to create a directory structure
14
14
  for your project. It supports profiles so that you can use different layouts for
@@ -21,6 +21,7 @@ Gem::Specification.new do |gem|
21
21
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
22
  gem.require_paths = ["lib"]
23
23
 
24
- gem.add_runtime_dependency 'active_support'
24
+ gem.add_runtime_dependency 'activesupport'
25
25
  gem.add_runtime_dependency 'middleware'
26
+ gem.add_runtime_dependency 'rubytree'
26
27
  end
data/script/terminal CHANGED
@@ -9,4 +9,5 @@ tmux.new_session(session_name: 'pointrb')
9
9
  tmux.new_window(:name => 'code', :command => "zsh -c 'vim -p lib/**/*.rb'")
10
10
  tmux.new_window(:name => 'spec', :command => "zsh -c 'vim -p spec/**/*.rb'")
11
11
  tmux.new_window(:name => 'features', :command => "zsh -c 'vim -p features/**/*.{rb,feature}'")
12
+ tmux.new_window(:name => 'doc', :command => "zsh -c 'vim -p *.md'")
12
13
  tmux.start
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe BobTheHelper::Command do
4
+
5
+ before(:each) do
6
+ cleanup_working_directory
7
+ end
8
+
9
+ it "runs commands" do
10
+ stdout = 'hello world'
11
+ command = "echo #{stdout}"
12
+ search_path = [ '/usr/bin' ]
13
+ result = run_command(command, search_path: search_path)
14
+
15
+ expect(result.stdout).to eq(stdout + "\n")
16
+ end
17
+
18
+ it "runs commands with default <root>/bin" do
19
+ end
20
+
21
+ it "takes input and run commands" do
22
+ stdin = 'hello world'
23
+ command = 'cat'
24
+ search_path = [ '/usr/bin' ]
25
+ result = run_command(command, stdin: stdin, search_path: search_path)
26
+
27
+ expect(result.stdout).to eq(stdin)
28
+ end
29
+
30
+ it "makes use of ENV" do
31
+ env = { 'THIS_IS_A_LONG_VARIABLE' => 'hello_world' }
32
+ env_output = "THIS_IS_A_LONG_VARIABLE=hello_world\n"
33
+ search_path = [ '/usr/bin' ]
34
+ command = 'env | grep THIS_IS'
35
+
36
+ result = run_command(command, env: env, search_path: search_path)
37
+ expect(result.stdout).to eq(env_output)
38
+ end
39
+
40
+ it "checks if a directory/file exists" do
41
+ file = 'blub123.txt'
42
+
43
+ switch_to_working_directory do
44
+ File.open(file, "wb") do |f|
45
+ f.write ''
46
+ end
47
+ end
48
+
49
+ result = path_exists? file
50
+ expect(result).to eq(true)
51
+
52
+ result = path_exists? 'asfdasdfsadf.txt'
53
+ expect(result).to eq(false)
54
+ end
55
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe BobTheHelper::Environment do
4
+
5
+ it "let you modify the environment of a process" do
6
+ env = { 'THIS_IS_A_LONG_VARIABLE' => 'hello_world' }
7
+
8
+ env_modified = {}
9
+ isolated_environment env do
10
+ env_modified = ENV.to_hash
11
+ end
12
+
13
+ expect( env_modified['THIS_IS_A_LONG_VARIABLE'] ).to eq(env['THIS_IS_A_LONG_VARIABLE'] )
14
+ end
15
+ end