imperator 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/imperator.gemspec +0 -4
- data/lib/imperator/command.rb +10 -13
- data/lib/imperator/version.rb +1 -1
- data/spec/imperator/command_spec.rb +2 -13
- metadata +13 -47
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 78ba3f973dcf41d4527c6862e2608a746ade3ee0
|
4
|
+
data.tar.gz: 32841add73d035cf2e9770ee46339c59a154f1b9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ded15ca1019035a5a89ec5225d3947129e20e13f99fb7811beb519473504046e4c4bfe093c76deb74d86229f1de5e4b7c036873207b8b32fd721050ad0de8204
|
7
|
+
data.tar.gz: c55f5a16026e92ebc3a95ed9a7ce19b4b8fdc404012786da8275acb90a432e8e00a62c7b6c1a6d9525a4172d4513173900b969bba644c8bf5219669ef4fb5a0d
|
data/Gemfile
CHANGED
data/imperator.gemspec
CHANGED
@@ -19,9 +19,5 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
# specify any dependencies here; for example:
|
22
|
-
s.add_development_dependency "rspec"
|
23
|
-
# s.add_runtime_dependency "rest-client"
|
24
|
-
s.add_runtime_dependency "uuidtools"
|
25
|
-
s.add_runtime_dependency "activemodel"
|
26
22
|
s.add_runtime_dependency "virtus"
|
27
23
|
end
|
data/lib/imperator/command.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
require 'uuidtools'
|
2
1
|
require 'active_model'
|
3
2
|
require 'virtus'
|
4
3
|
class Imperator::Command
|
5
4
|
include ActiveModel::Validations
|
6
5
|
extend ActiveModel::Callbacks
|
7
|
-
include Virtus
|
6
|
+
include Virtus.model
|
8
7
|
|
9
8
|
if defined? ActiveModel::Serializable
|
10
9
|
include ActiveModel::Serializable::JSON
|
@@ -16,13 +15,11 @@ class Imperator::Command
|
|
16
15
|
|
17
16
|
define_model_callbacks :create, :perform, :initialize
|
18
17
|
|
19
|
-
attribute :id, String, :default => proc { UUIDTools::UUID.timestamp_create.to_s }
|
20
|
-
|
21
18
|
def self.action(&block)
|
22
19
|
define_method(:action, &block)
|
23
20
|
end
|
24
21
|
|
25
|
-
|
22
|
+
alias params attributes
|
26
23
|
|
27
24
|
def as_json(*args)
|
28
25
|
attributes.as_json(*args)
|
@@ -33,13 +30,13 @@ class Imperator::Command
|
|
33
30
|
end
|
34
31
|
|
35
32
|
def commit!
|
36
|
-
raise Imperator::InvalidCommandError
|
37
|
-
|
33
|
+
raise Imperator::InvalidCommandError, 'Command was invalid' unless valid?
|
34
|
+
commit
|
38
35
|
end
|
39
36
|
|
40
37
|
def commit
|
41
|
-
#TODO: background code for this
|
42
|
-
|
38
|
+
# TODO: background code for this
|
39
|
+
perform
|
43
40
|
end
|
44
41
|
|
45
42
|
def initialize(*)
|
@@ -53,7 +50,7 @@ class Imperator::Command
|
|
53
50
|
end
|
54
51
|
|
55
52
|
def self.load(command_string)
|
56
|
-
|
53
|
+
new(JSON.parse(command_string))
|
57
54
|
end
|
58
55
|
|
59
56
|
def load(command_string)
|
@@ -61,13 +58,13 @@ class Imperator::Command
|
|
61
58
|
end
|
62
59
|
|
63
60
|
def perform!
|
64
|
-
raise InvalidCommandError
|
65
|
-
|
61
|
+
raise InvalidCommandError, 'Command was invalid' unless valid?
|
62
|
+
perform
|
66
63
|
end
|
67
64
|
|
68
65
|
# @abstract
|
69
66
|
def action
|
70
|
-
raise NoMethodError
|
67
|
+
raise NoMethodError, "Please define #action for #{self.class.name}"
|
71
68
|
end
|
72
69
|
|
73
70
|
def perform
|
data/lib/imperator/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'imperator'
|
2
2
|
describe Imperator::Command do
|
3
3
|
|
4
|
-
describe "
|
4
|
+
describe "actions" do
|
5
5
|
class CommandTestException < Exception; end
|
6
6
|
context "using DSL " do
|
7
7
|
class DSLTestCommand < Imperator::Command
|
@@ -29,16 +29,6 @@ describe Imperator::Command do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe "actions" do
|
33
|
-
context "using DSL" do
|
34
|
-
class ActionDSLExampleCommand < Imperator::Command
|
35
|
-
action do
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
32
|
describe "attributes" do
|
43
33
|
class AttributeCommand < Imperator::Command
|
44
34
|
attribute :gets_default, String, :default => "foo"
|
@@ -66,8 +56,7 @@ describe Imperator::Command do
|
|
66
56
|
|
67
57
|
it "will create attributes as json" do
|
68
58
|
command = AttributeCommand.new
|
69
|
-
command.as_json.should == {"
|
70
|
-
"gets_default" => "foo",
|
59
|
+
command.as_json.should == { "gets_default" => "foo",
|
71
60
|
"declared_attr" => nil}
|
72
61
|
end
|
73
62
|
end
|
metadata
CHANGED
@@ -1,61 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imperator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Keith Gaddis
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
11
|
+
date: 2017-06-26 00:00:00.000000000 Z
|
14
12
|
dependencies:
|
15
13
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
requirement:
|
18
|
-
none: false
|
19
|
-
requirements:
|
20
|
-
- - ! '>='
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '0'
|
23
|
-
type: :development
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: *70180076248340
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: uuidtools
|
28
|
-
requirement: &70180076247920 !ruby/object:Gem::Requirement
|
29
|
-
none: false
|
30
|
-
requirements:
|
31
|
-
- - ! '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: *70180076247920
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: activemodel
|
39
|
-
requirement: &70180076278720 !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
14
|
+
name: virtus
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
41
16
|
requirements:
|
42
|
-
- -
|
17
|
+
- - ">="
|
43
18
|
- !ruby/object:Gem::Version
|
44
19
|
version: '0'
|
45
20
|
type: :runtime
|
46
21
|
prerelease: false
|
47
|
-
version_requirements:
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: virtus
|
50
|
-
requirement: &70180076278300 !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
23
|
requirements:
|
53
|
-
- -
|
24
|
+
- - ">="
|
54
25
|
- !ruby/object:Gem::Version
|
55
26
|
version: '0'
|
56
|
-
type: :runtime
|
57
|
-
prerelease: false
|
58
|
-
version_requirements: *70180076278300
|
59
27
|
description: Imperator is a small gem to help with command objects. The command pattern
|
60
28
|
is a design pattern used to encapsulate all of the information needed to execute
|
61
29
|
a method or process at a point in time. In a web application, commands are typically
|
@@ -66,7 +34,7 @@ executables: []
|
|
66
34
|
extensions: []
|
67
35
|
extra_rdoc_files: []
|
68
36
|
files:
|
69
|
-
- .gitignore
|
37
|
+
- ".gitignore"
|
70
38
|
- Gemfile
|
71
39
|
- README.md
|
72
40
|
- Rakefile
|
@@ -76,30 +44,28 @@ files:
|
|
76
44
|
- lib/imperator/invalid_command_error.rb
|
77
45
|
- lib/imperator/version.rb
|
78
46
|
- spec/imperator/command_spec.rb
|
79
|
-
has_rdoc: true
|
80
47
|
homepage: http://github.com/karmajunkie/imperator
|
81
48
|
licenses: []
|
49
|
+
metadata: {}
|
82
50
|
post_install_message:
|
83
51
|
rdoc_options: []
|
84
52
|
require_paths:
|
85
53
|
- lib
|
86
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
55
|
requirements:
|
89
|
-
- -
|
56
|
+
- - ">="
|
90
57
|
- !ruby/object:Gem::Version
|
91
58
|
version: '0'
|
92
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
-
none: false
|
94
60
|
requirements:
|
95
|
-
- -
|
61
|
+
- - ">="
|
96
62
|
- !ruby/object:Gem::Version
|
97
63
|
version: '0'
|
98
64
|
requirements: []
|
99
65
|
rubyforge_project:
|
100
|
-
rubygems_version:
|
66
|
+
rubygems_version: 2.6.8
|
101
67
|
signing_key:
|
102
|
-
specification_version:
|
68
|
+
specification_version: 4
|
103
69
|
summary: Imperator supports the command pattern
|
104
70
|
test_files:
|
105
71
|
- spec/imperator/command_spec.rb
|