mvcli 0.0.2 → 0.0.3

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: d38bca7cf98c3cad670fe5df941fd17c8d8cd267
4
- data.tar.gz: a1438f4ab557e0f083b9eca8875b67a2b9b12a27
3
+ metadata.gz: 843f2e9a35f848c28d8fdf547f31234e1ee1ebd9
4
+ data.tar.gz: 0505a91108a5c2ea656d6c0b2d06307a812fa04b
5
5
  SHA512:
6
- metadata.gz: b707863564e785f0fe67fe47712a2ba416214708a4ae6fce7d9500e5d5347b6c2bc0b2112186bade3fda1baf1b7f1426c2eb0199189615e59d2b90e3b3969dd4
7
- data.tar.gz: 1add93e30613c13ba50b798543e76975df840a4f4b563cb83af8988118848994fdedfdd8e08c2772cc39e3f2e95f2a6864e074212bd02c5e7033fc9f30ded21d
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
- @router.call command
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
@@ -1,3 +1,3 @@
1
1
  module MVCLI
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/mvcli.gemspec CHANGED
@@ -19,4 +19,5 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "map"
22
+ spec.add_dependency "activesupport", ">= 3.0"
22
23
  end
@@ -0,0 +1,5 @@
1
+ class TestProvider
2
+ def value
3
+ "here is a free value just for you!!"
4
+ end
5
+ end
@@ -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.2
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-22 00:00:00.000000000 Z
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