apimaster 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'apimaster'
3
- s.version = '0.1.2'
4
- s.date = '2013-03-21'
5
- s.summary = "ApiMaster!"
3
+ s.version = '0.1.3'
4
+ s.date = '2013-04-16'
5
+ s.summary = "ApiMaster"
6
6
  s.description = "A simple restful api framework."
7
7
  s.authors = ["Sun", "Zhang", "Li"]
8
8
  s.email = 'sunxiqiu@admaster.com.cn'
@@ -6,8 +6,8 @@ require "rubygems"
6
6
  require "bundler"
7
7
  require "cgi"
8
8
 
9
- require "./config/patches"
10
9
  require "./config/initializer"
10
+ require "./config/patches"
11
11
  require "./lib/<%= app_name %>"
12
12
 
13
13
  Dir.glob "./app/{models,helpers,controllers}/**/*.rb" do |f|
@@ -55,6 +55,7 @@ module Apimaster
55
55
  self.send name, val
56
56
  end
57
57
 
58
+ # to be deleted
58
59
  def to_hash accessor = :all
59
60
  record = {}
60
61
  fields = self.class.find_attrs_in_options(:accessor, accessor)
@@ -69,6 +70,20 @@ module Apimaster
69
70
  record
70
71
  end
71
72
 
73
+ def to_api_hash accessor = :all
74
+ record = {}
75
+ fields = self.class.find_attrs_in_options(:accessor, accessor)
76
+ fields.each do |field|
77
+ if self.respond_to?(field)
78
+ val = self.send(field)
79
+ record[field] = val.respond_to?(:to_api_hash) ? val.to_api_hash(accessor) : val
80
+ else
81
+ raise "Dataset #{self.class} has no method with the name of #{field}"
82
+ end
83
+ end
84
+ record
85
+ end
86
+
72
87
  def class_name
73
88
  @class_name ||= self.class.to_s.split("::").last
74
89
  end
@@ -109,6 +124,14 @@ module Apimaster
109
124
  result
110
125
  end
111
126
 
127
+ def to_api_hashes accessor = :all
128
+ result = []
129
+ self.each do |val|
130
+ result << val.to_api_hash(accessor)
131
+ end
132
+ result
133
+ end
134
+
112
135
  end
113
136
  end
114
137
  end
@@ -6,7 +6,8 @@ module Apimaster::Mocks
6
6
  class User
7
7
 
8
8
  def self.auth access_token
9
- Apimaster::Models::User.new id: 1, email: "hello@admaster.com.cn", username: "hello"
9
+ Apimaster::Models::User.new id: 1, email: "hello@admaster.com.cn",
10
+ username: "hello", uuid: "1d936f8e-f7f3-11e1-975a-782bcb4b65ed"
10
11
  end
11
12
 
12
13
  end
@@ -10,6 +10,7 @@ module Apimaster::Models
10
10
  attr_accessor :id
11
11
  attr_accessor :email
12
12
  attr_accessor :username
13
+ attr_accessor :uuid
13
14
 
14
15
  def initialize hash
15
16
  hash.each do |key, val|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apimaster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-03-21 00:00:00.000000000 Z
14
+ date: 2013-04-16 00:00:00.000000000 Z
15
15
  dependencies: []
16
16
  description: A simple restful api framework.
17
17
  email: sunxiqiu@admaster.com.cn
@@ -96,6 +96,6 @@ rubyforge_project:
96
96
  rubygems_version: 1.8.25
97
97
  signing_key:
98
98
  specification_version: 3
99
- summary: ApiMaster!
99
+ summary: ApiMaster
100
100
  test_files: []
101
101
  has_rdoc: