apimaster 0.0.4 → 0.0.5
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/apimaster.gemspec +1 -1
- data/lib/apimaster/generators/app_generator.rb +22 -20
- data/lib/apimaster/generators/controller_generator.rb +1 -0
- data/lib/apimaster/generators/model_generator.rb +1 -0
- data/lib/apimaster/generators/templates/app/models/example.rb.erb +9 -3
- data/lib/apimaster/generators/templates/config/application.rb.erb +5 -3
- data/lib/apimaster/mapper.rb +9 -5
- metadata +1 -1
data/apimaster.gemspec
CHANGED
@@ -17,32 +17,34 @@ module Apimaster::Generators
|
|
17
17
|
record do |m|
|
18
18
|
# Ensure appropriate folder(s) exists
|
19
19
|
m.directory ''
|
20
|
-
BASEDIRS.each { |path| m.directory path }
|
21
|
-
m.directory "lib/#{app_name}"
|
20
|
+
BASEDIRS.each { |path| m.directory(app_name + '/' + path) }
|
21
|
+
m.directory "#{app_name}/lib/#{app_name}"
|
22
22
|
|
23
23
|
# config
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
templates = {
|
25
|
+
"config/boot.rb.erb" => "config/boot.rb",
|
26
|
+
"config/patches.rb.erb" => "config/patches.rb",
|
27
|
+
"config/initializer.rb.erb" => "config/initializer.rb",
|
28
|
+
"config/application.rb.erb" => "config/application.rb",
|
29
|
+
"config/settings/mongoid.yml.erb" => "config/settings/mongoid.yml",
|
30
|
+
"config/settings/app.yml.erb" => "config/settings/app.yml",
|
31
|
+
"config/settings/oauth.yml.erb" => "config/settings/oauth.yml",
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
# Create stubs
|
34
|
+
"config.ru.erb" => "config.ru",
|
35
|
+
"gitignore" => ".gitignore",
|
36
|
+
"lib/module.rb.erb" => "lib/#{app_name}.rb",
|
37
|
+
"app/tasks/test.rake.erb" => "app/tasks/test.rake",
|
38
|
+
"app/tasks/stat.rake.erb" => "app/tasks/stat.rake",
|
39
|
+
"app/controllers/index_controller.rb.erb" => "app/controllers/index_controller.rb",
|
40
|
+
"app/controllers/befores_controller.rb.erb" => "app/controllers/befores_controller.rb",
|
40
41
|
|
41
|
-
|
42
|
-
|
42
|
+
# Test stubs
|
43
|
+
"test/test_helper.rb.erb" => "test/test_helper.rb"
|
44
|
+
}.each { |k, v| m.template(k, app_name + '/' + v) }
|
43
45
|
|
44
46
|
%w(LICENSE Rakefile README.md Gemfile TODO test.watchr).each do |file|
|
45
|
-
m.template file, file
|
47
|
+
m.template file, app_name + '/' + file
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
@@ -3,17 +3,23 @@
|
|
3
3
|
# Copyright (C) 2011-2012 AdMaster, Inc.
|
4
4
|
|
5
5
|
module <%= module_name %>
|
6
|
-
class <%= camelize name %>
|
6
|
+
class <%= camelize name %>
|
7
|
+
include Apimaster::Mapper
|
7
8
|
include Mongoid::Document
|
8
9
|
|
9
10
|
field :title, type: String
|
10
11
|
field :content, type: String
|
11
12
|
|
12
|
-
attr_options :title, accessor: [:get, :list], required: [:post],
|
13
|
-
|
13
|
+
attr_options :title, accessor: [:get, :list], required: [:post],
|
14
|
+
optional: [:patch]
|
15
|
+
attr_options :content, accessor: [:get], required: [:post],
|
16
|
+
optional: [:patch]
|
14
17
|
|
15
18
|
validates :title, length: { minimum: 2, maximum: 30 }
|
16
19
|
|
20
|
+
# Embedded 1-1
|
21
|
+
# embeds_one :label, class_name: "<%= module_name %>::Label"
|
22
|
+
|
17
23
|
class << self
|
18
24
|
|
19
25
|
def get id
|
@@ -8,9 +8,11 @@ module <%= module_name %>
|
|
8
8
|
use Apimaster::Application
|
9
9
|
|
10
10
|
# controllers
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
<%= module_name %>.constants.each do |k|
|
12
|
+
if k =~ /Controller$/
|
13
|
+
use <%= module_name %>.const_get(k)
|
14
|
+
end
|
15
|
+
end
|
14
16
|
|
15
17
|
end
|
16
18
|
end
|
data/lib/apimaster/mapper.rb
CHANGED
@@ -3,8 +3,7 @@
|
|
3
3
|
# Copyright (C) 2011-2012 AdMaster, Inc.
|
4
4
|
|
5
5
|
module Apimaster
|
6
|
-
|
7
|
-
#include ::Mongoid::Document
|
6
|
+
module Mapper
|
8
7
|
|
9
8
|
def post hash
|
10
9
|
save_with_hash hash, :post
|
@@ -23,7 +22,7 @@ module Apimaster
|
|
23
22
|
if valid?
|
24
23
|
save
|
25
24
|
else
|
26
|
-
raise InvalidFieldError.new(class_name, errors.keys.first)
|
25
|
+
raise Apimaster::InvalidFieldError.new(class_name, errors.keys.first)
|
27
26
|
end
|
28
27
|
self
|
29
28
|
end
|
@@ -61,7 +60,8 @@ module Apimaster
|
|
61
60
|
fields = self.class.find_attrs_in_options(:accessor, accessor)
|
62
61
|
fields.each do |field|
|
63
62
|
if self.respond_to?(field)
|
64
|
-
|
63
|
+
val = self.send(field)
|
64
|
+
record[field] = val.respond_to?(:to_hash) ? val.to_hash(accessor) : val
|
65
65
|
else
|
66
66
|
raise "Dataset #{self.class} has no method with the name of #{field}"
|
67
67
|
end
|
@@ -73,7 +73,11 @@ module Apimaster
|
|
73
73
|
@class_name ||= self.class.to_s.split("::").last
|
74
74
|
end
|
75
75
|
|
76
|
-
|
76
|
+
def self.included(base)
|
77
|
+
base.extend ClassMethods
|
78
|
+
end
|
79
|
+
|
80
|
+
module ClassMethods
|
77
81
|
|
78
82
|
OPTION_TYPES = [:accessor, :required, :optional]
|
79
83
|
|