smartclient 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.
data/lib/DSRequest.rb CHANGED
@@ -1,4 +1,11 @@
1
1
  require 'DataSource'
2
+ =begin
3
+ <summary>
4
+ reference to the RPCManager executing this request will be stored in DSRequest.
5
+ This has to be done because, while the request is being.executed, access will be required to various items such as
6
+ the DataSource object, etc - These items will all be provided by the RPCManager class.
7
+ </summary>
8
+ =end
2
9
  class DSRequest
3
10
  attr_accessor :dataSource, :operationType, :startRow, :endRow, :textMatchStyle, :data, :sortBy, :oldValues
4
11
 
@@ -26,7 +33,16 @@ class DSRequest
26
33
 
27
34
  @@obj = model
28
35
  end
29
-
36
+ =begin
37
+ <summary>
38
+ The execute() method itself only loads the DataSource object then calls the DataSource's execute method for
39
+ processing the request.
40
+ </summary>
41
+ <params>
42
+ @datasource: DataSource object from the RPCManager helper class
43
+ @@obj: model object that is mapped to the table
44
+ </params>
45
+ =end
30
46
  def execute
31
47
  ds = DataSource.new(@dataSource, @@obj)
32
48
  if ds.nil?
data/lib/DataSource.rb CHANGED
@@ -1,3 +1,9 @@
1
+ =begin
2
+ <summary>
3
+ This helper classes process the request after recieve from the DSRequest.
4
+ The CRUD methods(add, remove, update, fetch) were supported.
5
+ </summary>
6
+ =end
1
7
  class DataSource
2
8
  attr_accessor :data_source
3
9
  @data_source = nil
@@ -6,7 +12,9 @@ class DataSource
6
12
  #@data_source = self.get_data(path)
7
13
  @model = model
8
14
  end
9
-
15
+ =begin
16
+ <summary> get the DataSource contents from the path and parse to JSON format </summary>
17
+ =end
10
18
  def get_data(path)
11
19
  ds_content = File.read(path)
12
20
  #remove the isc tag and the end tag
@@ -16,7 +24,9 @@ class DataSource
16
24
  result = ds_content.gsub('/\r|\n|\t|>>|\/\//', '')
17
25
  return JSON.parse(result)
18
26
  end
19
-
27
+ =begin
28
+ <summary> get the field content by the filed name </summary>
29
+ =end
20
30
  def get_field(field_name)
21
31
  fields = @data_source['fields']
22
32
 
@@ -27,7 +37,9 @@ class DataSource
27
37
  end
28
38
  return nil
29
39
  end
30
-
40
+ =begin
41
+ <summary> process the request </summary>
42
+ =end
31
43
  def execute(request)
32
44
  operation_type = request.operationType
33
45
  case operation_type
@@ -43,9 +55,14 @@ class DataSource
43
55
  return @result
44
56
  end
45
57
 
46
- private
58
+ private
59
+ =begin
60
+ <summary> get the item list from the table </summary>
61
+ <note>Before this method is called, the filter method should define in the model of the projects.</note>
62
+ =end
47
63
  def fetch(request)
48
- unless request.data.empty?
64
+ unless request.data.empty?
65
+ # get the filter from the model
49
66
  @obj_items = @model.filter(request)
50
67
  else
51
68
  # get all supplyitems from the database
@@ -54,7 +71,9 @@ private
54
71
 
55
72
  objs_count = @obj_items.count
56
73
  # get the count of the obj_items
57
- endRow = (objs_count > 0)?objs_count - 1 : objs_count
74
+ endRow = (objs_count > 0)?objs_count - 1 : objs_count
75
+
76
+ # make the Response result object
58
77
  response = DSResponse.new
59
78
  response.data = @obj_items
60
79
  response.startRow = 0
@@ -65,7 +84,9 @@ private
65
84
  @result = { :response => response }
66
85
  return @result
67
86
  end
68
-
87
+ =begin
88
+ <summary>Add new item</summary>
89
+ =end
69
90
  def add(request)
70
91
  new_data = request.data
71
92
  new_supplyitem = @model.create(new_data)
@@ -75,24 +96,30 @@ private
75
96
  @result = { :response => response }
76
97
  return @result
77
98
  end
