jtask 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/changelist.txt +7 -1
- data/jtask.gemspec +2 -2
- data/lib/jtask.rb +2 -2
- data/lib/jtask/chop.rb +3 -3
- data/lib/jtask/destroy.rb +1 -1
- data/lib/jtask/get.rb +41 -24
- data/lib/jtask/save.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0851a01dafb0753c4883abf034310c496a3181a8
|
4
|
+
data.tar.gz: ae407131ec5fd73379f5ffe2deeb327b7578eab1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9de71bd836ab66469769925591e7764ba9753f81d98c7a5e6ca822cb6dafb2ff1f77dbcc13680cdd3e79b894bda54d337a140b2b0ef80e0c8ce3abf43c632673
|
7
|
+
data.tar.gz: 02e2d26f4009028e2cca6ca74f126ee1eec2bd7599ea4a62aab14c8e58089aceafe7be3b45077221ae81996bb8e404e56191fb99544babe76362a7ad6651b992
|
data/.gitignore
CHANGED
data/changelist.txt
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0 [Beta] [Current Version]
|
2
|
+
=====================================
|
3
|
+
- Released a major bug fix regarding the `JTask.get()` method (see: https://github.com/adammcarthur/jtask/issues/1)
|
4
|
+
- Minor code enhancements to the Get module.
|
5
|
+
- Error messages have been reformatted for both web and console use.
|
6
|
+
|
7
|
+
0.0.2 [Beta]
|
2
8
|
=====================================
|
3
9
|
- Swapped gemspec description and summary (mix up error).
|
4
10
|
|
data/jtask.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'jtask'
|
3
|
-
s.version = '0.0
|
3
|
+
s.version = '0.1.0'
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.date = '2014-03-23'
|
6
6
|
s.description = "Provides CRUD actions for JSON files, plus a few extra goodies."
|
@@ -12,5 +12,5 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.files = `git ls-files`.split($/)
|
13
13
|
s.require_paths = ["lib"]
|
14
14
|
s.add_runtime_dependency "json", "~> 1.4"
|
15
|
-
s.post_install_message = "\nThanks for installing JTask Beta. Check out the full documentation and contribute at https://github.com/adammcarthur/jtask\n\n- Adam (@adammcarth)\n-"
|
15
|
+
s.post_install_message = "\nThanks for installing JTask Beta. Check out the full documentation and contribute at https://github.com/adammcarthur/jtask\n\nIn this release (v0.1.0 Beta): Fixed a major flaw in the JTask.get() output. Read more about this error here: https://github.com/adammcarthur/jtask/issues/1\n\n- Adam (@adammcarth)\n-"
|
16
16
|
end
|
data/lib/jtask.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
###########################################################################
|
2
|
-
# ` JTask v0.0
|
2
|
+
# ` JTask v0.1.0 Beta ` #
|
3
3
|
# ` Provides CRUD actions for JSON files, plus a few extra goodies. ` #
|
4
4
|
# ` Created by Adam McArthur (@adammcarth) ` #
|
5
5
|
# ` Released under the MIT licence ` #
|
@@ -16,7 +16,7 @@ class JTask
|
|
16
16
|
modules.each do |m|
|
17
17
|
require "jtask/#{m}"
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
extend Save
|
21
21
|
extend Get
|
22
22
|
extend Update
|
data/lib/jtask/chop.rb
CHANGED
@@ -10,7 +10,7 @@ module Chop
|
|
10
10
|
|
11
11
|
# Quality control - ensure paramter is a string
|
12
12
|
unless parameter.is_a?(String)
|
13
|
-
raise SyntaxError, "The chop() method can only remove one parameter at a time
|
13
|
+
raise SyntaxError, "[JTask] The chop() method can only remove one parameter at a time - only a string can be used to specify the parameter."
|
14
14
|
end
|
15
15
|
|
16
16
|
if id.is_a?(Integer)
|
@@ -20,7 +20,7 @@ module Chop
|
|
20
20
|
insert = objects
|
21
21
|
insert["#{id}"] = removed_version
|
22
22
|
else
|
23
|
-
raise NameError, "
|
23
|
+
raise NameError, "[JTask] The id #{method} could not be found in the file \"#{dir + filename}\". The file has not been changed."
|
24
24
|
end
|
25
25
|
elsif id == :all
|
26
26
|
# Parameter must be removed from all objects
|
@@ -30,7 +30,7 @@ module Chop
|
|
30
30
|
end
|
31
31
|
insert = objects
|
32
32
|
else
|
33
|
-
raise NameError, "
|
33
|
+
raise NameError, "[JTask] Incorrect id method used. A single id (integer) can be specified, or the symbol \":all\" to remove the parameter from every object."
|
34
34
|
end
|
35
35
|
|
36
36
|
# Re-write the file with the new version.
|
data/lib/jtask/destroy.rb
CHANGED
@@ -13,7 +13,7 @@ module Destroy
|
|
13
13
|
insert = objects.tap{ |x| x.delete("#{id}") }
|
14
14
|
else
|
15
15
|
# the id doesn't exist in the file
|
16
|
-
raise NameError, "
|
16
|
+
raise NameError, "[JTask] An id of #{id} does not exsist in the file specified at \"#{dir + filename}\". Nothing has been deleted."
|
17
17
|
end
|
18
18
|
|
19
19
|
# Re-write the file with the new version.
|
data/lib/jtask/get.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# JTask.get() by Adam McArthur
|
2
|
+
# Retrieves stored JSON data from the file and returns a hash.
|
3
|
+
|
1
4
|
module Get
|
2
5
|
def get(filename, method=nil, dir=nil)
|
3
6
|
# Check if user has specified a custom directory.
|
@@ -7,36 +10,50 @@ module Get
|
|
7
10
|
end
|
8
11
|
original_file = File.read(File.join(dir, filename))
|
9
12
|
objects = JSON.parse(original_file)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
|
14
|
+
# Work out which retrieval method is wanted.
|
15
|
+
# An integer indicates we want to find a single record by id.
|
16
|
+
# A hash indicates the first/last method has been used.
|
17
|
+
|
18
|
+
# Check for integer
|
19
|
+
if method.is_a?(Integer)
|
20
|
+
# Our method will be the id - lets alias it:
|
21
|
+
id = method
|
22
|
+
|
23
|
+
if objects["#{id}"]
|
24
|
+
output = { "id" => id.to_i }.merge(objects["#{id}"])
|
25
|
+
else
|
26
|
+
# id supplied doesn't exist
|
27
|
+
raise NameError, "[JTask] The id #{method} could not be found in the file \"#{dir + filename}\"."
|
28
|
+
end
|
29
|
+
else
|
30
|
+
# Method could be either blank, invalid or a "first/last" hash.
|
31
|
+
begin
|
32
|
+
# Treat method as a hash
|
33
|
+
# Assemble hashes of the required records, as specified by the user.
|
23
34
|
if method[:first]
|
24
|
-
|
25
|
-
output = Hash[(objects.to_a).first(method[:first].to_i)]
|
35
|
+
required_records = Hash[(objects.to_a).first(method[:first].to_i)]
|
26
36
|
elsif method[:last]
|
27
|
-
|
28
|
-
|
37
|
+
required_records = Hash[(objects.to_a).last(method[:last].to_i).reverse] # wow!
|
38
|
+
end
|
39
|
+
# Rescue to prevent '[]' nil class error if method is empty
|
40
|
+
rescue
|
41
|
+
if method == nil
|
42
|
+
# We want all the records since no get method is supplied
|
43
|
+
required_records = objects
|
29
44
|
else
|
30
|
-
|
45
|
+
# Unrecognisable value used as the method, crash immediatly.
|
46
|
+
raise SyntaxError, "[JTask] Invalid value given for the get method."
|
31
47
|
end
|
32
|
-
else
|
33
|
-
raise NameError, "\n\nJTask Error => Invalid get method specified. Try using\n JTask.get(\"filename\", 1) instead.\n\n-"
|
34
48
|
end
|
35
|
-
|
36
|
-
#
|
37
|
-
output =
|
49
|
+
# Loop through each required record and
|
50
|
+
# push each one to the blank output array.
|
51
|
+
output = []
|
52
|
+
required_records.each do |id, record|
|
53
|
+
output.push({ "id" => id.to_i }.merge(record))
|
54
|
+
end
|
38
55
|
end
|
39
|
-
|
56
|
+
|
40
57
|
return output
|
41
58
|
end
|
42
59
|
end
|
data/lib/jtask/save.rb
CHANGED
@@ -12,7 +12,7 @@ module Save
|
|
12
12
|
end
|
13
13
|
# Validate haash supplied for parameters
|
14
14
|
unless parameters.is_a?(Hash)
|
15
|
-
raise SyntaxError, "
|
15
|
+
raise SyntaxError, "[JTask] Invalid value supplied to the parameters variable. Ensure your parameters are in the symbol hash form, eg - {name: \"Adam\", city: \"Melbourne\"}"
|
16
16
|
end
|
17
17
|
|
18
18
|
original_file = File.read(File.join(dir, filename))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jtask
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam McArthur
|
@@ -30,13 +30,10 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
-
- ".DS_Store"
|
34
33
|
- ".gitignore"
|
35
34
|
- changelist.txt
|
36
35
|
- jtask.gemspec
|
37
|
-
- lib/.DS_Store
|
38
36
|
- lib/jtask.rb
|
39
|
-
- lib/jtask/.DS_Store
|
40
37
|
- lib/jtask/chop.rb
|
41
38
|
- lib/jtask/destroy.rb
|
42
39
|
- lib/jtask/get.rb
|
@@ -55,6 +52,8 @@ post_install_message: |2-
|
|
55
52
|
|
56
53
|
Thanks for installing JTask Beta. Check out the full documentation and contribute at https://github.com/adammcarthur/jtask
|
57
54
|
|
55
|
+
In this release (v0.1.0 Beta): Fixed a major flaw in the JTask.get() output. Read more about this error here: https://github.com/adammcarthur/jtask/issues/1
|
56
|
+
|
58
57
|
- Adam (@adammcarth)
|
59
58
|
-
|
60
59
|
rdoc_options: []
|