restpack_service 0.0.77 → 0.0.78

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce3958587090fb919dc8b56ab51175c8a7b22bfc
4
- data.tar.gz: 557e3da71cb2f66d78caeb2f04c1389082f4c324
3
+ metadata.gz: 530391dd80fa2f394ce52ccefa57d4aadf07761c
4
+ data.tar.gz: 9f5aa239b6a2ce575fcf282f4aea19557a9bd55e
5
5
  SHA512:
6
- metadata.gz: 715172d24177e047787770f3c1802066826d54f8f8000427960e30e0b3e3fb27261681876a82f09118ae959be8064437329921a845175c0685ba4a6780b77169
7
- data.tar.gz: b75fc1fd85fbaea84cad4b05279ff2963e91377298390e2d9f2049baec4ca862b94e67ba1c1677b90f7643b42b0abfffa3d0d2841385648c144fd0c2a0f662d4
6
+ metadata.gz: d6877c4ec151c1ceb825f41d98401d9994caf10d6ead6c73d2d49f5e8f713eae0b391efc58687b2b07d07377db7dadcaff22355926b46d68f9b255b556d8037a
7
+ data.tar.gz: 68ff5b6cdf796344872c16088767a2d621f52998c00c876dc6d233978c5cb38eb43720c2998f84753930acedf8cd0f942cf56d4c9465ef32d7199d72144e289d
@@ -57,16 +57,15 @@ module RestPack::Service
57
57
  end
58
58
 
59
59
  def Serializer
60
- self.class.const_get(:Serializer)
60
+ self.class.serializer_class
61
61
  end
62
62
 
63
63
  def Model
64
- self.class.const_get(:Model)
64
+ self.class.model_class
65
65
  end
66
66
 
67
67
  def self.inherited(command)
68
68
  namespaces = command.to_s.split('::') # eg. GroupService::Commands::Group::Create
69
-
70
69
  add_module_aliases(command, namespaces)
71
70
  end
72
71
 
@@ -77,8 +76,17 @@ module RestPack::Service
77
76
  Modularize.create("#{namespaces[0]}::Serializers")
78
77
  Modularize.create("#{namespaces[0]}::#{namespaces[2]}")
79
78
 
80
- command.const_set(:Model, "#{namespaces[0]}::Models::#{namespaces[2]}".safe_constantize)
81
- command.const_set(:Serializer, "#{namespaces[0]}::Serializers::#{namespaces[2]}".safe_constantize)
79
+ model_class = "#{namespaces[0]}::Models::#{namespaces[2]}".safe_constantize
80
+ if model_class
81
+ command.const_set(:Model, model_class)
82
+ command.send(:define_singleton_method, "model_class") { model_class }
83
+ end
84
+
85
+ serializer_class = "#{namespaces[0]}::Serializers::#{namespaces[2]}".safe_constantize
86
+ if serializer_class
87
+ command.const_set(:Serializer, serializer_class)
88
+ command.send(:define_singleton_method, "serializer_class") { serializer_class }
89
+ end
82
90
 
83
91
  command.const_set(:Commands, "#{namespaces[0]}::Commands".safe_constantize)
84
92
  command.const_set(:Models, "#{namespaces[0]}::Models".safe_constantize)
@@ -1,9 +1,15 @@
1
- # module RestPack::Service
2
- # module Commands
3
- # class Get < RestPack::Service::Command
4
- # def execute
5
- # get
6
- # end
7
- # end
8
- # end
9
- # end
1
+ module RestPack::Service
2
+ module Commands
3
+ class Get < RestPack::Service::Command
4
+ def execute
5
+ result = self.class.serializer_class.resource(inputs)
6
+
7
+ if result[self.class.serializer_class.key].empty?
8
+ status :not_found
9
+ else
10
+ result
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -8,7 +8,7 @@ module RestPack::Service
8
8
  end
9
9
 
10
10
  def execute
11
- Serializer.resource(inputs)
11
+ self.class.serializer_class.resource(inputs)
12
12
  end
13
13
  end
14
14
  end
@@ -1,5 +1,5 @@
1
1
  module RestPack
2
2
  module Service
3
- VERSION = "0.0.77"
3
+ VERSION = "0.0.78"
4
4
  end
5
5
  end
data/spec/command_spec.rb CHANGED
@@ -6,11 +6,13 @@ describe RestPack::Service::Command do
6
6
  Command = TextService::Commands::Text::Reverse
7
7
  command = Command.new
8
8
 
9
- expect(Command::Model).to eq(TextService::Models::Text)
10
9
  expect(command.Model).to eq(TextService::Models::Text)
10
+ expect(Command::Model).to eq(TextService::Models::Text)
11
+ expect(Command.model_class).to eq(TextService::Models::Text)
11
12
 
12
- expect(Command::Serializer).to eq(TextService::Serializers::Text)
13
13
  expect(command.Serializer).to eq(TextService::Serializers::Text)
14
+ expect(Command::Serializer).to eq(TextService::Serializers::Text)
15
+ expect(Command.serializer_class).to eq(TextService::Serializers::Text)
14
16
 
15
17
  expect(Command::Commands).to eq(TextService::Commands)
16
18
  expect(Command::Models).to eq(TextService::Models)
@@ -9,9 +9,14 @@ module TextService
9
9
  end
10
10
  end
11
11
 
12
+ module Base
13
+ class Command < RestPack::Service::Command
14
+ end
15
+ end
16
+
12
17
  module Commands
13
18
  module Text
14
- class Reverse < RestPack::Service::Command
19
+ class Reverse < Base::Command
15
20
  required do
16
21
  string :text
17
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restpack_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.77
4
+ version: 0.0.78
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Joyce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-16 00:00:00.000000000 Z
11
+ date: 2014-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mutations