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 CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'apimaster'
3
- s.version = '0.0.4'
3
+ s.version = '0.0.5'
4
4
  s.date = '2012-07-12'
5
5
  s.summary = "ApiMaster!"
6
6
  s.description = "A simple restful api framework."
@@ -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
- m.template "config/boot.rb.erb", "config/boot.rb"
25
- m.template "config/patches.rb.erb", "config/patches.rb"
26
- m.template "config/initializer.rb.erb", "config/initializer.rb"
27
- m.template "config/application.rb.erb", "config/application.rb"
28
- m.template "config/settings/mongoid.yml.erb", "config/settings/mongoid.yml"
29
- m.template "config/settings/app.yml.erb", "config/settings/app.yml"
30
- m.template "config/settings/oauth.yml.erb", "config/settings/oauth.yml"
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
- # Create stubs
33
- m.template "config.ru.erb", "config.ru"
34
- m.template "gitignore", ".gitignore"
35
- m.template "lib/module.rb.erb", "lib/#{app_name}.rb"
36
- m.template "app/tasks/test.rake.erb", "app/tasks/test.rake"
37
- m.template "app/tasks/stat.rake.erb", "app/tasks/stat.rake"
38
- m.template "app/controllers/index_controller.rb.erb", "app/controllers/index_controller.rb"
39
- m.template "app/controllers/befores_controller.rb.erb", "app/controllers/befores_controller.rb"
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
- # Test stubs
42
- m.template "test/test_helper.rb.erb", "test/test_helper.rb"
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
@@ -5,6 +5,7 @@ module Apimaster::Generators
5
5
 
6
6
  def initialize(runtime_args, runtime_options = {})
7
7
  super
8
+ raise 'Unknown app directory.' unless File.exists?('./Gemfile')
8
9
  @app_name = File.basename(File.expand_path('./'))
9
10
  @module_name = camelize(app_name)
10
11
  @name = args[0]
@@ -5,6 +5,7 @@ module Apimaster::Generators
5
5
 
6
6
  def initialize(runtime_args, runtime_options = {})
7
7
  super
8
+ raise 'Unknown app directory.' unless File.exists?('./Gemfile')
8
9
  @app_name = File.basename(File.expand_path('./'))
9
10
  @module_name = camelize(app_name)
10
11
  @name = args[0]
@@ -3,17 +3,23 @@
3
3
  # Copyright (C) 2011-2012 AdMaster, Inc.
4
4
 
5
5
  module <%= module_name %>
6
- class <%= camelize name %> < Apimaster::Mapper
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], optional: [:patch]
13
- attr_options :content, accessor: [:get], required: [:post], optional: [:patch]
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
- use BeforesController
12
- use IndexController
13
- # use YourCountroller
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
@@ -3,8 +3,7 @@
3
3
  # Copyright (C) 2011-2012 AdMaster, Inc.
4
4
 
5
5
  module Apimaster
6
- class Mapper
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
- record[field] = self.send(field)
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
- class << self
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
 
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.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: