roject 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/exp/loadsaveable/foo.json +2 -1
- data/exp/loadsaveable/foo.yaml +1 -0
- data/exp/loadsaveable/foo.yml +1 -0
- data/exp/project/makers.rb +21 -0
- data/exp/project/output/testheader.h +17 -0
- data/exp/project/output/testsource.cpp +14 -0
- data/exp/project/project.yaml +9 -0
- data/exp/project/templates/header.general +17 -0
- data/exp/project/templates/source.general +14 -0
- data/lib/helpers.rb +33 -0
- data/lib/loadsaveable.rb +27 -0
- data/lib/maker.rb +78 -0
- data/lib/project.rb +46 -4
- data/lib/roject.rb +1 -1
- data/spec/{shared/loadsaveable_spec.rb → loadsaveable_spec.rb} +123 -52
- data/spec/project_spec.rb +58 -11
- data/spec/spec_require.rb +1 -3
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 208a333165807d295fc40b90cfddc1431721cfb4
|
4
|
+
data.tar.gz: b16f2f8863a41781887024765afbe592ad461503
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0adfc93d7dc2c1add24a6537b217821a30a45f3e4b241036e55229c8a4fbe49169980af3fb1041fe3da14a74ec569ed16edbafc85e97f4fad040dc157747c6c
|
7
|
+
data.tar.gz: 2e395a73765997c907e5ebd83b0805c1e5abcf6384cfdf329a8a0328c03c48f4038bde95ab73d28b343e25baa534be836855d52b19295c8617b9e5f7a0f5c6fc
|
data/README.md
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
# Roject
|
2
2
|
|
3
|
-
Roject is a programming project manager written in Ruby. With Roject, you can create and edit projects based on templates using simple commands without a heavy IDE.
|
3
|
+
Roject is a programming project manager written in Ruby. With Roject, you can create and edit projects based on templates and using simple, customisable commands without a heavy IDE.
|
data/exp/loadsaveable/foo.json
CHANGED
data/exp/loadsaveable/foo.yaml
CHANGED
data/exp/loadsaveable/foo.yml
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Header file
|
2
|
+
file :header,
|
3
|
+
path: "include/@(project_name)/@(path)",
|
4
|
+
template: "templates/header.general",
|
5
|
+
extension: "h"
|
6
|
+
|
7
|
+
# Source file
|
8
|
+
file :source,
|
9
|
+
path: "src/@(path)",
|
10
|
+
template: "templates/source.general",
|
11
|
+
extension: "cpp"
|
12
|
+
|
13
|
+
# Module includes a source and include
|
14
|
+
task :module do |args|
|
15
|
+
# Add header id
|
16
|
+
args[:header_id] = c_header_id(args[:path])
|
17
|
+
|
18
|
+
# Create source and header
|
19
|
+
make :header, args
|
20
|
+
make :source, args
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Program: Dre
|
4
|
+
|
5
|
+
Nowadays everybody wanna talk like they got somethin' to say but nothin' comes out when they move their lips just a bunch of gibberish and they all acting like they forgot about Dre.
|
6
|
+
|
7
|
+
Author: Anshul Kharbanda
|
8
|
+
Created: 7 - 23 - 2016
|
9
|
+
|
10
|
+
*/
|
11
|
+
|
12
|
+
#ifndef _PATH_TO_FILE_H_
|
13
|
+
#define _PATH_TO_FILE_H_
|
14
|
+
|
15
|
+
// Code
|
16
|
+
|
17
|
+
#endif
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Program: Dre
|
4
|
+
|
5
|
+
Nowadays everybody wanna talk like they got somethin' to say but nothin' comes out when they move their lips just a bunch of gibberish and they all acting like they forgot about Dre.
|
6
|
+
|
7
|
+
Author: Anshul Kharbanda
|
8
|
+
Created: 7 - 23 - 2016
|
9
|
+
|
10
|
+
*/
|
11
|
+
|
12
|
+
#include "Dre/path/to/file.h"
|
13
|
+
|
14
|
+
// Code
|
data/exp/project/project.yaml
CHANGED
@@ -0,0 +1,9 @@
|
|
1
|
+
---
|
2
|
+
project_name: Dre
|
3
|
+
author: Anshul Kharbanda
|
4
|
+
created: 7 - 23 - 2016
|
5
|
+
short_description: Forgot about Dre.
|
6
|
+
long_description: Nowadays everybody wanna talk like they got somethin' to say but nothin' comes out when they move their lips just a bunch of gibberish and they all acting like they forgot about Dre.
|
7
|
+
directories:
|
8
|
+
- include
|
9
|
+
- src
|
data/lib/helpers.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
Program: Roject
|
4
|
+
|
5
|
+
Roject is a programming project manager written in Ruby.
|
6
|
+
With Roject, you can create and edit projects based on templates
|
7
|
+
using simple commands without a heavy IDE.
|
8
|
+
|
9
|
+
Author: Anshul Kharbanda
|
10
|
+
Created: 7 - 8 - 2016
|
11
|
+
|
12
|
+
=end
|
13
|
+
|
14
|
+
# Roject is a programming project manager written in Ruby.
|
15
|
+
#
|
16
|
+
# Author: Anshul Kharbanda
|
17
|
+
# Created: 7 - 8 - 2016
|
18
|
+
module Roject
|
19
|
+
# Helpers for Roject projects
|
20
|
+
#
|
21
|
+
# Author: Anshul Kharbanda
|
22
|
+
# Created: 7 - 8 - 2016
|
23
|
+
module Helpers
|
24
|
+
# Generates a c header id for the given path
|
25
|
+
# this is an identifier used for checking if
|
26
|
+
# the header has been implemented
|
27
|
+
#
|
28
|
+
# Parameters: path - the path being converted
|
29
|
+
#
|
30
|
+
# Return: a c header id generated from the given path
|
31
|
+
def c_header_id(path); "_#{path.upcase.gsub(/\/|\\/, "_")}_H_"; end
|
32
|
+
end
|
33
|
+
end
|
data/lib/loadsaveable.rb
CHANGED
@@ -64,6 +64,33 @@ module Roject
|
|
64
64
|
def load filename
|
65
65
|
self.new Parsers.get(filename).parse IO.read filename
|
66
66
|
end
|
67
|
+
|
68
|
+
# Defines getter methods for the given names
|
69
|
+
# each retrieve the value of name in the hash
|
70
|
+
#
|
71
|
+
# Parameter: names - the names to define
|
72
|
+
def get *names
|
73
|
+
unless names.empty?
|
74
|
+
names.each do |name|
|
75
|
+
#add name to attributes list
|
76
|
+
@attributes ||= []
|
77
|
+
@attributes << name
|
78
|
+
|
79
|
+
# define method name
|
80
|
+
define_method(name) { hash[name] }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Returns all attributes that are
|
86
|
+
# part of the LoadSaveable implementation
|
87
|
+
#
|
88
|
+
# Return: all attributes that are
|
89
|
+
# part of the LoadSaveable
|
90
|
+
# implementation
|
91
|
+
def attributes
|
92
|
+
@attributes or []
|
93
|
+
end
|
67
94
|
end
|
68
95
|
|
69
96
|
# Methods that are implemented at the instance level
|
data/lib/maker.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
Program: Roject
|
4
|
+
|
5
|
+
Roject is a programming project manager written in Ruby.
|
6
|
+
With Roject, you can create and edit projects based on templates
|
7
|
+
using simple commands without a heavy IDE.
|
8
|
+
|
9
|
+
Author: Anshul Kharbanda
|
10
|
+
Created: 7 - 8 - 2016
|
11
|
+
|
12
|
+
=end
|
13
|
+
|
14
|
+
# Libraries
|
15
|
+
require "general"
|
16
|
+
require "fileutils"
|
17
|
+
|
18
|
+
# Roject is a programming project manager written in Ruby.
|
19
|
+
#
|
20
|
+
# Author: Anshul Kharbanda
|
21
|
+
# Created: 7 - 8 - 2016
|
22
|
+
module Roject
|
23
|
+
# Runs a task with the given arguments
|
24
|
+
#
|
25
|
+
# Author: Anshul Kharbanda
|
26
|
+
# Created: 7 - 23 - 2016
|
27
|
+
class TaskMaker
|
28
|
+
# Initializes a TaskMaker with the given block
|
29
|
+
#
|
30
|
+
# Parameter: &block - the block to run on make
|
31
|
+
def initialize(&block); @block = block; end
|
32
|
+
|
33
|
+
# Runs the task with the given arguments
|
34
|
+
#
|
35
|
+
# Parameter: project - the project running the task
|
36
|
+
# Parameter: args - the args being used to run the task
|
37
|
+
def make project, args
|
38
|
+
project.instance_exec project.hash.merge(args), &@block
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Creates files according to the given credentials
|
43
|
+
#
|
44
|
+
# Author: Anshul Kharbanda
|
45
|
+
# Created: 7 - 21 - 2016
|
46
|
+
class FileMaker
|
47
|
+
# Read extension, directory, and template
|
48
|
+
attr :extension, :directory, :template
|
49
|
+
|
50
|
+
# Initializes a FileMaker from the given hash
|
51
|
+
#
|
52
|
+
# Parameter: hash - the hash to parse
|
53
|
+
def initialize hash
|
54
|
+
@path = General::GTemplate.new hash[:path]
|
55
|
+
@template = General::GIO.load hash[:template]
|
56
|
+
@extension = hash[:extension]
|
57
|
+
end
|
58
|
+
|
59
|
+
# Creates a file of the filetype with the given args
|
60
|
+
#
|
61
|
+
# Parameter: project - the project running the task
|
62
|
+
# Parameter: args - the args being used to create the file
|
63
|
+
def make project, args
|
64
|
+
# merge args with project
|
65
|
+
args.merge! project.hash
|
66
|
+
|
67
|
+
# Get path
|
68
|
+
path = "#{@path.apply(args)}.#{@extension}"
|
69
|
+
|
70
|
+
# Create directory
|
71
|
+
dir = File.dirname(path)
|
72
|
+
FileUtils.mkdir_p dir unless Dir.exist? dir
|
73
|
+
|
74
|
+
# Write template to path
|
75
|
+
@template.write(path, args)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/project.rb
CHANGED
@@ -11,8 +11,10 @@ Created: 7 - 8 - 2016
|
|
11
11
|
|
12
12
|
=end
|
13
13
|
|
14
|
-
#
|
14
|
+
# Other modules
|
15
15
|
require_relative "loadsaveable"
|
16
|
+
require_relative "helpers"
|
17
|
+
require_relative "maker"
|
16
18
|
|
17
19
|
# Roject is a programming project manager written in Ruby.
|
18
20
|
#
|
@@ -24,21 +26,61 @@ module Roject
|
|
24
26
|
# Author: Anshul Kharbanda
|
25
27
|
# Created: 7 - 10 - 2016
|
26
28
|
class Project
|
27
|
-
# Includes
|
29
|
+
# Includes
|
28
30
|
include LoadSaveable
|
31
|
+
include Helpers
|
29
32
|
|
30
33
|
# Creates a Project with the given data hash
|
31
34
|
#
|
32
35
|
# Parameter: hash - the data to be contained in the project
|
33
36
|
def initialize hash={}
|
34
37
|
@project = hash
|
38
|
+
@makers = {}
|
35
39
|
end
|
36
40
|
|
37
41
|
# Returns a hash of the data contained in the project
|
38
42
|
#
|
39
43
|
# Return: a hash of the data contained in the project
|
40
|
-
def hash
|
41
|
-
|
44
|
+
def hash; @project; end
|
45
|
+
|
46
|
+
# Attributes part of Project
|
47
|
+
get :project_name,
|
48
|
+
:author,
|
49
|
+
:created,
|
50
|
+
:short_description,
|
51
|
+
:long_description,
|
52
|
+
:directories
|
53
|
+
|
54
|
+
# Loads the makers in the file with the given filename
|
55
|
+
#
|
56
|
+
# Parameter: filename - the name of the file to read
|
57
|
+
def load_makers(filename); instance_eval(IO.read(filename)); end
|
58
|
+
|
59
|
+
# Runs the maker of the given name with the given args
|
60
|
+
#
|
61
|
+
# Parameter: name - the name of the maker to run
|
62
|
+
# Parameter: args - the args to pass to the file
|
63
|
+
def make name, args
|
64
|
+
@makers[name].make(self, args)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Creates a file maker with the given name and hash
|
68
|
+
#
|
69
|
+
# Parameter: name - the name of the maker
|
70
|
+
# Parameter: hash - the hash arguments of the maker
|
71
|
+
def file name, hash
|
72
|
+
@makers[name] = FileMaker.new(hash)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Adds the recipie specified by the given name and block
|
76
|
+
# to the makers table
|
77
|
+
#
|
78
|
+
# Parameter: name - the name of the recipie
|
79
|
+
# Parameter: block - the recipie block
|
80
|
+
#
|
81
|
+
# Throw: RuntimeError - if the name is already defined as a filetype
|
82
|
+
def task name, &block
|
83
|
+
@makers[name] = TaskMaker.new &block
|
42
84
|
end
|
43
85
|
end
|
44
86
|
end
|
data/lib/roject.rb
CHANGED
@@ -11,7 +11,9 @@ Created: 7 - 8 - 2016
|
|
11
11
|
|
12
12
|
=end
|
13
13
|
|
14
|
-
|
14
|
+
require_relative "spec_require"
|
15
|
+
|
16
|
+
# Describing LoadSaveable
|
15
17
|
#
|
16
18
|
# Implementing objects can be loaded from and saved to files in
|
17
19
|
# any of the supported data storage formats.
|
@@ -23,17 +25,25 @@ Created: 7 - 8 - 2016
|
|
23
25
|
#
|
24
26
|
# Author: Anshul Kharbanda
|
25
27
|
# Created: 7 - 11 - 2016
|
26
|
-
|
28
|
+
describe Roject::LoadSaveable do
|
27
29
|
#---------------------------------------BEFORE----------------------------------------
|
28
30
|
|
29
31
|
before :all do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
# Basic LoadSaveable implementation
|
33
|
+
class LoadSaveableClass
|
34
|
+
include Roject::LoadSaveable
|
35
|
+
def initialize(hash={}); @foo = hash; end
|
36
|
+
def hash; @foo; end
|
37
|
+
get :name, :author
|
38
|
+
end
|
39
|
+
|
40
|
+
@dir = "exp/loadsaveable"
|
41
|
+
@default_hash = { name: "project", author: "Anshul Kharbanda" }
|
42
|
+
@modded_hash = { name: "superproject", author: "Super Anshul Kharbanda" }
|
43
|
+
@pjson_name = "#{@dir}/foo.json"
|
44
|
+
@pyaml_name = "#{@dir}/foo.yaml"
|
45
|
+
@pyml_name = "#{@dir}/foo.yml"
|
46
|
+
@phony_name = "#{@dir}/foo.bar"
|
37
47
|
end
|
38
48
|
|
39
49
|
#--------------------------------------METHODS-----------------------------------------
|
@@ -47,17 +57,17 @@ shared_examples "loadsaveable" do |loadsaveable_class|
|
|
47
57
|
# Return: the created LoadSaveable
|
48
58
|
describe "::new" do
|
49
59
|
context "with no arguments" do
|
50
|
-
it "creates an empty
|
51
|
-
project =
|
52
|
-
expect(project).to be_an_instance_of
|
60
|
+
it "creates an empty LoadSaveable" do
|
61
|
+
project = LoadSaveableClass.new
|
62
|
+
expect(project).to be_an_instance_of LoadSaveableClass
|
53
63
|
expect(project.hash).to eql Hash.new
|
54
64
|
end
|
55
65
|
end
|
56
66
|
|
57
67
|
context "with a given data hash" do
|
58
|
-
it "creates a new
|
59
|
-
project =
|
60
|
-
expect(project).to be_an_instance_of
|
68
|
+
it "creates a new LoadSaveable with the given data hash" do
|
69
|
+
project = LoadSaveableClass.new @default_hash
|
70
|
+
expect(project).to be_an_instance_of LoadSaveableClass
|
61
71
|
expect(project.hash).to eql @default_hash
|
62
72
|
end
|
63
73
|
end
|
@@ -75,25 +85,25 @@ shared_examples "loadsaveable" do |loadsaveable_class|
|
|
75
85
|
#------------------------------FILETYPES------------------------------
|
76
86
|
|
77
87
|
context "with a .json filename given" do
|
78
|
-
it "returns a new
|
79
|
-
project =
|
80
|
-
expect(project).to be_an_instance_of
|
88
|
+
it "returns a new LoadSaveable from the json file with the given filename" do
|
89
|
+
project = LoadSaveableClass.load(@pjson_name)
|
90
|
+
expect(project).to be_an_instance_of LoadSaveableClass
|
81
91
|
expect(project.hash).to eql read_json(@pjson_name)
|
82
92
|
end
|
83
93
|
end
|
84
94
|
|
85
95
|
context "with a .yaml filename given" do
|
86
|
-
it "returns a new
|
87
|
-
project =
|
88
|
-
expect(project).to be_an_instance_of
|
96
|
+
it "returns a new LoadSaveable from the yaml file with the given filename" do
|
97
|
+
project = LoadSaveableClass.load(@pyaml_name)
|
98
|
+
expect(project).to be_an_instance_of LoadSaveableClass
|
89
99
|
expect(project.hash).to eql read_yaml(@pyaml_name)
|
90
100
|
end
|
91
101
|
end
|
92
102
|
|
93
103
|
context "with a .yml filename given" do
|
94
|
-
it "returns a new
|
95
|
-
project =
|
96
|
-
expect(project).to be_an_instance_of
|
104
|
+
it "returns a new LoadSaveable from the yml file with the given filename" do
|
105
|
+
project = LoadSaveableClass.load(@pyml_name)
|
106
|
+
expect(project).to be_an_instance_of LoadSaveableClass
|
97
107
|
expect(project.hash).to eql read_yaml(@pyml_name)
|
98
108
|
end
|
99
109
|
end
|
@@ -102,7 +112,7 @@ shared_examples "loadsaveable" do |loadsaveable_class|
|
|
102
112
|
|
103
113
|
context "with an unsupported file extension given" do
|
104
114
|
it "raises LoadError" do
|
105
|
-
expect {
|
115
|
+
expect { LoadSaveableClass.load(@phony_name) }.to raise_error LoadError
|
106
116
|
end
|
107
117
|
end
|
108
118
|
end
|
@@ -119,7 +129,7 @@ shared_examples "loadsaveable" do |loadsaveable_class|
|
|
119
129
|
#-------------------------------BEFORE--------------------------------
|
120
130
|
|
121
131
|
before :each do
|
122
|
-
@project =
|
132
|
+
@project = LoadSaveableClass.new @modded_hash
|
123
133
|
end
|
124
134
|
|
125
135
|
#------------------------------FILETYPES------------------------------
|
@@ -181,12 +191,12 @@ shared_examples "loadsaveable" do |loadsaveable_class|
|
|
181
191
|
# Declare project local variable
|
182
192
|
project = nil
|
183
193
|
|
184
|
-
it "loads a
|
194
|
+
it "loads a LoadSaveable from the json file with the given filename (calling #load)" do
|
185
195
|
# Declare modded_hash local variable
|
186
196
|
mhash = @modded_hash
|
187
197
|
|
188
198
|
# Open project in a block
|
189
|
-
expect {
|
199
|
+
expect { LoadSaveableClass.open @pjson_name do
|
190
200
|
# Set project to instance
|
191
201
|
project = self
|
192
202
|
|
@@ -195,13 +205,13 @@ shared_examples "loadsaveable" do |loadsaveable_class|
|
|
195
205
|
end }.not_to raise_error
|
196
206
|
end
|
197
207
|
|
198
|
-
it "evaluates the given block in the context of the loaded
|
208
|
+
it "evaluates the given block in the context of the loaded LoadSaveable" do
|
199
209
|
# Check if project was actually self, and it was successfuly modified
|
200
|
-
expect(project).to be_an_instance_of
|
210
|
+
expect(project).to be_an_instance_of LoadSaveableClass
|
201
211
|
expect(project.hash).to eql @modded_hash
|
202
212
|
end
|
203
213
|
|
204
|
-
it "saves the
|
214
|
+
it "saves the LoadSaveable when the block ends" do
|
205
215
|
# Check if the modded project was saved
|
206
216
|
expect(read_json(@pjson_name)).to eql @modded_hash
|
207
217
|
end
|
@@ -211,12 +221,12 @@ shared_examples "loadsaveable" do |loadsaveable_class|
|
|
211
221
|
# Declare project local variable
|
212
222
|
project = nil
|
213
223
|
|
214
|
-
it "loads a
|
224
|
+
it "loads a LoadSaveable from the yaml file with the given filename (calling #load)" do
|
215
225
|
# Declare modded_hash local variable
|
216
226
|
mhash = @modded_hash
|
217
227
|
|
218
228
|
# Open project in a block
|
219
|
-
expect {
|
229
|
+
expect { LoadSaveableClass.open @pyaml_name do
|
220
230
|
# Set project to instance
|
221
231
|
project = self
|
222
232
|
|
@@ -225,13 +235,13 @@ shared_examples "loadsaveable" do |loadsaveable_class|
|
|
225
235
|
end }.not_to raise_error
|
226
236
|
end
|
227
237
|
|
228
|
-
it "evaluates the given block in the context of the loaded
|
238
|
+
it "evaluates the given block in the context of the loaded LoadSaveable" do
|
229
239
|
# Check if project was actually self, and it was successfuly modified
|
230
|
-
expect(project).to be_an_instance_of
|
240
|
+
expect(project).to be_an_instance_of LoadSaveableClass
|
231
241
|
expect(project.hash).to eql @modded_hash
|
232
242
|
end
|
233
243
|
|
234
|
-
it "saves the
|
244
|
+
it "saves the LoadSaveable when the block ends" do
|
235
245
|
# Check if the modded project was saved
|
236
246
|
expect(read_yaml(@pyaml_name)).to eql @modded_hash
|
237
247
|
end
|
@@ -241,12 +251,12 @@ shared_examples "loadsaveable" do |loadsaveable_class|
|
|
241
251
|
# Declare project local variable
|
242
252
|
project = nil
|
243
253
|
|
244
|
-
it "loads a
|
254
|
+
it "loads a LoadSaveable from the yml file with the given filename (calling #load)" do
|
245
255
|
# Declare modded_hash local variable
|
246
256
|
mhash = @modded_hash
|
247
257
|
|
248
258
|
# Open project in a block
|
249
|
-
expect {
|
259
|
+
expect { LoadSaveableClass.open @pyml_name do
|
250
260
|
# Set project to instance
|
251
261
|
project = self
|
252
262
|
|
@@ -255,13 +265,13 @@ shared_examples "loadsaveable" do |loadsaveable_class|
|
|
255
265
|
end }.not_to raise_error
|
256
266
|
end
|
257
267
|
|
258
|
-
it "evaluates the given block in the context of the loaded
|
268
|
+
it "evaluates the given block in the context of the loaded LoadSaveable" do
|
259
269
|
# Check if project was actually self, and it was successfuly modified
|
260
|
-
expect(project).to be_an_instance_of
|
270
|
+
expect(project).to be_an_instance_of LoadSaveableClass
|
261
271
|
expect(project.hash).to eql @modded_hash
|
262
272
|
end
|
263
273
|
|
264
|
-
it "saves the
|
274
|
+
it "saves the LoadSaveable when the block ends" do
|
265
275
|
# Check if the modded project was saved
|
266
276
|
expect(read_yaml(@pyml_name)).to eql @modded_hash
|
267
277
|
end
|
@@ -271,7 +281,7 @@ shared_examples "loadsaveable" do |loadsaveable_class|
|
|
271
281
|
|
272
282
|
context "when filetype is unsupported" do
|
273
283
|
it "raises LoadError" do
|
274
|
-
expect {
|
284
|
+
expect { LoadSaveableClass.open(@phony_name) {} }.to raise_error LoadError
|
275
285
|
end
|
276
286
|
end
|
277
287
|
|
@@ -286,25 +296,25 @@ shared_examples "loadsaveable" do |loadsaveable_class|
|
|
286
296
|
#------------------------------FILETYPES------------------------------
|
287
297
|
|
288
298
|
context "when file is .json" do
|
289
|
-
it "loads a
|
290
|
-
project =
|
291
|
-
expect(project).to be_an_instance_of
|
299
|
+
it "loads a LoadSaveable from the json file with the given filename (calling #load) and returns it." do
|
300
|
+
project = LoadSaveableClass.open @pjson_name
|
301
|
+
expect(project).to be_an_instance_of LoadSaveableClass
|
292
302
|
expect(project.hash).to eql @default_hash
|
293
303
|
end
|
294
304
|
end
|
295
305
|
|
296
306
|
context "when file is .yaml" do
|
297
|
-
it "loads a
|
298
|
-
project =
|
299
|
-
expect(project).to be_an_instance_of
|
307
|
+
it "loads a LoadSaveable from the yaml file with the given filename (calling #load) and returns it." do
|
308
|
+
project = LoadSaveableClass.open @pyaml_name
|
309
|
+
expect(project).to be_an_instance_of LoadSaveableClass
|
300
310
|
expect(project.hash).to eql @default_hash
|
301
311
|
end
|
302
312
|
end
|
303
313
|
|
304
314
|
context "when file is .yml" do
|
305
|
-
it "loads a
|
306
|
-
project =
|
307
|
-
expect(project).to be_an_instance_of
|
315
|
+
it "loads a LoadSaveable from the yml file with the given filename (calling #load) and returns it." do
|
316
|
+
project = LoadSaveableClass.open @pyml_name
|
317
|
+
expect(project).to be_an_instance_of LoadSaveableClass
|
308
318
|
expect(project.hash).to eql @default_hash
|
309
319
|
end
|
310
320
|
end
|
@@ -313,8 +323,69 @@ shared_examples "loadsaveable" do |loadsaveable_class|
|
|
313
323
|
|
314
324
|
context "when filetype is unsupported" do
|
315
325
|
it "raises LoadError" do
|
316
|
-
expect {
|
326
|
+
expect { LoadSaveableClass.open @phony_name }.to raise_error LoadError
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
# Describing LoadSaveable::get
|
333
|
+
#
|
334
|
+
# Defines a getter method for the given name
|
335
|
+
# which retrieves the value of name in the data
|
336
|
+
# hash
|
337
|
+
#
|
338
|
+
# Parameter: name - the name to define
|
339
|
+
describe '::get' do
|
340
|
+
before :all do
|
341
|
+
@hash = { name: "foo", author: "bar", value: "baz" }
|
342
|
+
end
|
343
|
+
|
344
|
+
it 'defines methods with the given names' do
|
345
|
+
LoadSaveableClass.get *@hash.each_key
|
346
|
+
|
347
|
+
@hash.each_key do |key|
|
348
|
+
expect(LoadSaveableClass.method_defined?(key)).to be true
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
it 'defines methods which return the values in the hash at their corresponding names' do
|
353
|
+
@instance = LoadSaveableClass.new @hash
|
354
|
+
|
355
|
+
@hash.each_pair do |key, value|
|
356
|
+
expect(@instance.send(key)).to eql value
|
357
|
+
end
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
# Describing LoadSaveable::attributes
|
362
|
+
#
|
363
|
+
# Returns all attributes that are
|
364
|
+
# part of the LoadSaveable implementation
|
365
|
+
#
|
366
|
+
# Return: all attributes that are
|
367
|
+
# part of the LoadSaveable
|
368
|
+
# implementation
|
369
|
+
describe '::attributes' do
|
370
|
+
context 'with attributes set' do
|
371
|
+
it 'returns all attributes that are part of the loadsaveable implementation' do
|
372
|
+
hash = @default_hash
|
373
|
+
instance = LoadSaveableClass.new hash
|
374
|
+
|
375
|
+
LoadSaveableClass.attributes.each do |attribute|
|
376
|
+
expect(instance.send(attribute)).to eql hash[attribute]
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
context 'with no attributes set' do
|
382
|
+
it 'returns an empty array' do
|
383
|
+
class LoadSaveableClass2
|
384
|
+
include Roject::LoadSaveable
|
385
|
+
def initialize(hash={}); @bar = hash; end
|
386
|
+
def hash; @bar; end
|
317
387
|
end
|
388
|
+
expect(LoadSaveableClass2.attributes).to be_empty
|
318
389
|
end
|
319
390
|
end
|
320
391
|
end
|
data/spec/project_spec.rb
CHANGED
@@ -21,20 +21,67 @@ require_relative "spec_require"
|
|
21
21
|
# Author: Anshul Kharbanda
|
22
22
|
# Created: 7 - 8 - 2016
|
23
23
|
describe Roject::Project do
|
24
|
-
#
|
24
|
+
# Do before
|
25
|
+
before :all do
|
26
|
+
Dir.chdir "exp/project"
|
27
|
+
@project = Roject::Project.load "project.yaml"
|
28
|
+
end
|
29
|
+
|
30
|
+
# Describe Roject::Project#load_recipies
|
25
31
|
#
|
26
|
-
#
|
27
|
-
# any of the supported data storage formats.
|
32
|
+
# Loads the recipies in the file with the given filename
|
28
33
|
#
|
29
|
-
#
|
34
|
+
# Parameter: filename - the name of the file to read
|
35
|
+
describe '#load_recipies' do
|
36
|
+
it 'reads a recipies file and evaluates it in the context of the Project' do
|
37
|
+
expect { @project.load_makers("makers.rb") }.not_to raise_error
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Describe Roject::Project#make
|
30
42
|
#
|
31
|
-
#
|
32
|
-
# argument and respond to the :hash method which returns a hash of the
|
33
|
-
# data that needs to be saved
|
43
|
+
# Runs the maker of the given name with the given args
|
34
44
|
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
describe '
|
38
|
-
|
45
|
+
# Parameter: name - the name of the maker to run
|
46
|
+
# Parameter: args - the args to pass to the file
|
47
|
+
describe '#make' do
|
48
|
+
before :all do
|
49
|
+
@path = "path/to/file"
|
50
|
+
|
51
|
+
@header = {
|
52
|
+
type: :header,
|
53
|
+
out: "include/#{@project.project_name}/#{@path}.h",
|
54
|
+
text: IO.read("output/testheader.h")
|
55
|
+
}
|
56
|
+
|
57
|
+
@source = {
|
58
|
+
type: :source,
|
59
|
+
out: "src/#{@path}.cpp",
|
60
|
+
text: IO.read("output/testsource.cpp")
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
# Creating filetype
|
65
|
+
context 'with a file maker name given' do
|
66
|
+
it 'creates a file of the given type with the given arguments' do
|
67
|
+
@project.make @header[:type], path: @path, header_id: @project.c_header_id(@path)
|
68
|
+
expect(File).to be_file(@header[:out])
|
69
|
+
expect(IO.read(@header[:out])).to eql @header[:text]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Performing task
|
74
|
+
context 'with a task maker name given' do
|
75
|
+
it 'performs the task of the given name with the given arguments' do
|
76
|
+
@project.make :module, path: @path
|
77
|
+
[@header, @source].each do |file|
|
78
|
+
expect(File).to be_file(file[:out])
|
79
|
+
expect(IO.read(file[:out])).to eql file[:text]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Do afterwards
|
85
|
+
after :each do FileUtils.rmtree(@project.directories) end
|
39
86
|
end
|
40
87
|
end
|
data/spec/spec_require.rb
CHANGED
@@ -18,9 +18,7 @@ require "yaml"
|
|
18
18
|
# Required files for spec
|
19
19
|
require_relative "../lib/parsers"
|
20
20
|
require_relative "../lib/project"
|
21
|
-
|
22
|
-
# Spec shared examples
|
23
|
-
require_relative "shared/loadsaveable_spec"
|
21
|
+
require_relative "../lib/loadsaveable"
|
24
22
|
|
25
23
|
#-----------------------HASHMOD METHODS------------------------
|
26
24
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roject
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anshul Kharbanda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: general
|
@@ -81,14 +81,21 @@ files:
|
|
81
81
|
- exp/loadsaveable/foo.json
|
82
82
|
- exp/loadsaveable/foo.yaml
|
83
83
|
- exp/loadsaveable/foo.yml
|
84
|
+
- exp/project/makers.rb
|
85
|
+
- exp/project/output/testheader.h
|
86
|
+
- exp/project/output/testsource.cpp
|
84
87
|
- exp/project/project.yaml
|
88
|
+
- exp/project/templates/header.general
|
89
|
+
- exp/project/templates/source.general
|
90
|
+
- lib/helpers.rb
|
85
91
|
- lib/loadsaveable.rb
|
92
|
+
- lib/maker.rb
|
86
93
|
- lib/parsers.rb
|
87
94
|
- lib/project.rb
|
88
95
|
- lib/roject.rb
|
96
|
+
- spec/loadsaveable_spec.rb
|
89
97
|
- spec/parsers_spec.rb
|
90
98
|
- spec/project_spec.rb
|
91
|
-
- spec/shared/loadsaveable_spec.rb
|
92
99
|
- spec/spec_require.rb
|
93
100
|
homepage:
|
94
101
|
licenses:
|