methodmissing-scrooge 1.0.4 → 2.0.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.
Files changed (58) hide show
  1. data/README.textile +139 -449
  2. data/Rakefile +20 -19
  3. data/VERSION.yml +2 -2
  4. data/lib/attributes_proxy.rb +121 -0
  5. data/lib/scrooge.rb +206 -47
  6. data/rails/init.rb +1 -10
  7. data/test/helper.rb +88 -0
  8. data/test/models/mysql_user.rb +4 -0
  9. data/test/scrooge_test.rb +75 -0
  10. data/test/setup.rb +3 -0
  11. metadata +11 -76
  12. data/assets/config/scrooge.yml.template +0 -27
  13. data/lib/scrooge/core/string.rb +0 -29
  14. data/lib/scrooge/core/symbol.rb +0 -21
  15. data/lib/scrooge/core/thread.rb +0 -26
  16. data/lib/scrooge/framework/base.rb +0 -315
  17. data/lib/scrooge/framework/rails.rb +0 -132
  18. data/lib/scrooge/middleware/tracker.rb +0 -46
  19. data/lib/scrooge/orm/active_record.rb +0 -159
  20. data/lib/scrooge/orm/base.rb +0 -102
  21. data/lib/scrooge/profile.rb +0 -223
  22. data/lib/scrooge/storage/base.rb +0 -46
  23. data/lib/scrooge/storage/memory.rb +0 -25
  24. data/lib/scrooge/strategy/base.rb +0 -74
  25. data/lib/scrooge/strategy/controller.rb +0 -31
  26. data/lib/scrooge/strategy/scope.rb +0 -15
  27. data/lib/scrooge/strategy/stage.rb +0 -77
  28. data/lib/scrooge/strategy/track.rb +0 -19
  29. data/lib/scrooge/strategy/track_then_scope.rb +0 -41
  30. data/lib/scrooge/tracker/app.rb +0 -161
  31. data/lib/scrooge/tracker/base.rb +0 -66
  32. data/lib/scrooge/tracker/model.rb +0 -150
  33. data/lib/scrooge/tracker/resource.rb +0 -181
  34. data/spec/fixtures/config/scrooge/scopes/1234567891/scope.yml +0 -2
  35. data/spec/fixtures/config/scrooge.yml +0 -20
  36. data/spec/helpers/framework/rails/cache.rb +0 -25
  37. data/spec/spec_helper.rb +0 -55
  38. data/spec/units/scrooge/core/string_spec.rb +0 -21
  39. data/spec/units/scrooge/core/symbol_spec.rb +0 -13
  40. data/spec/units/scrooge/core/thread_spec.rb +0 -15
  41. data/spec/units/scrooge/framework/base_spec.rb +0 -160
  42. data/spec/units/scrooge/framework/rails_spec.rb +0 -40
  43. data/spec/units/scrooge/orm/base_spec.rb +0 -61
  44. data/spec/units/scrooge/profile_spec.rb +0 -79
  45. data/spec/units/scrooge/storage/base_spec.rb +0 -35
  46. data/spec/units/scrooge/storage/memory_spec.rb +0 -20
  47. data/spec/units/scrooge/strategy/base_spec.rb +0 -62
  48. data/spec/units/scrooge/strategy/controller_spec.rb +0 -26
  49. data/spec/units/scrooge/strategy/scope_spec.rb +0 -18
  50. data/spec/units/scrooge/strategy/stage_spec.rb +0 -35
  51. data/spec/units/scrooge/strategy/track_spec.rb +0 -19
  52. data/spec/units/scrooge/strategy/track_then_scope_spec.rb +0 -22
  53. data/spec/units/scrooge/tracker/app_spec.rb +0 -68
  54. data/spec/units/scrooge/tracker/base_spec.rb +0 -29
  55. data/spec/units/scrooge/tracker/model_spec.rb +0 -79
  56. data/spec/units/scrooge/tracker/resource_spec.rb +0 -115
  57. data/spec/units/scrooge_spec.rb +0 -13
  58. data/tasks/scrooge.rake +0 -43
