ns_service_pack 0.0.7 → 0.0.8
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/History +6 -0
- data/README +24 -4
- data/lib/ns_service_pack/application_controller_module.rb +23 -25
- data/lib/ns_service_pack/version.rb +1 -1
- metadata +3 -3
data/History
CHANGED
data/README
CHANGED
@@ -1,5 +1,23 @@
|
|
1
|
-
##==
|
1
|
+
##==README
|
2
|
+
|
3
|
+
Service层基础共享代码模式抽取
|
4
|
+
|
5
|
+
功能列表:
|
6
|
+
* 支持自定义json格式的资源crud操作
|
7
|
+
* 提供全局字典常量/转换管理
|
8
|
+
* 提供数据库层-业务层字段自动转换
|
2
9
|
|
10
|
+
#==TODO TASK LIST
|
11
|
+
* 更好用的安装使用接口,自动完成,可配置
|
12
|
+
* rake 任务的引入, 产品模式将数据文件预编译成一个数据文件
|
13
|
+
* fieldmapping 和 常量管理的分离
|
14
|
+
让使用者可以决定是否使用mapping,目前可以通过注释initializer中片段完成
|
15
|
+
* 用模板的方法生成initializer,以便插入一些动态数据
|
16
|
+
* 提供scaffold结构化方法,辅助开发
|
17
|
+
* application_controller_module的引入还是有问题!!!
|
18
|
+
* index默认查询条件加入,传入条件的merge(目前已提供传入条件的精确搜索)
|
19
|
+
|
20
|
+
##==NS Service Pack使用指南
|
3
21
|
*1 在rails3项目Gemfile中引入
|
4
22
|
gem 'ns_service_pack'
|
5
23
|
|
@@ -10,10 +28,11 @@
|
|
10
28
|
config/code_hashes/**/*.yml中数据会作为CodeHash加载
|
11
29
|
可在控制台下用以下命令辅助生成:
|
12
30
|
<ModelName>.dump_mapping
|
13
|
-
生成buz-db field_mapping, 可配置, --><app>/config/code_hashes
|
31
|
+
生成buz-db field_mapping, 可配置, --><app>/config/code_hashes/fields/*.yml
|
32
|
+
|
33
|
+
<ModelName>.dump_new
|
34
|
+
客户new该资源时的结构,--> <app>/data/*.yml
|
14
35
|
|
15
|
-
<ModelName>.dump_init_hash
|
16
|
-
为远端客户端生成初始项hash结构,--> <app>/data/*.yml
|
17
36
|
常量的使用:
|
18
37
|
GlobalConst.ns_statuses[key_or_value]
|
19
38
|
|
@@ -25,6 +44,7 @@ class AddressesController < ApplicationController
|
|
25
44
|
#引用的模型类,是ActiveRecord::Base子类
|
26
45
|
end
|
27
46
|
|
47
|
+
#已提供默认条件查询
|
28
48
|
def index
|
29
49
|
#定义@conds实例变量,组织查询的条件,默认支持分页
|
30
50
|
end
|
@@ -1,16 +1,27 @@
|
|
1
1
|
#coding: utf-8
|
2
2
|
module ApplicationControllerModule
|
3
3
|
def index
|
4
|
-
|
5
|
-
|
4
|
+
result = paginate(params) do |start, page_size|
|
5
|
+
get_page_data(start, page_size, params)
|
6
|
+
end
|
7
|
+
render :json=>ResultPacker.data(result.as_json)
|
8
|
+
end
|
9
|
+
|
10
|
+
#return [total_count, page_data]
|
11
|
+
#可在子类中覆盖定制
|
12
|
+
def get_page_data(start = 0, size = 10, params = {})
|
13
|
+
logger.debug "===================in module..."
|
14
|
+
where_conds = if @conds.present?
|
6
15
|
@conds
|
7
16
|
else
|
8
17
|
query_conditionize(params, @conds)
|
9
18
|
end
|
10
19
|
logger.debug "====>conds: #{where_conds.inspect}"
|
11
|
-
|
12
|
-
|
13
|
-
|
20
|
+
conds = {:conditions=>where_conds}
|
21
|
+
total_count = model_class.count(conds)
|
22
|
+
page_params = conds.merge!(:offset=>start, :limit=>page_size, :order=>params[:order])
|
23
|
+
model_class.all(page_params)
|
24
|
+
[total_count, page_data]
|
14
25
|
end
|
15
26
|
|
16
27
|
def query_conditionize(params = {}, conds = {})
|
@@ -20,31 +31,19 @@ module ApplicationControllerModule
|
|
20
31
|
end
|
21
32
|
|
22
33
|
#分页方法
|
23
|
-
def paginate(
|
24
|
-
|
25
|
-
|
26
|
-
#计算page参数
|
27
|
-
page_num = params[:current_page].to_i
|
28
|
-
page_num = page_num < 1 ? 1 : page_num
|
34
|
+
def paginate(params = {})
|
35
|
+
current_page = params[:current_page].to_i
|
36
|
+
current_page = current_page < 1 ? 1 : current_page
|
29
37
|
page_size = params[:page_size].to_i
|
30
38
|
page_size = page_size <= 0 ? 10 : page_size
|
31
39
|
page_size = page_size > 250 ? 250 : page_size
|
32
|
-
offset = (
|
33
|
-
|
34
|
-
|
35
|
-
conds = {:conditions=>where_conds}
|
36
|
-
total_count = base_class.count(conds)
|
37
|
-
conds.merge!(:limit=>page_size,
|
38
|
-
:offset=>offset,
|
39
|
-
:order=>params[:order])
|
40
|
-
new_conds = conds #yield conds
|
41
|
-
#添加select子句 TODO
|
42
|
-
page_data = base_class.all(new_conds)
|
43
|
-
|
40
|
+
offset = (current_page-1)*page_size
|
41
|
+
#返回总数和当前页数据 起始位置, 数量
|
42
|
+
total_count, page_data = yield(offset, page_size)
|
44
43
|
{
|
45
44
|
:total_size=>total_count,
|
46
45
|
:page_size=>page_size,
|
47
|
-
:current_page=>
|
46
|
+
:current_page=>current_page,
|
48
47
|
:page_from=>offset + 1,
|
49
48
|
:page_to=>offset + page_data.size,
|
50
49
|
:page_items=>page_data
|
@@ -85,7 +84,6 @@ module ApplicationControllerModule
|
|
85
84
|
#ABORTED NOW, keep here
|
86
85
|
def query_fields
|
87
86
|
data = model_class.buz_hashize
|
88
|
-
#field_maps.keys.inject({}){|result, k| result[k]=nil; result}
|
89
87
|
render :json=>ResultPacker.data(:fields=>data)
|
90
88
|
end
|
91
89
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ns_service_pack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -15,7 +15,7 @@ date: 2011-11-17 00:00:00.000000000Z
|
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
18
|
-
requirement: &
|
18
|
+
requirement: &78489940 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ! '>='
|
@@ -23,7 +23,7 @@ dependencies:
|
|
23
23
|
version: 3.1.0
|
24
24
|
type: :development
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *78489940
|
27
27
|
description: Service package for our service lier
|
28
28
|
email: cao7113@gmail.com
|
29
29
|
executables: []
|