crud-service 0.0.3 → 0.0.4

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTJkYTAyY2I2NDNjMGFmMGEwYTIwMDZlNDcxYTEzMTdmNTBmYjI0Nw==
4
+ YjI2NzcwMzlkODRmMGFmMzg3Mzc4MWQ3YjBkNWIxMjcyZGEyZDM4Mg==
5
5
  data.tar.gz: !binary |-
6
- NjU1MzQwMzU4NTNmOGNmYzEyMmZlNjdkODNlYTQ4MDk1MGQ3YmE0Mg==
6
+ YjI5YThmMDI1ODMxODU2NzlkNzU1NTg0ODk4YzhiNzk4YTUxNzg0Yg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MjIyMjBiYTJmYmI0MzBlZjEwYWM1OWVkMmI4ZmQyMzM3NzRmOTNlMzEyOGIx
10
- YTFmMGM4NTFlNTIwNzYzM2JlNDhjZjVmNzEwOTcxM2U2OTM1YWE5YWIxNDFj
11
- ZjFiNGNhZGM3ZThjMGExZGFlMzllZTE0ZTg2MWRkODY5ODhiOGM=
9
+ YjhlZjM4MTAyYzk5YmQ1NTlkMGRjNmFjYjkzYjQ4N2FkYmFmNWU4NGE1YjVl
10
+ Y2JhNzIwNGM5NGFkYjllM2JhNjlkM2Q2ZDg3YjNkYTZjMGEzZjk5ZThkNWUy
11
+ NjBjZjMyNGRiODRkNWFmZTZiNTIyODk2ODM2ZDUxOThkMzUzYzg=
12
12
  data.tar.gz: !binary |-
13
- OWU1NTE2Mjk5ZTNmMWVjODBjMWJkMjUzMDhkOTBhZTQ0NzI5MTA5MWIzNjI2
14
- OTMxMjQ1Mjg3ZWNiYmJiMWNhNGY0ZTU0ZmU5OGQ3YWNiNjY1YTNlZTc1N2Ux
15
- YzQ5MWNmNjdmNDQ1N2QxNGFlZGQ3NTkyZTE3NWI3NDg3M2U1M2E=
13
+ ZjM0N2JiYWYxZjAxZTVhODk3YzQ4M2UzZWRhZWIyY2ZmNDhmZjYzZTMwMzNm
14
+ MTFmN2I1OTZiNDQ0Mjg5OTRlY2Q5YWMzN2M0NzgwY2Q1YmM2ZGNkNDk2MjQ5
15
+ OGY2YTBjYWM4ODUyZDdiZWE1ZjY0ZDcyZTY4ZGI2OGM0N2U2YjU=
data/lib/crud-service.rb CHANGED
@@ -1,3 +1,10 @@
1
+ # The crud-service gem provides a set of classes to quickly produce a basic CRUD API, from
2
+ # a MySQL database with optional memcached caching.
3
+ #
4
+ # Author:: Tom Cully (mailto:tomhughcully@gmail.com)
5
+ # Copyright:: Copyright (c) Tom Cully
6
+ # License:: Apache 2
7
+
1
8
  base = File.expand_path('../', __FILE__)
2
9
 
3
10
  require "#{base}/generic_dal.rb"
data/lib/generic_api.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  module CrudService
2
+
3
+ # This class provides a static method, crud_api, to configure a sinatra class with the
4
+ # provided service, resource and primary key.
2
5
  class GenericApi
3
6
 
4
7
  def self.crud_api(sinatra, service_name, name, primary_key_name)
data/lib/generic_dal.rb CHANGED
@@ -2,11 +2,17 @@ require 'json'
2
2
  require 'mysql2'
3
3
 
4
4
  module CrudService
5
+
6
+ # This class creates an instance of a generic DAL (Data Access Layer) with cache
7
+ # capability from the provided mysql client, logger and optionally memcache client.
8
+ # Your should extend this class to provide configuration for your dal, please see
9
+ # the README file at http://github.com/tomcully/crud-service
5
10
  class GenericDal
6
11
 
7
12
  attr_accessor :mysql, :memcache, :log, :table_name, :fields, :relations, :primary_key
