mvcli 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mvcli/app.rb +6 -1
- data/lib/mvcli/provisioning.rb +69 -0
- data/lib/mvcli/version.rb +1 -1
- data/mvcli.gemspec +1 -0
- data/spec/mvcli/dummy/app/providers/test_provider.rb +5 -0
- data/spec/mvcli/provisioning_spec.rb +50 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 843f2e9a35f848c28d8fdf547f31234e1ee1ebd9
|
4
|
+
data.tar.gz: 0505a91108a5c2ea656d6c0b2d06307a812fa04b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdbb170f92c985159aff0be98f9111e5bc38fb13bf71ce66a0cd23bc1e4b83bda7839d41fa51fe0545875469264c1c755343fcc659fd283a7e6ad4bacf16130c
|
7
|
+
data.tar.gz: bb7efd8d702ac6d6d1b798c2659b5c7f09fb915bd11c4a320a84a285ca6b309204b3215171ab4714c6515efcdca92ce33683b1060cf2107d369ed95f33ebdd6b
|
data/lib/mvcli/app.rb
CHANGED
@@ -2,16 +2,21 @@ require_relative "middleware"
|
|
2
2
|
require_relative "command"
|
3
3
|
require_relative "actions"
|
4
4
|
require_relative "router"
|
5
|
+
require_relative "provisioning"
|
5
6
|
|
6
7
|
module MVCLI
|
7
8
|
class App
|
8
9
|
def initialize
|
9
10
|
@router = Router.new Actions.new root
|
10
11
|
@router.instance_eval route_file.read, route_file.to_s, 1
|
12
|
+
ActiveSupport::Dependencies.autoload_paths << root.join('app/providers')
|
13
|
+
@middleware = Middleware.new
|
14
|
+
@middleware << Provisioning::Middleware.new
|
15
|
+
@middleware << @router
|
11
16
|
end
|
12
17
|
|
13
18
|
def call(command)
|
14
|
-
@
|
19
|
+
@middleware.call command
|
15
20
|
end
|
16
21
|
|
17
22
|
def root
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "map"
|
2
|
+
require "active_support/concern"
|
3
|
+
require "active_support/dependencies"
|
4
|
+
|
5
|
+
module MVCLI
|
6
|
+
module Provisioning
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
UnsatisfiedRequirement = Class.new StandardError
|
9
|
+
MissingScope = Class.new StandardError
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def requires(*deps)
|
13
|
+
deps.each do |dep|
|
14
|
+
self.send(:define_method, dep) {Scope[dep]}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Scope
|
20
|
+
def initialize(provisioner)
|
21
|
+
@provisioner = provisioner
|
22
|
+
end
|
23
|
+
|
24
|
+
def [](name)
|
25
|
+
@provisioner[name]
|
26
|
+
end
|
27
|
+
|
28
|
+
def evaluate
|
29
|
+
old = self.class.current
|
30
|
+
self.class.current = self
|
31
|
+
yield
|
32
|
+
ensure
|
33
|
+
self.class.current = old
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.current
|
37
|
+
Thread.current[self.class.name]
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.current!
|
41
|
+
current or fail MissingScope, "attempting to access scope, but none is active!"
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.current=(scope)
|
45
|
+
Thread.current[self.class.name] = scope
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.[](name)
|
49
|
+
current![name] or fail UnsatisfiedRequirement, "'#{name}' is required, but can't find it"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Provisioner
|
54
|
+
def [](name)
|
55
|
+
provider = "#{name.capitalize}Provider".constantize.new
|
56
|
+
provider.value
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class Middleware
|
61
|
+
def call(command)
|
62
|
+
Scope.new(Provisioner.new).evaluate do
|
63
|
+
yield command
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
::Object.send :include, self
|
68
|
+
end
|
69
|
+
end
|
data/lib/mvcli/version.rb
CHANGED
data/mvcli.gemspec
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "mvcli/provisioning"
|
3
|
+
|
4
|
+
describe "Provisioning" do
|
5
|
+
use_natural_assertions
|
6
|
+
describe "Scope" do
|
7
|
+
Given(:provisioner) {{}}
|
8
|
+
Given(:mod) {Module.new {include MVCLI::Provisioning}}
|
9
|
+
Given(:cls) {m = mod; Class.new {include m}}
|
10
|
+
Given(:obj) {cls.new}
|
11
|
+
Given(:container) {MVCLI::Provisioning::Scope.new provisioner}
|
12
|
+
context "with a requirement is specified on the module" do
|
13
|
+
Given {mod.requires :foo}
|
14
|
+
context "when accessing it but it is not present" do
|
15
|
+
When(:result) {container.evaluate {obj.foo}}
|
16
|
+
Then {result.should have_failed MVCLI::Provisioning::UnsatisfiedRequirement, /foo/}
|
17
|
+
end
|
18
|
+
context "and there is a scope which satisfies the requirement" do
|
19
|
+
Given(:foo) {Object.new}
|
20
|
+
Given {provisioner[:foo] = foo}
|
21
|
+
|
22
|
+
context "when a dependency is accessed in the context of the container" do
|
23
|
+
When(:result) {container.evaluate {obj.foo}}
|
24
|
+
Then {result == foo}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
context "accessing requirements with no scope" do
|
28
|
+
When(:result) {obj.foo}
|
29
|
+
Then {result.should have_failed MVCLI::Provisioning::MissingScope}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "Provisioner" do
|
35
|
+
Given do
|
36
|
+
ActiveSupport::Dependencies.clear
|
37
|
+
ActiveSupport::Dependencies.autoload_paths.clear
|
38
|
+
ActiveSupport::Dependencies.autoload_paths << File.expand_path('../dummy/app/providers', __FILE__)
|
39
|
+
end
|
40
|
+
Given(:provisioner) {MVCLI::Provisioning::Provisioner.new}
|
41
|
+
context "when no provider exists for a value" do
|
42
|
+
When(:result) {provisioner[:does_not_exist]}
|
43
|
+
Then {result.should have_failed}
|
44
|
+
end
|
45
|
+
context "when a provider exists" do
|
46
|
+
When(:result) {provisioner[:test]}
|
47
|
+
Then {result == "here is a free value just for you!!"}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mvcli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charles Lowell
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
UgImJlChAzCoDP9zi9tdm6jAr7ttF25R9PPYr11ILb7dYe3qUzlNlM6zJx/nb31b
|
30
30
|
IhdyRVup4qLcqYSTPsm6u7VA
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2013-05-
|
32
|
+
date: 2013-05-25 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: map
|
@@ -45,6 +45,20 @@ dependencies:
|
|
45
45
|
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: activesupport
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
48
62
|
description: MVC Framework for Building Command Line Apps
|
49
63
|
email:
|
50
64
|
- cowboyd@thefrontside.net
|
@@ -66,14 +80,17 @@ files:
|
|
66
80
|
- lib/mvcli/erb.rb
|
67
81
|
- lib/mvcli/loader.rb
|
68
82
|
- lib/mvcli/middleware.rb
|
83
|
+
- lib/mvcli/provisioning.rb
|
69
84
|
- lib/mvcli/renderer.rb
|
70
85
|
- lib/mvcli/router.rb
|
71
86
|
- lib/mvcli/version.rb
|
72
87
|
- mvcli.gemspec
|
73
88
|
- spec/mvcli/actions_spec.rb
|
89
|
+
- spec/mvcli/dummy/app/providers/test_provider.rb
|
74
90
|
- spec/mvcli/erb_spec.rb
|
75
91
|
- spec/mvcli/loader_spec.rb
|
76
92
|
- spec/mvcli/middleware_spec.rb
|
93
|
+
- spec/mvcli/provisioning_spec.rb
|
77
94
|
- spec/mvcli/router_spec.rb
|
78
95
|
- spec/spec_helper.rb
|
79
96
|
homepage: https://github.com/cowboyd/mvcli
|
@@ -102,8 +119,10 @@ specification_version: 4
|
|
102
119
|
summary: Local Apps. Remote Apps. They're all at your fingertips
|
103
120
|
test_files:
|
104
121
|
- spec/mvcli/actions_spec.rb
|
122
|
+
- spec/mvcli/dummy/app/providers/test_provider.rb
|
105
123
|
- spec/mvcli/erb_spec.rb
|
106
124
|
- spec/mvcli/loader_spec.rb
|
107
125
|
- spec/mvcli/middleware_spec.rb
|
126
|
+
- spec/mvcli/provisioning_spec.rb
|
108
127
|
- spec/mvcli/router_spec.rb
|
109
128
|
- spec/spec_helper.rb
|