@@ -1,35 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe Scrooge::Strategy::Stage do
4
-
5
- before(:each) do
6
- @stage = Scrooge::Strategy::Stage.new( :test, :for => 0.5 ) do
7
- 'payload'
8
- end
9
- end
10
-
11
- it "should be able to determine if it's executeable" do
12
- @stage.executeable?().should equal( true )
13
- end
14
-
15
- it "should be able to determine if it's initialized" do
16
- @stage.initialized?().should equal( true )
17
- end
18
-
19
- it "should be able to determine if it's in execution" do
20
- @stage.running?().should equal( false )
21
- @stage.execute!
22
- @stage.running?().should equal( false )
23
- end
24
-
25
- it "should be able to execute itself" do
26
- @stage.execute!().should eql( "payload" )
27
- end
28
-
29
- it "should be able to determine if it's terminated" do
30
- @stage.terminated?().should equal( false )
31
- @stage.execute!
32
- @stage.terminated?().should equal( true )
33
- end
34
-
35
- end
@@ -1,19 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe Scrooge::Strategy::Track do
4
-
5
- before(:each) do
6
- Scrooge::Base.profile.stub!(:warmup).and_return( 1 )
7
- @track = Scrooge::Strategy::Track.new
8
- @controller = Scrooge::Strategy::Controller.new( @track )
9
- Scrooge::Base.profile.framework.stub!(:install_tracking_middleware).and_return('installed')
10
- Scrooge::Base.profile.stub!(:start_tracking!).and_return('tracking')
11
- end
12
-
13
- it "should be able to execute a given strategy" do
14
- with_rails do
15
- lambda{ @controller.run!().value }.should raise_error( SystemExit )
16
- end
17
- end
18
-
19
- end
@@ -1,22 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe Scrooge::Strategy::TrackThenScope do
4
-
5
- before(:each) do
6
- Scrooge::Base.profile.stub!(:warmup).and_return( 1 )
7
- @track_then_scope = Scrooge::Strategy::TrackThenScope.new
8
- @controller = Scrooge::Strategy::Controller.new( @track_then_scope )
9
- Scrooge::Base.profile.framework.stub!(:install_tracking_middleware).and_return('installed')
10
- Scrooge::Base.profile.framework.stub!(:uninstall_tracking_middleware).and_return('installed')
11
- Scrooge::Base.profile.framework.stub!(:install_scope_middleware).and_return('installed')
12
- end
13
-
14
- it "should be able to execute a given strategy" do
15
- Scrooge::Base.profile.stub!(:synchronize!).and_return([])
16
- Scrooge::Base.profile.stub!(:aggregate!).and_return([])
17
- with_rails do
18
- @controller.run!().value.should include( 'installed' )
19
- end
20
- end
21
-
22
- end
@@ -1,68 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe Scrooge::Tracker::App do
4
-
5
- before(:each) do
6
- @app = Scrooge::Tracker::App.new
7
- @resource = Scrooge::Tracker::Resource.new do |resource|
8
- resource.controller = 'products'
9
- resource.action = 'show'
10
- resource.method = :get
11
- resource.format = :html
12
- resource.is_public = true
13
- end
14
- end
15
-
16
- it "should be able to determine if any resources has been tracked" do
17
- @app.any?().should equal( false )
18
- end
19
-
20
- it "should initialize with an empty set of resources" do
21
- @app.resources.should eql( Set.new )
22
- end
23
-
24
- it "should be able to accept resources" do
25
- lambda { @app << 'a_resource' }.should change( @app.resources, :size ).from(0).to(1)
26
- end
27
-
28
- it "should be able to dump itself to a serializeable representation" do
29
- @app << @resource
30
- with_rails do
31
- @app.marshal_dump().should eql( [ { "products_show_get_public" => { :method => :get,
32
- :models => [],
33
- :format => :html,
34
- :action => "show",
35
- :controller => "products",
36
- :is_public => true } } ] )
37
- end
38
- end
39
-
40
- it "should be able to restore itself from a serialized representation" do
41
- @app << @resource
42
- with_rails do
43
- Marshal.load( Marshal.dump( @app ) ).should eql( @app )
44
- end
45
- end
46
-
47
- it "should be able to compare itself to other app trackers" do
48
- with_rails do
49
- @app.should eql( @app )
50
- end
51
- end
52
-
53
- it "should implemented a custom Object#inspect" do
54
- @app << @resource
55
- @app.inspect().should match( /GET/ )
56
- @app.inspect().should match( /products/ )
57
- end
58
-
59
- it "should be able to determine if a resource's been seen before" do
60
- @app.resource_for( @resource ).should eql( @resource )
61
- end
62
-
63
- it "should be able to find a resource" do
64
- @app << @resource
65
- @app.resource( @resource ).should eql( @resource )
66
- end
67
-
68
- end
@@ -1,29 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe "Scrooge::Tracker::Base singleton" do
4
-
5
- it "should be able to yield an instance from given Marshalled data" do
6
- lambda{ Scrooge::Tracker::Base.load( [] ) }.should raise_error( Scrooge::Tracker::Base::NotImplemented )
7
- end
8
-
9
- end
10
-
11
- describe Scrooge::Tracker::Base do
12
-
13
- before(:each) do
14
- @base = Scrooge::Tracker::Base.new
15
- end
16
-
17
- it "should have a numeric representation" do
18
- @base.to_i.should equal(0)
19
- end
20
-
21
- it "should be able to dump itself to serializeable representation" do
22
- lambda{ @base.marshal_dump }.should raise_error( Scrooge::Tracker::Base::NotImplemented )
23
- end
24
-
25
- it "should be able to restore itself from a serializeable representation" do
26
- lambda{ @base.marshal_load( '' ) }.should raise_error( Scrooge::Tracker::Base::NotImplemented )
27
- end
28
-
29
- end
@@ -1,79 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe Scrooge::Tracker::Model do
4
-
5
- before(:each) do
6
- @model = Scrooge::Tracker::Model.new( 'Post' )
7
- @model.stub!(:name).and_return( 'Product' )
8
- @model.stub!(:table_name).and_return( 'products' )
9
- @model.stub!(:primary_key).and_return( 'id' )
10
- @other_model = Scrooge::Tracker::Model.new( 'OtherPost' )
11
- @another_model = Scrooge::Tracker::Model.new( 'AnotherPost' )
12
- @resource = Scrooge::Tracker::Resource.new do |resource|
13
- resource.controller = 'products'
14
- resource.action = 'show'
15
- resource.method = :get
16
- resource.format = :html
17
- resource.is_public = true
18
- end
19
- end
20
-
21
- it "should be able to determine if any attributes has been tracked" do
22
- @model.any?().should equal( false )
23
- end
24
-
25
- it "should initialize with an empty set of attributes" do
26
- @model.attributes.should eql( Set.new )
27
- end
28
-
29
- it "should be able to accept attributes" do
30
- lambda { @model << :name }.should change( @model.attributes, :size ).from(0).to(1)
31
- end
32
-
33
- it "should be able to dump itself to a serializeable representation" do
34
- @model << [:name, :description, :price]
35
- @model.marshal_dump().should eql( { "Product" => [:price, :description, :name] } )
36
- end
37
-
38
- it "should be able to restore itself from a serialized representation" do
39
- @model << [:name, :description, :price]
40
- @model.marshal_load( { "Product" => [:price] } )
41
- @model.attributes.size.should eql( 1 )
42
- end
43
-
44
- it "should be able to render a attribute selection SQL snippet from it's referenced attributes" do
45
- @model << [:name, :description, :price]
46
- @model.to_sql().should eql( "products.id, products.price, products.description, products.name" )
47
- end
48
-
49
- it "should be able to compare itself to other model trackers" do
50
- @model << [:name, :description, :price]
51
- @model.should eql( @model )
52
- end
53
-
54
- it "should implemented a custom Object#inspect" do
55
- @model << [:name, :description]
56
- @model.inspect().should match( /Product/ )
57
- @model.inspect().should match( /:name/ )
58
- end
59
-
60
- it "should be able to merge itself with another model tracker" do
61
- @other_model << %w(name description)
62
- @model.merge( @other_model )
63
- @model.attributes.to_a.sort.should eql( %w(description name) )
64
- @another_model.merge( @model )
65
- @another_model.attributes.to_a.sort.should eql( %w(description name) )
66
- @another_model.attributes.should_not_receive(:merge)
67
- @another_model.merge( nil )
68
- end
69
-
70
- it "should be able to setup Rack middleware" do
71
- @model << %w(name description)
72
- @model.middleware( @resource ).class.should equal( Class )
73
- @model.middleware( @resource ).inspect.should match( /Middleware/ )
74
- @model.middleware( @resource ).inspect.should match( /Product/ )
75
- @model.middleware( @resource ).inspect.should match( /description/ )
76
- @model.middleware( @resource ).new( @model ).should respond_to( :call )
77
- end
78
-
79
- end
@@ -1,115 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe Scrooge::Tracker::Resource do
4
-
5
- before(:each) do
6
- @resource = Scrooge::Tracker::Resource.new do |resource|
7
- resource.controller = 'products'
8
- resource.action = 'show'
9
- resource.method = :get
10
- resource.format = :html
11
- resource.is_public = true
12
- end
13
- @model = Scrooge::Tracker::Model.new( 'Class' )
14
- @model.stub!(:name).and_return( 'Product' )
15
- @model.stub!(:table_name).and_return( 'products' )
16
- @model.stub!(:primary_key).and_return( 'id' )
17
- @other_resource = Scrooge::Tracker::Resource.new do |resource|
18
- resource.controller = 'categories'
19
- resource.action = 'show'
20
- resource.method = :get
21
- resource.format = :html
22
- resource.is_public = true
23
- end
24
- end
25
-
26
- it "should be able to determine if any models has been tracked" do
27
- @resource.any?().should equal( false )
28
- end
29
-
30
- it "should be able to determine if it's a public resource" do
31
- @resource.public?().should equal( true )
32
- end
33
-
34
- it "should be able to determine if it's a private resource" do
35
- @resource.private?().should equal( false )
36
- end
37
-
38
- it "should initialize with an empty set of models" do
39
- @resource.models.should eql( Set.new )
40
- end
41
-
42
- it "should be able to accept models" do
43
- lambda { @resource << @model }.should change( @resource.models, :size ).from(0).to(1)
44
- end
45
-
46
- it "should be able to wrap model objects" do
47
- @resource << 'Model'
48
- @resource.models.all?{|m| m.is_a?( Scrooge::Tracker::Model ) }.should equal( true )
49
- end
50
-
51
- it "should be able to log an attribute access for a given model" do
52
- @resource << ['Post', :title]
53
- @resource.models.first.attributes.should eql( Set[:title] )
54
- end
55
-
56
- it "should be able to determine if it's trackable" do
57
- @resource.trackable?().should equal( true )
58
- @resource.stub!(:method).and_return( :put )
59
- @resource.trackable?().should equal( false )
60
- end
61
-
62
- it "should be able to generate a lookup signature" do
63
- @resource.signature().should eql( "products_show_get_public" )
64
- end
65
-
66
- it "should be able to dump itself to a serializeable representation" do
67
- @resource.marshal_dump().should eql( { "products_show_get_public" => { :models => [],
68
- :method => :get,
69
- :format => :html,
70
- :action => "show",
71
- :controller => "products",
72
- :is_public => true} } )
73
- end
74
-
75
- it "should be able to restore itself from a serialized representation" do
76
- Marshal.load( Marshal.dump( @resource ) ).should eql( @resource )
77
- end
78
-
79
- it "should be able to compare itself to other resource trackers" do
80
- @resource.should eql( @resource )
81
- end
82
-
83
- it "should be able to setup Rack middleware" do
84
- @resource.profile.orm.stub!(:resource_scope_method).and_return(:scoped_to_resource_method)
85
- @resource << @model
86
- @resource.middleware().class.should equal( Array )
87
- @resource.middleware().first.class.should equal( Class )
88
- @resource.middleware().first.inspect.should match( /Middleware/ )
89
- @resource.middleware().first.inspect.should match( /Product/ )
90
- @resource.middleware().first.new( @model ).should respond_to( :call )
91
- end
92
-
93
- it "should implemented a custom Object#inspect" do
94
- @resource << @model
95
- @resource.inspect().should match( /GET/ )
96
- @resource.inspect().should match( /products/ )
97
- @resource.inspect().should match( /Product/ )
98
- end
99
-
100
- it "should be able to find a given model" do
101
- @resource << @model
102
- other_model = mock('model')
103
- other_model.stub!(:name).and_return('Product')
104
- @resource.model( other_model ).should == @model
105
- end
106
-
107
- it "should be able to merge itself with another resource" do
108
- @other_resource << @model
109
- @resource.merge( @other_resource )
110
- @resource.models.to_a.should eql( [@model] )
111
- @resource.models.should_not_receive(:merge)
112
- @resource.merge( nil )
113
- end
114
-
115
- end
@@ -1,13 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe Scrooge::Base do
4
-
5
- before(:each) do
6
- @base = Scrooge::Base
7
- end
8
-
9
- it "should be able to instantiate it's profile" do
10
- @base.profile.class.should == Scrooge::Profile
11
- end
12
-
13
- end
data/tasks/scrooge.rake DELETED
@@ -1,43 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__) + '/../lib')
2
-
3
- require 'scrooge'
4
-
5
- Scrooge::Framework::Rails
6
-
7
- namespace :scrooge do
8
-
9
- desc "Copies over the example scrooge.yml file to the host framework's configuration directory"
10
- task :setup do
11
- Scrooge::Base.setup!
12
- end
13
-
14
- desc "List all available Scrooge scopes"
15
- task :list do
16
- any_scopes do
17
- Scrooge::Profile.framework.scopes.each do |scope|
18
- puts "- #{scope}"
19
- end
20
- end
21
- end
22
-
23
- desc "Dumps Resources and Models for a given scope to a human friendly format.Assumes ENV['scope'] is set."
24
- task :inspect do
25
- any_scopes do
26
- begin
27
- Scrooge::Base.profile.scope = ENV['scope']
28
- puts Scrooge::Base.profile.tracker.inspect
29
- rescue Scrooge::Framework::Base::InvalidScopeSignature
30
- puts "Please set ENV['scope'] to the scope you'd like to inspect."
31
- end
32
- end
33
- end
34
-
35
- def any_scopes
36
- if Scrooge::Profile.framework.scopes?
37
- yield
38
- else
39
- puts "There's no existing Scrooge scopes!"
40
- end
41
- end
42
-
43
- end