restpack_service 0.0.62 → 0.0.63

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72772440e033dee063fcad2ad3b89764784bb042
4
- data.tar.gz: b1172e66fea38fc0dab9917d205bf66809796801
3
+ metadata.gz: c0938d27334d3f63cd499c39dbd26c64c6b09858
4
+ data.tar.gz: 08fd476e36b612893f7bcc83d753909b59a193a9
5
5
  SHA512:
6
- metadata.gz: f81c735a4e9664168960a636afedb39ca8b408f3b2187c261f5fca558525056ef56305168666b44d420b8017d7b1bbe120048d767bfd7ece15d98295109bc06d
7
- data.tar.gz: 16b91036a19c6a6b3d8540adfab477ad6f27f954cd961914a41c8c36846de1dcdd17ff9e2cb36cffde44adb903a73a42d76d9f0aea7f8c76f43bc8308085b2f8
6
+ metadata.gz: 17105580553ccfd876d4b4e474b8eac95774eb639c9619a290f3fe1a1f8007baf07353637851723e805dff5b6af9d74cffa560a1a5188b70c344a27313f744e9
7
+ data.tar.gz: c3e3bd881b02a32cc4eb20650135f8916642a031078eb76026a91caefe8e957eaf637f4b4c556753b7ed26478dcb84831d2b2ad6f22de3df4be1412e64ffae22
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
1
  --color
2
- --format progress
2
+ --format documentation
@@ -1,3 +1,5 @@
1
+ require 'modularize'
2
+
1
3
  module RestPack::Service
2
4
  class Command < Mutations::Command
3
5
  attr_accessor :response
@@ -89,8 +91,52 @@ module RestPack::Service
89
91
  serializer_klass.as_json(model)
90
92
  end
91
93
 
94
+ def self.inherited(command)
95
+ namespaces = command.to_s.split('::') # eg. GroupService::Commands::Group::Create
96
+
97
+ add_module_aliases(command, namespaces)
98
+ add_command_methods(command, namespaces)
99
+ end
100
+
92
101
  private
93
102
 
103
+ def self.add_module_aliases(command, namespaces)
104
+ Modularize.create("#{namespaces[0]}::Models")
105
+ Modularize.create("#{namespaces[0]}::Serializers")
106
+ Modularize.create("#{namespaces[0]}::#{namespaces[2]}")
107
+
108
+ command.const_set(:Model, "#{namespaces[0]}::Models::#{namespaces[2]}".safe_constantize)
109
+ command.const_set(:Serializer, "#{namespaces[0]}::Serializers::#{namespaces[2]}".safe_constantize)
110
+
111
+ command.const_set(:Commands, "#{namespaces[0]}::Commands".safe_constantize)
112
+ command.const_set(:Models, "#{namespaces[0]}::Models".safe_constantize)
113
+ end
114
+
115
+ def self.add_command_methods(command, namespaces)
116
+ method_name = command.name.demodulize.downcase
117
+ container = method_container_module(command, namespaces)
118
+
119
+ container.send(
120
+ :define_singleton_method,
121
+ method_name.to_sym,
122
+ Proc.new { |*args| command.run(*args) }
123
+ )
124
+
125
+ container.send(
126
+ :define_singleton_method,
127
+ "#{method_name}!".to_sym,
128
+ Proc.new { |*args| command.run!(*args) }
129
+ )
130
+ end
131
+
132
+ def self.method_container_module(command, namespaces)
133
+ if namespaces[1] == 'Commands'
134
+ "#{namespaces[0]}::#{namespaces[2]}".safe_constantize #GroupService::Group
135
+ else
136
+ namespaces.take(namespaces.length - 1).join('::').safe_constantize #Commands::Group
137
+ end
138
+ end
139
+
94
140
  def create_models!(array)
95
141
  model_klass.create!(array)
96
142
  end
@@ -105,7 +151,7 @@ module RestPack::Service
105
151
 
106
152
  def service_namespace
107
153
  identifiers = service_identifiers
108
- namespace = "#{identifiers[:service].capitalize}::#{identifiers[:resource].capitalize}"
154
+ namespace = "#{identifiers[:service]}::#{identifiers[:resource].capitalize}"
109
155
  end