8
13
 
9
- def initialize(mysql, memcache, log)
14
+ # Create an instance.
15
+ def initialize(mysql, memcache = nil, log)
10
16
  @mysql = mysql
11
17
  @memcache = memcache
12
18
  @log = log
data/lib/generic_log.rb CHANGED
@@ -1,17 +1,23 @@
1
1
  module CrudService
2
+
3
+ # This class provides a Generic Logger.
2
4
  class GenericLog
5
+ # Log a debug message
3
6
  def debug(str)
4
7
  puts "DEBUG: #{str}"
5
8
  end
6
9
 
10
+ # Log an info message
7
11
  def info(str)
8
12
  puts "INFO: #{str}"
9
13
  end
10
14
 
15
+ # Log a warning message
11
16
  def warn(str)
12
17
  puts "WARN: #{str}"
13
18
  end
14
19
 
20
+ # Log an error message
15
21
  def error(str)
16
22
  puts "ERROR: #{str}"
17
23
  end
@@ -1,57 +1,62 @@
1
1
  module CrudService
2
- class GenericService
3
2
 
3
+ # This class provides a generic service instance for the provided DAL and logger.
4
+ class GenericService
4
5
  attr_accessor :dal, :log
5
6
 
7
+ # Instantiate a service with the specified DAL and logger.
6
8
  def initialize(dal, log)
7
9
  @dal = dal
8
10
  @log = log
9
11
  end
10
12
 
11
- # CRUD
12
-
13
- def insert(body)
14
- @dal.insert(body)
13
+ # Insert a record with the supplied data record
14
+ def insert(data)
15
+ @dal.insert(data)
15
16
  end
16
17
 
18
+ # Get all records matching the specified query
17
19
  def get_all_by_query(query)
18
20
  res = @dal.get_all_by_query(query)
19
21
  @dal.map_in_included_relations!(res,query)
20
22
  res
21
23
  end
22
24
 
25
+ # Get one records matching the specified query
23
26
  def get_one_by_query(query)
24
27
  res = get_all_by_query(query)
25
28
  return nil if res.length == 0
26
29
  res[0]
27
30
  end
28
31
 
29
- def update_by_primary_key(primary_key,body)
30
- @dal.update_by_primary_key(primary_key,body)
32
+ # Update one record matching the specified primary key with data
33
+ def update_by_primary_key(primary_key, data)
34
+ @dal.update_by_primary_key(primary_key,data)
31
35
  end
32
36
 
37
+ # Delete one record matching the specified primary key
33
38
  def delete_by_primary_key(primary_key)
34
39
  @dal.delete_by_primary_key(primary_key)
35
40
  end
36
41
 
37
- # Existence
38
-
42
+ # Return true if a record matching the specified primary key exists
39
43
  def exists_by_primary_key?(primary_key)
40
44
  @dal.exists_by_primary_key?(primary_key)
41
45
  end
42
46
 
43
- # Validation
44
-
45
- def valid_insert?(body)
46
- @dal.valid_insert?(body)
47
+ # Return true if the specified data is valid for insert
48
+ def valid_insert?(data)
49
+ @dal.valid_insert?(data)
47
50
  end
48
51
 
52
+ # Return true if the specified query is valid
49
53
  def valid_query?(query)
50
54
  @dal.valid_query?(query)
51
55
  end
52
56
 
53
- def valid_update?(body)
54
- @dal.valid_update?(body)
57
+ # Return true if the specified data is valid for update
58
+ def valid_update?(data)
59
+ @dal.valid_update?(data)
55
60
  end
56
61
  end
57
62
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crud-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Cully
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-25 00:00:00.000000000 Z
11
+ date: 2013-08-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A basic gem for automatic CRUD services using only Sinatra, MySQL and
14
14
  Memcache
@@ -22,7 +22,7 @@ files:
22
22
  - lib/generic_dal.rb
23
23
  - lib/generic_log.rb
24
24
  - lib/generic_service.rb
25
- homepage: http://rubygems.org/gems/crud-service
25
+ homepage: http://github.com/tomcully/crud-service
26
26
  licenses:
27
27
  - Apache2
28
28
  metadata: {}