78
-
99
+ =begin
100
+ <summary>Remove the selected item</summary>
101
+ =end
79
102
  def remove(request)
80
103
  data = request.data
81
104
  item_id = data['itemID']
105
+ # remove the item
82
106
  @model.destroy(item_id)
83
107
  response = DSResponse.new
84
108
  response.data = data
85
109
  response.status = 0
86
110
  @result = { :response => response }
87
- return @result
88
-
111
+ return @result
89
112
  end
90
-
113
+ =begin
114
+ <summary>Update the items</summary>
115
+ =end
91
116
  def update(request)
117
+ # get the old data from the request object
92
118
  old_data = request.oldValues
119
+ # get the date from the request object
93
120
  update_data = request.data
94
121
  item_id = update_data['itemID']
95
-
122
+ # merge to hash objects
96
123
  merged_data = old_data.merge!(update_data)
97
124
  merged_data.delete('itemID')
98
125
 
data/lib/RPCManager.rb CHANGED
@@ -1,9 +1,27 @@
1
+ =begin
2
+ <summary>
3
+ Any action of the user with the DataSource will only call the RPCManager and will delegate all responsibility to it.
4
+ The RPCManager will parse the payload and setup the DSRequest request and will call for the request's execute() method
5
+ which will return the DSResponse object. The RPCManager will then convert this DSResponse into a suitable response
6
+ and return it to the front-end.
7
+ </summary>
8
+ =end
1
9
  require 'DSRequest'
2
10
  require 'DSResponse'
3
11
 
4
12
  class RPCManager
5
13
  @request = nil
6
14
  @model = nil
15
+ =begin
16
+ <summary>
17
+ Process the request with the model.
18
+ </summary>
19
+
20
+ <params>
21
+ request: posted request parameters
22
+ model: the object that is mapped to the table
23
+ </params>
24
+ =end
7
25
  def initialize(request=nil, model=nil)
8
26
  @request = request
9
27
  @model = model
@@ -17,12 +35,11 @@ class RPCManager
17
35
  <returns>the created json object</returns>
18
36
  =end
19
37
  def processRequest
20
- # retrieve the requests with data
21
-
38
+ # retrieve the requests with data
22
39
  req = DSRequest.new(@request, @model)
23
40
  # set the response variable
24
41
  res = req.execute
25
- File.open('kris.txt', 'w') { |file| file.write(res) }
42
+
26
43
  # safeguard, if was null, create an empty response with failed status
27
44
  if res.nil?
28
45
  res = DSResponse.new
data/lib/filter.rb ADDED
@@ -0,0 +1,32 @@
1
+ def self.filter(request)
2
+ param = Array.new
3
+ condition = ''
4
+ request.data.each do |key, value|
5
+ condition += "#{key} LIKE ? AND "
6
+ param << "%" + value + "%"
7
+ end
8
+ q = condition[0, condition.rindex('AND ')]
9
+ temp = Array.new
10
+ temp << q
11
+ temp.concat(param)
12
+ where(temp)
13
+ order = ''
14
+ # sort by
15
+ unless request.sortBy.nil?
16
+ request.sortBy.each do |idx|
17
+ if idx.index('-') === nil
18
+ order = idx.to_s + " ASC"
19
+ else
20
+ order = idx.to_s + " DESC"
21
+ end
22
+ end
23
+ end
24
+ # return the result
25
+
26
+
27
+ if order == nil
28
+ where(temp)
29
+ else
30
+ where(temp).order(order)
31
+ end
32
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,10 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2013-05-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: This gem will work for the smartclient. The RPCManager Helper was added!
14
+ description: ! "This gem will work for the smartclient. \n\t After
15
+ you install this gem, you should define the filter method in the models.\n\t To
16
+ do this you need to copy the filter method of the filter.rb of the gem/smartclient
17
+ directory to the model class."
15
18
  email: kris.jin81@gmail.com
16
19
  executables: []
17
20
  extensions: []
@@ -21,7 +24,8 @@ files:
21
24
  - lib/DSRequest.rb
22
25
  - lib/DSResponse.rb
23
26
  - lib/DataSource.rb
24
- homepage: https://isomorphic.atlassian.net
27
+ - lib/filter.rb
28
+ homepage: http://smartclient.com/
25
29
  licenses: []
26
30
  post_install_message:
27
31
  rdoc_options: []