jtask 0.0.2 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e4e1aed55bba786830b3fa70b9334dedc413096
4
- data.tar.gz: 7b1b5a4fb9da48ac9af6769c7b6221f39653a945
3
+ metadata.gz: 0851a01dafb0753c4883abf034310c496a3181a8
4
+ data.tar.gz: ae407131ec5fd73379f5ffe2deeb327b7578eab1
5
5
  SHA512:
6
- metadata.gz: b706543cf01b4c7ea2712d33a2e3db7120f75eeeaa64fc8049afd2bb2dc707ab0cb9127cb6e42e05cdc3402e38efdb099c2fcd1ae129bbc757f4fc53960a0f0c
7
- data.tar.gz: 21584581aea94107c1a1a3315d1e30905fd5f0c7f5fdb09467dc074dca4b4fef347cd85e74410b1f76b764cefd86c2d597eab24d4aee8e88c03c9bc525911ba6
6
+ metadata.gz: 9de71bd836ab66469769925591e7764ba9753f81d98c7a5e6ca822cb6dafb2ff1f77dbcc13680cdd3e79b894bda54d337a140b2b0ef80e0c8ce3abf43c632673
7
+ data.tar.gz: 02e2d26f4009028e2cca6ca74f126ee1eec2bd7599ea4a62aab14c8e58089aceafe7be3b45077221ae81996bb8e404e56191fb99544babe76362a7ad6651b992
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  tmp
3
3
  doc
4
4
  .DS_Store
5
+ *.sublime-workspace
@@ -1,4 +1,10 @@
1
- 0.0.2 [Beta] [Current Version]
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
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jtask'
3
- s.version = '0.0.2'
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
@@ -1,5 +1,5 @@
1
1
  ###########################################################################
2
- # ` JTask v0.0.1 Beta ` #
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
@@ -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\n - only a string can be used to specify the parameter.\n\n-"
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, "\n\nJTask Error => The id #{method} could not be found in the\n file \"#{dir + filename}\". The file has not been changed.\n\n-"
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, "/n/nJTask Error => Incorrect id method used. A single id (integer) can be specified,\n or the symbol \":all\" to remove the parameter from every object.\n\n-"
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.
@@ -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, "\n\nJTask Error => An id of #{id} does not exsist in the file specified at\n \"#{dir + filename}\". Nothing has been deleted.\n\n-"
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.
@@ -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
- if method
12
- # Determine if an id integer or {first: - last:} hash method has been supplied.
13
- if method.is_a?(Integer)
14
- # Check if 'method' (in this case the single id to retrieve) exists.
15
- if objects["#{method}"]
16
- output = {"id" => "#{method}"}.merge(objects["#{method}"])
17
- # Old objects.select { |k, v| k == "#{method}" }
18
- else
19
- # id supplied doesn't exist
20
- raise NameError, "\n\nJTask Error => The id #{method} could not be found in\n the file \"#{dir + filename}\".\n\n-"
21
- end
22
- elsif method.is_a?(Hash)
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
- # Load the FIRST n number of objects from the file
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
- # Load the LAST n number of objects from the file
28
- output = Hash[(objects.to_a).last(method[:last].to_i).reverse] # wow!
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
- raise NameError, "\n\nJTask Error => Invalid get method specified. Try using\n JTask.get(\"filename\", last: 10) instead.\n\n-"
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
- else
36
- # No retrieval method supplied, so output all the objects from the file :)
37
- output = objects
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
@@ -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, "\n\nJTask Error => Invalid value supplied to the parameters variable.\n Ensure your parameters are in a symbol hash form\n like - {name: \"Adam\", city: \"Melbourne\"}\n\n-"
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.2
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: []