110
156
 
111
157
  def service_identifiers
@@ -113,7 +159,7 @@ module RestPack::Service
113
159
  namespaces = self.class.ancestors.first.to_s.split('::')
114
160
  resource = namespaces[2].downcase
115
161
  return {
116
- service: namespaces[1].downcase.to_sym,
162
+ service: namespaces[1].to_sym,
117
163
  resource: resource.to_sym,
118
164
  resources: resource.pluralize.to_sym
119
165
  }
@@ -1,5 +1,5 @@
1
1
  module RestPack
2
2
  module Service
3
- VERSION = "0.0.62"
3
+ VERSION = "0.0.63"
4
4
  end
5
5
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe RestPack::Service::Command do
4
+ context 'with a commands in a namespace like TextService::Commands::Text::Reverse' do
5
+ it 'defines sugar methods' do
6
+ TextService::Text.respond_to?(:reverse).should == true
7
+ TextService::Text.respond_to?(:reverse!).should == true
8
+ TextService::Text.reverse!(text: 'gavin').should == 'nivag'
9
+ end
10
+
11
+ it 'defines aliases' do
12
+ command = TextService::Commands::Text::Reverse
13
+
14
+ command::Model.should == TextService::Models::Text
15
+ command::Serializer.should == TextService::Serializers::Text
16
+ command::Commands.should == TextService::Commands
17
+ command::Models.should == TextService::Models
18
+ end
19
+ end
20
+
21
+ context 'with a commands in a namespace like Commands::Template::Create' do
22
+ it 'defines sugar methods' do
23
+ Commands::Math.respond_to?(:add).should == true
24
+ Commands::Math.respond_to?(:add!).should == true
25
+ Commands::Math.add!(a: 1, b: 2).should == 3
26
+ end
27
+ end
28
+ end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,2 @@
1
1
  require 'restpack_service'
2
+ require 'support/fixtures'
@@ -0,0 +1,41 @@
1
+ module TextService
2
+ module Models
3
+ class Text
4
+ end
5
+ end
6
+
7
+ module Serializers
8
+ class Text
9
+ end
10
+ end
11
+
12
+ module Commands
13
+ module Text
14
+ class Reverse < RestPack::Service::Command
15
+ required do
16
+ string :text
17
+ end
18
+
19
+ def execute
20
+ text.reverse
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+
28
+ module Commands
29
+ module Math
30
+ class Add < RestPack::Service::Command
31
+ required do
32
+ integer :a
33
+ integer :b
34
+ end
35
+
36
+ def execute
37
+ a + b
38
+ end
39
+ end
40
+ end
41
+ 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.62
4
+ version: 0.0.63
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Joyce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-19 00:00:00.000000000 Z
11
+ date: 2014-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mutations
@@ -236,10 +236,11 @@ files:
236
236
  - lib/restpack_service/support/spec_helper.rb
237
237
  - lib/restpack_service/version.rb
238
238
  - restpack_service.gemspec
239
+ - spec/command_spec.rb
239
240
  - spec/configuration_spec.rb
240
241
  - spec/response_spec.rb
241
- - spec/service_spec.rb
242
242
  - spec/spec_helper.rb
243
+ - spec/support/fixtures.rb
243
244
  homepage: https://github.com/RestPack
244
245
  licenses:
245
246
  - MIT
@@ -260,12 +261,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
260
261
  version: '0'
261
262
  requirements: []
262
263
  rubyforge_project:
263
- rubygems_version: 2.0.7
264
+ rubygems_version: 2.0.14
264
265
  signing_key:
265
266
  specification_version: 4
266
267
  summary: A base for RestPack services
267
268
  test_files:
269
+ - spec/command_spec.rb
268
270
  - spec/configuration_spec.rb
269
271
  - spec/response_spec.rb
270
- - spec/service_spec.rb
271
272
  - spec/spec_helper.rb
273
+ - spec/support/fixtures.rb
274
+ has_rdoc:
data/spec/service_spec.rb DELETED
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RestPack::Service::Command do
4
- pending "Write some specs"
5
- end