imperator-ext 0.2.0
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/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +69 -0
- data/LICENSE.txt +20 -0
- data/README.md +339 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/docs/Design.md +197 -0
- data/imperator-ext.gemspec +90 -0
- data/lib/imperator/command/class_factory.rb +121 -0
- data/lib/imperator/command/macros.rb +13 -0
- data/lib/imperator/command/method_factory.rb +17 -0
- data/lib/imperator/command/rest.rb +7 -0
- data/lib/imperator/command/rest_helper.rb +78 -0
- data/lib/imperator/command-ext.rb +14 -0
- data/lib/imperator/factory.rb +3 -0
- data/lib/imperator/mongoid/attribute_helper.rb +29 -0
- data/lib/imperator/mongoid/command/rest.rb +9 -0
- data/lib/imperator/mongoid/command.rb +21 -0
- data/lib/imperator/mongoid.rb +6 -0
- data/lib/imperator-ext.rb +5 -0
- data/spec/imperator-ext/command/class_factory_spec.rb +186 -0
- data/spec/imperator-ext/command/macros_spec.rb +32 -0
- data/spec/imperator-ext/command/method_factory_spec.rb +64 -0
- data/spec/imperator-ext/command/rest_helper_spec.rb +7 -0
- data/spec/imperator-ext/command/rest_spec.rb +8 -0
- data/spec/imperator-ext/mongoid/command_spec.rb +10 -0
- data/spec/imperator-ext/mongoid/rest_command_spec.rb +8 -0
- data/spec/imperator-ext/shared_ex/attribute_helper_ex.rb +54 -0
- data/spec/imperator-ext/shared_ex/command_ex.rb +0 -0
- data/spec/imperator-ext/shared_ex/rest_helper_ex.rb +15 -0
- data/spec/spec_helper.rb +11 -0
- metadata +195 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Commander
|
4
|
+
extend Imperator::Command::MethodFactory
|
5
|
+
end
|
6
|
+
|
7
|
+
class UpdateCommand < Imperator::Command
|
8
|
+
end
|
9
|
+
|
10
|
+
module Landlord
|
11
|
+
module Account
|
12
|
+
class PayCommand < Imperator::Command
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module Landlord
|
18
|
+
module AccountController
|
19
|
+
class Action # imperator action
|
20
|
+
end
|
21
|
+
|
22
|
+
class Pay < Action # imperator action
|
23
|
+
extend Imperator::Command::MethodFactory
|
24
|
+
|
25
|
+
command_method :pay, object: 'hello', ns: self.parent
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe Imperator::Command::MethodFactory do
|
31
|
+
subject { clazz.new }
|
32
|
+
|
33
|
+
let(:clazz) { Commander }
|
34
|
+
|
35
|
+
describe '.command_method(command)' do
|
36
|
+
before do
|
37
|
+
clazz.command_method :update
|
38
|
+
end
|
39
|
+
|
40
|
+
its(:update_command) { should be_a(Imperator::Command) }
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '.command_method(command, options)' do
|
44
|
+
before do
|
45
|
+
clazz.command_method :create, object: 'hello'
|
46
|
+
end
|
47
|
+
|
48
|
+
its(:update_command) { should be_a(Imperator::Command) }
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'with namespace :ns option' do
|
52
|
+
before do
|
53
|
+
clazz.command_method :pay, object: 'hello', ns: Landlord::Account
|
54
|
+
end
|
55
|
+
|
56
|
+
specify { subject.pay_command.class.to_s.should == 'Landlord::Account::PayCommand' }
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'with namespace :ns option as self.parent' do
|
60
|
+
subject { Landlord::AccountController::Pay }
|
61
|
+
|
62
|
+
specify { subject.new.pay_command.class.to_s.should == 'Landlord::Account::PayCommand' }
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'imperator-ext/shared_ex/attribute_helper_ex'
|
3
|
+
|
4
|
+
describe Imperator::Mongoid::Command do
|
5
|
+
subject { clazz }
|
6
|
+
let(:clazz) { Imperator::Mongoid::Command }
|
7
|
+
|
8
|
+
it_behaves_like 'an attribute helper'
|
9
|
+
it_behaves_like 'a mongoid rest command'
|
10
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# require 'imperator/command/macros'
|
2
|
+
|
3
|
+
class Person
|
4
|
+
include Mongoid::Document
|
5
|
+
|
6
|
+
field :name
|
7
|
+
field :title
|
8
|
+
field :age, type: Integer
|
9
|
+
end
|
10
|
+
|
11
|
+
class UpdatePersonCommand < Imperator::Mongoid::Command
|
12
|
+
attributes_for Person
|
13
|
+
end
|
14
|
+
|
15
|
+
class ShowPersonCommand < Imperator::Mongoid::Command
|
16
|
+
attributes_for Person, except: :age
|
17
|
+
end
|
18
|
+
|
19
|
+
shared_examples 'a mongoid rest command' do
|
20
|
+
context 'update' do
|
21
|
+
before :all do
|
22
|
+
Imperator::Command::ClassFactory.use do |factory|
|
23
|
+
# factory.default_rest_class = Imperator::Mongoid::Command::Rest
|
24
|
+
factory.rest_command :create, Person, :auto_attributes => true do
|
25
|
+
def hello
|
26
|
+
"hello"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'CreatePersonCommand created' do
|
33
|
+
let(:command) { CreatePersonCommand.new }
|
34
|
+
|
35
|
+
specify { CreatePersonCommand.superclass.should == Imperator::Mongoid::Command::Rest }
|
36
|
+
specify { command.hello.should == "hello" }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
shared_examples "an attribute helper" do
|
42
|
+
describe 'includes all Mongoid model fields' do
|
43
|
+
subject { UpdatePersonCommand.attribute_set }
|
44
|
+
|
45
|
+
its(:names) { should include :name, :title, :age }
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'includes all Mongoid model fields :except age' do
|
49
|
+
subject { ShowPersonCommand.attribute_set }
|
50
|
+
|
51
|
+
its(:names) { should include :name, :title }
|
52
|
+
its(:names) { should_not include :age }
|
53
|
+
end
|
54
|
+
end
|
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'mongoid'
|
3
|
+
require 'imperator-ext'
|
4
|
+
|
5
|
+
# Requires supporting files with custom matchers and macros, etc,
|
6
|
+
# in ./support/ and its subdirectories.
|
7
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: imperator-ext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kristian Mandrup
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: virtus
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: imperator
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.8.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.8.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rdoc
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.12'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.12'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.0.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.0.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: jeweler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.8.4
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.8.4
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: simplecov
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.5'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0.5'
|
126
|
+
description: Factories, Macros, REST helpers and Mongoid integration
|
127
|
+
email: kmandrup@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files:
|
131
|
+
- LICENSE.txt
|
132
|
+
- README.md
|
133
|
+
files:
|
134
|
+
- .document
|
135
|
+
- .rspec
|
136
|
+
- Gemfile
|
137
|
+
- Gemfile.lock
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- VERSION
|
142
|
+
- docs/Design.md
|
143
|
+
- imperator-ext.gemspec
|
144
|
+
- lib/imperator-ext.rb
|
145
|
+
- lib/imperator/command-ext.rb
|
146
|
+
- lib/imperator/command/class_factory.rb
|
147
|
+
- lib/imperator/command/macros.rb
|
148
|
+
- lib/imperator/command/method_factory.rb
|
149
|
+
- lib/imperator/command/rest.rb
|
150
|
+
- lib/imperator/command/rest_helper.rb
|
151
|
+
- lib/imperator/factory.rb
|
152
|
+
- lib/imperator/mongoid.rb
|
153
|
+
- lib/imperator/mongoid/attribute_helper.rb
|
154
|
+
- lib/imperator/mongoid/command.rb
|
155
|
+
- lib/imperator/mongoid/command/rest.rb
|
156
|
+
- spec/imperator-ext/command/class_factory_spec.rb
|
157
|
+
- spec/imperator-ext/command/macros_spec.rb
|
158
|
+
- spec/imperator-ext/command/method_factory_spec.rb
|
159
|
+
- spec/imperator-ext/command/rest_helper_spec.rb
|
160
|
+
- spec/imperator-ext/command/rest_spec.rb
|
161
|
+
- spec/imperator-ext/mongoid/command_spec.rb
|
162
|
+
- spec/imperator-ext/mongoid/rest_command_spec.rb
|
163
|
+
- spec/imperator-ext/shared_ex/attribute_helper_ex.rb
|
164
|
+
- spec/imperator-ext/shared_ex/command_ex.rb
|
165
|
+
- spec/imperator-ext/shared_ex/rest_helper_ex.rb
|
166
|
+
- spec/spec_helper.rb
|
167
|
+
homepage: http://github.com/kristianmandrup/imperator-ext
|
168
|
+
licenses:
|
169
|
+
- MIT
|
170
|
+
post_install_message:
|
171
|
+
rdoc_options: []
|
172
|
+
require_paths:
|
173
|
+
- lib
|
174
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
+
none: false
|
176
|
+
requirements:
|
177
|
+
- - ! '>='
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
segments:
|
181
|
+
- 0
|
182
|
+
hash: -3288576765044501661
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
none: false
|
185
|
+
requirements:
|
186
|
+
- - ! '>='
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
requirements: []
|
190
|
+
rubyforge_project:
|
191
|
+
rubygems_version: 1.8.24
|
192
|
+
signing_key:
|
193
|
+
specification_version: 3
|
194
|
+
summary: Various extensions for Imperator
|
195
|
+
test_files: []
|