contextualize 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +186 -0
- data/VERSION +1 -1
- data/contextualize.gemspec +68 -0
- data/lib/contextualize.rb +14 -4
- data/lib/contextualize/core_ext.rb +10 -0
- data/lib/contextualize/decent_exposure.rb +20 -0
- data/spec/contextualize_spec.rb +39 -21
- metadata +70 -108
- data/README.rdoc +0 -73
data/README.textile
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
h1. contextualize
|
2
|
+
|
3
|
+
Adds the ability to add and remove specific modules to an object depending on the current context
|
4
|
+
This can fx be used for Models in a _MVC_ pattern, where the model could have different behavior
|
5
|
+
depending on the context it operates in, fx if is currently accessed in a _View_ or a _Controller_, or
|
6
|
+
even depending on the scope (fx Admin) etc. This way, a lot of the typical scenarios for helper methods
|
7
|
+
can be avoided, and instead you simply create scope folders for the model, typically one for view and
|
8
|
+
possibly one for controller.
|
9
|
+
|
10
|
+
"Decorator Pattern with Mixology":http://ruby.simapse.com/2008/08/test.html
|
11
|
+
|
12
|
+
In a Rails project, you should use the following structure
|
13
|
+
|
14
|
+
<pre>
|
15
|
+
+ app
|
16
|
+
+ contexts
|
17
|
+
project_view.rb
|
18
|
+
project_control.rb
|
19
|
+
+ admin
|
20
|
+
project_view.rb
|
21
|
+
|
22
|
+
+ models
|
23
|
+
project.rb
|
24
|
+
</pre>
|
25
|
+
|
26
|
+
Define each context specific module
|
27
|
+
|
28
|
+
<pre>
|
29
|
+
module ProjectView
|
30
|
+
# display the best project
|
31
|
+
def show_best
|
32
|
+
# calls method :best
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
module ProjectControl
|
37
|
+
# select the best project
|
38
|
+
def best
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module Admin
|
43
|
+
module ProjectControl
|
44
|
+
# admin specific logic to select the best project!
|
45
|
+
def best
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
</pre>
|
50
|
+
|
51
|
+
Then bind these modules to one or more contexts
|
52
|
+
|
53
|
+
<pre>
|
54
|
+
class Project
|
55
|
+
contextualize
|
56
|
+
icontexts :view, :control # using naming conventions
|
57
|
+
icontext :admin, Admin::ProjectControl
|
58
|
+
end
|
59
|
+
</pre>
|
60
|
+
|
61
|
+
Now you can operate on the object according to the context you are in
|
62
|
+
|
63
|
+
<pre>
|
64
|
+
project = Project.new
|
65
|
+
|
66
|
+
# add :view context
|
67
|
+
project.add_icontext :view
|
68
|
+
project.add_icontexts :view, :control
|
69
|
+
|
70
|
+
# use the view context methods now available
|
71
|
+
project.own_methods.should include('view')
|
72
|
+
project.view.should == "view"
|
73
|
+
|
74
|
+
# remove the :view context
|
75
|
+
project.remove_icontext :view
|
76
|
+
project.remove_icontexts :view, :control
|
77
|
+
|
78
|
+
|
79
|
+
# the methods of the view context are no longer available!
|
80
|
+
lambda {project.view}.should raise_error
|
81
|
+
|
82
|
+
# operate on object within one or more contexts
|
83
|
+
project.icontext_scope :view do |project|
|
84
|
+
project.view.should == "view"
|
85
|
+
end
|
86
|
+
|
87
|
+
# contexts are automatically removed from object when block terminates
|
88
|
+
lambda {project.view}.should raise_error
|
89
|
+
|
90
|
+
project.icontext_scope :view, :control do |project|
|
91
|
+
# ...
|
92
|
+
end
|
93
|
+
</pre>
|
94
|
+
|
95
|
+
h2. Usage in Rails
|
96
|
+
|
97
|
+
<pre>
|
98
|
+
class ProjectsController < ApplicationController
|
99
|
+
# "simulated" exposure
|
100
|
+
def project
|
101
|
+
@project ||= begin
|
102
|
+
p = params[:id] ? Project.find(params[:id]) : Project.new(params[:project])
|
103
|
+
p.add_icontext :view
|
104
|
+
end
|
105
|
+
end
|
106
|
+
helper_method project
|
107
|
+
hide_action project
|
108
|
+
|
109
|
+
def projects
|
110
|
+
@projects ||= Project.all.add_icontext :view
|
111
|
+
end
|
112
|
+
helper_method projects
|
113
|
+
hide_action projects
|
114
|
+
|
115
|
+
def index
|
116
|
+
end
|
117
|
+
|
118
|
+
def show
|
119
|
+
end
|
120
|
+
|
121
|
+
...
|
122
|
+
end
|
123
|
+
</pre>
|
124
|
+
|
125
|
+
h2. Using decent_exposure integration
|
126
|
+
|
127
|
+
Contextualize monkey-patches the _#expose_ method of the _decent_exposure_ gem to add the icontext :view to each model (if present)
|
128
|
+
|
129
|
+
<pre>
|
130
|
+
class ProjectsController < ApplicationController
|
131
|
+
expose(:projects) { Project.all }
|
132
|
+
expose(:project)
|
133
|
+
|
134
|
+
def index
|
135
|
+
end
|
136
|
+
|
137
|
+
def show
|
138
|
+
end
|
139
|
+
|
140
|
+
def new
|
141
|
+
end
|
142
|
+
|
143
|
+
def edit
|
144
|
+
end
|
145
|
+
|
146
|
+
def create
|
147
|
+
if project.save
|
148
|
+
redirect_to project, notice: 'Project was successfully created.'
|
149
|
+
else
|
150
|
+
render action: "new"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def update
|
155
|
+
if project.update_attributes(params[:project])
|
156
|
+
redirect_to project, notice: 'Project was successfully updated.'
|
157
|
+
else
|
158
|
+
render action: "edit"
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def destroy
|
163
|
+
project.destroy
|
164
|
+
redirect_to projects_url
|
165
|
+
end
|
166
|
+
end
|
167
|
+
</pre>
|
168
|
+
|
169
|
+
|
170
|
+
Enjoy!
|
171
|
+
|
172
|
+
h2. Contributing to contextualize
|
173
|
+
|
174
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
175
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
176
|
+
* Fork the project
|
177
|
+
* Start a feature/bugfix branch
|
178
|
+
* Commit and push until you are happy with your contribution
|
179
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
180
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
181
|
+
|
182
|
+
== Copyright
|
183
|
+
|
184
|
+
Copyright (c) 2011 Kristian Mandrup. See LICENSE.txt for
|
185
|
+
further details.
|
186
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{contextualize}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{Kristian Mandrup}]
|
12
|
+
s.date = %q{2011-07-05}
|
13
|
+
s.description = %q{Add and remove behaviors defined in modules depending on context an object operates in}
|
14
|
+
s.email = %q{kmandrup@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.textile"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.textile",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"contextualize.gemspec",
|
29
|
+
"lib/contextualize.rb",
|
30
|
+
"lib/contextualize/core_ext.rb",
|
31
|
+
"lib/contextualize/decent_exposure.rb",
|
32
|
+
"spec/contextualize_spec.rb",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/kristianmandrup/contextualize}
|
36
|
+
s.licenses = [%q{MIT}]
|
37
|
+
s.require_paths = [%q{lib}]
|
38
|
+
s.rubygems_version = %q{1.8.5}
|
39
|
+
s.summary = %q{Contextual behaviors for objects for use with Rails models and many other scenarios}
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<mixology>, ["~> 0.2.0"])
|
46
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.1"])
|
47
|
+
s.add_development_dependency(%q<rspec>, [">= 2.3.0"])
|
48
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.1"])
|
49
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.3"])
|
50
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<mixology>, ["~> 0.2.0"])
|
53
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.1"])
|
54
|
+
s.add_dependency(%q<rspec>, [">= 2.3.0"])
|
55
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.1"])
|
56
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.3"])
|
57
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<mixology>, ["~> 0.2.0"])
|
61
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.1"])
|
62
|
+
s.add_dependency(%q<rspec>, [">= 2.3.0"])
|
63
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.1"])
|
64
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.3"])
|
65
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/lib/contextualize.rb
CHANGED
@@ -1,15 +1,20 @@
|
|
1
1
|
require 'mixology'
|
2
2
|
require 'active_support/inflector'
|
3
3
|
require 'contextualize/core_ext'
|
4
|
+
require 'contextualize/decent_exposure'
|
4
5
|
|
5
6
|
module Contextualize
|
6
|
-
|
7
7
|
module ClassMethods
|
8
8
|
attr_reader :icontext_map
|
9
9
|
|
10
10
|
def icontext name, *constants
|
11
11
|
@icontext_map ||= {}
|
12
|
-
|
12
|
+
context_modules = if constants.flatten.empty?
|
13
|
+
const_by_convention(name)
|
14
|
+
else
|
15
|
+
select_modules constants
|
16
|
+
end
|
17
|
+
@icontext_map[name.to_sym] = context_modules
|
13
18
|
end
|
14
19
|
|
15
20
|
def icontexts *names
|
@@ -22,7 +27,7 @@ module Contextualize
|
|
22
27
|
|
23
28
|
def const_by_convention name
|
24
29
|
cls_name = self.name.demodulize
|
25
|
-
const_name = "
|
30
|
+
const_name = "#{cls_name}#{name.to_s.camelize}"
|
26
31
|
const_name.constantize
|
27
32
|
end
|
28
33
|
|
@@ -41,16 +46,19 @@ module Contextualize
|
|
41
46
|
|
42
47
|
def add_icontexts *names
|
43
48
|
names.each {|name| add_icontext(name) }
|
49
|
+
self
|
44
50
|
end
|
45
51
|
|
46
52
|
def remove_icontexts *names
|
47
53
|
names.each {|name| remove_icontext(name) }
|
54
|
+
self
|
48
55
|
end
|
49
56
|
|
50
57
|
def add_icontext name
|
51
58
|
icontext(name).each do |const|
|
52
59
|
self.send :mixin, const
|
53
60
|
end
|
61
|
+
self
|
54
62
|
end
|
55
63
|
|
56
64
|
def remove_icontext name
|
@@ -58,11 +66,13 @@ module Contextualize
|
|
58
66
|
icontext(name).each do |const|
|
59
67
|
self.send :unmix, const
|
60
68
|
end
|
69
|
+
self
|
61
70
|
end
|
62
71
|
|
63
72
|
protected
|
64
73
|
|
65
74
|
def icontext name
|
66
|
-
icontext_map[name.to_sym] || []
|
75
|
+
mods = icontext_map[name.to_sym] || []
|
76
|
+
[mods].flatten
|
67
77
|
end
|
68
78
|
end
|
@@ -10,6 +10,16 @@ class Object
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
class Array
|
14
|
+
def add_icontext name
|
15
|
+
self.each {|item| item.add_icontext name }
|
16
|
+
end
|
17
|
+
|
18
|
+
def remove_icontext name
|
19
|
+
self.each {|item| item.remove_icontext name }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
13
23
|
class Module
|
14
24
|
def contextualize
|
15
25
|
self.send :include, Contextualize
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module DecentExposure
|
2
|
+
def expose(name, &block)
|
3
|
+
closured_exposure = default_exposure
|
4
|
+
define_method name do
|
5
|
+
@_resources ||= {}
|
6
|
+
@_resources[name] ||= if block_given?
|
7
|
+
instance_eval(&block)
|
8
|
+
else
|
9
|
+
instance_exec(name, &closured_exposure)
|
10
|
+
end
|
11
|
+
puts "expose contextualize"
|
12
|
+
@_resources[name].add_icontext :view
|
13
|
+
end
|
14
|
+
helper_method name
|
15
|
+
hide_action name
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :view_expose, :expose
|
19
|
+
end
|
20
|
+
|
data/spec/contextualize_spec.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module ProjectViewer
|
4
4
|
def view
|
5
5
|
"view"
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
module
|
10
|
-
|
11
|
-
|
9
|
+
module Admin
|
10
|
+
module ProjectDetailedView
|
11
|
+
def detailed_view
|
12
|
+
"detailed_view"
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
@@ -19,32 +21,31 @@ module ProjectControl
|
|
19
21
|
end
|
20
22
|
|
21
23
|
|
22
|
-
|
23
24
|
class Project
|
24
25
|
contextualize
|
25
26
|
|
26
|
-
icontext :view,
|
27
|
+
icontext :view, ProjectViewer, Admin::ProjectDetailedView
|
27
28
|
icontext :control, ProjectControl
|
28
29
|
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
31
|
+
|
32
|
+
module EventView
|
33
|
+
def view
|
34
|
+
"view"
|
35
35
|
end
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
38
|
+
module EventControl
|
39
|
+
def control
|
40
|
+
"control"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
|
44
45
|
class Event
|
45
46
|
contextualize
|
46
|
-
|
47
|
-
icontexts :view
|
47
|
+
icontext :control
|
48
|
+
icontexts :view
|
48
49
|
end
|
49
50
|
|
50
51
|
describe "Contextualize" do
|
@@ -52,9 +53,14 @@ describe "Contextualize" do
|
|
52
53
|
Project.new
|
53
54
|
end
|
54
55
|
|
56
|
+
it "gracefully handles adding an invalid context to an object without raising error" do
|
57
|
+
lambda {project.add_icontext :blip}.should_not raise_error
|
58
|
+
lambda {project.remove_icontext :blip}.should_not raise_error
|
59
|
+
end
|
60
|
+
|
55
61
|
it "can add a context to an object" do
|
56
62
|
project.add_icontext :view
|
57
|
-
project.own_methods.should include(
|
63
|
+
project.own_methods.should include(:view)
|
58
64
|
|
59
65
|
project.view.should == "view"
|
60
66
|
project.detailed_view.should == "detailed_view"
|
@@ -62,7 +68,7 @@ describe "Contextualize" do
|
|
62
68
|
|
63
69
|
it "can remove a context from an object" do
|
64
70
|
project.add_icontext :view
|
65
|
-
project.own_methods.should include(
|
71
|
+
project.own_methods.should include(:view)
|
66
72
|
|
67
73
|
project.remove_icontext :view
|
68
74
|
lambda {project.view}.should raise_error
|
@@ -78,6 +84,16 @@ describe "Contextualize" do
|
|
78
84
|
lambda {project.control}.should raise_error
|
79
85
|
end
|
80
86
|
|
87
|
+
describe 'Array extension' do
|
88
|
+
let (:events) do
|
89
|
+
[Event.new, Event.new].add_icontext :view
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should work on an Array instance' do
|
93
|
+
events.first.own_methods.should include(:view)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
81
97
|
describe 'naming conventions' do
|
82
98
|
let (:event) do
|
83
99
|
Event.new
|
@@ -85,9 +101,11 @@ describe "Contextualize" do
|
|
85
101
|
|
86
102
|
it 'should apply naming conventions' do
|
87
103
|
event.add_icontext :view
|
88
|
-
event.own_methods.should include(
|
89
|
-
|
104
|
+
event.own_methods.should include(:view)
|
90
105
|
event.view.should == "view"
|
106
|
+
|
107
|
+
event.add_icontext :control
|
108
|
+
event.own_methods.should include(:control)
|
91
109
|
end
|
92
110
|
end
|
93
111
|
end
|
metadata
CHANGED
@@ -1,170 +1,132 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: contextualize
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Kristian Mandrup
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
requirement: &
|
12
|
+
date: 2011-07-05 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mixology
|
16
|
+
requirement: &2154964500 !ruby/object:Gem::Requirement
|
22
17
|
none: false
|
23
|
-
requirements:
|
18
|
+
requirements:
|
24
19
|
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
hash: 23
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
- 2
|
30
|
-
- 0
|
20
|
+
- !ruby/object:Gem::Version
|
31
21
|
version: 0.2.0
|
32
|
-
version_requirements: *id001
|
33
22
|
type: :runtime
|
34
|
-
name: mixology
|
35
23
|
prerelease: false
|
36
|
-
|
37
|
-
|
24
|
+
version_requirements: *2154964500
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activesupport
|
27
|
+
requirement: &2154964020 !ruby/object:Gem::Requirement
|
38
28
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
hash: 5
|
43
|
-
segments:
|
44
|
-
- 3
|
45
|
-
- 0
|
46
|
-
- 1
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
47
32
|
version: 3.0.1
|
48
|
-
version_requirements: *id002
|
49
33
|
type: :runtime
|
50
|
-
name: activesupport
|
51
34
|
prerelease: false
|
52
|
-
|
53
|
-
|
35
|
+
version_requirements: *2154964020
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &2154980680 !ruby/object:Gem::Requirement
|
54
39
|
none: false
|
55
|
-
requirements:
|
56
|
-
- -
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
hash: 3
|
59
|
-
segments:
|
60
|
-
- 2
|
61
|
-
- 3
|
62
|
-
- 0
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
63
43
|
version: 2.3.0
|
64
|
-
version_requirements: *id003
|
65
44
|
type: :development
|
66
|
-
name: rspec
|
67
45
|
prerelease: false
|
68
|
-
|
69
|
-
|
46
|
+
version_requirements: *2154980680
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: &2154980200 !ruby/object:Gem::Requirement
|
70
50
|
none: false
|
71
|
-
requirements:
|
51
|
+
requirements:
|
72
52
|
- - ~>
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
hash: 21
|
75
|
-
segments:
|
76
|
-
- 1
|
77
|
-
- 0
|
78
|
-
- 1
|
53
|
+
- !ruby/object:Gem::Version
|
79
54
|
version: 1.0.1
|
80
|
-
version_requirements: *id004
|
81
55
|
type: :development
|
82
|
-
name: bundler
|
83
56
|
prerelease: false
|
84
|
-
|
85
|
-
|
57
|
+
version_requirements: *2154980200
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: jeweler
|
60
|
+
requirement: &2154979720 !ruby/object:Gem::Requirement
|
86
61
|
none: false
|
87
|
-
requirements:
|
62
|
+
requirements:
|
88
63
|
- - ~>
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
hash: 9
|
91
|
-
segments:
|
92
|
-
- 1
|
93
|
-
- 6
|
94
|
-
- 3
|
64
|
+
- !ruby/object:Gem::Version
|
95
65
|
version: 1.6.3
|
96
|
-
version_requirements: *id005
|
97
66
|
type: :development
|
98
|
-
name: jeweler
|
99
67
|
prerelease: false
|
100
|
-
|
101
|
-
|
68
|
+
version_requirements: *2154979720
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rcov
|
71
|
+
requirement: &2154979240 !ruby/object:Gem::Requirement
|
102
72
|
none: false
|
103
|
-
requirements:
|
104
|
-
- -
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
|
107
|
-
segments:
|
108
|
-
- 0
|
109
|
-
version: "0"
|
110
|
-
version_requirements: *id006
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
111
77
|
type: :development
|
112
|
-
name: rcov
|
113
78
|
prerelease: false
|
114
|
-
|
79
|
+
version_requirements: *2154979240
|
80
|
+
description: Add and remove behaviors defined in modules depending on context an object
|
81
|
+
operates in
|
115
82
|
email: kmandrup@gmail.com
|
116
83
|
executables: []
|
117
|
-
|
118
84
|
extensions: []
|
119
|
-
|
120
|
-
extra_rdoc_files:
|
85
|
+
extra_rdoc_files:
|
121
86
|
- LICENSE.txt
|
122
|
-
- README.
|
123
|
-
files:
|
87
|
+
- README.textile
|
88
|
+
files:
|
124
89
|
- .document
|
125
90
|
- .rspec
|
126
91
|
- Gemfile
|
127
92
|
- Gemfile.lock
|
128
93
|
- LICENSE.txt
|
129
|
-
- README.
|
94
|
+
- README.textile
|
130
95
|
- Rakefile
|
131
96
|
- VERSION
|
97
|
+
- contextualize.gemspec
|
132
98
|
- lib/contextualize.rb
|
133
99
|
- lib/contextualize/core_ext.rb
|
100
|
+
- lib/contextualize/decent_exposure.rb
|
134
101
|
- spec/contextualize_spec.rb
|
135
102
|
- spec/spec_helper.rb
|
136
103
|
homepage: http://github.com/kristianmandrup/contextualize
|
137
|
-
licenses:
|
104
|
+
licenses:
|
138
105
|
- MIT
|
139
106
|
post_install_message:
|
140
107
|
rdoc_options: []
|
141
|
-
|
142
|
-
require_paths:
|
108
|
+
require_paths:
|
143
109
|
- lib
|
144
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
111
|
none: false
|
146
|
-
requirements:
|
147
|
-
- -
|
148
|
-
- !ruby/object:Gem::Version
|
149
|
-
|
150
|
-
segments:
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
segments:
|
151
117
|
- 0
|
152
|
-
|
153
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
hash: -4138437113857599099
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
120
|
none: false
|
155
|
-
requirements:
|
156
|
-
- -
|
157
|
-
- !ruby/object:Gem::Version
|
158
|
-
|
159
|
-
segments:
|
160
|
-
- 0
|
161
|
-
version: "0"
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
162
125
|
requirements: []
|
163
|
-
|
164
126
|
rubyforge_project:
|
165
127
|
rubygems_version: 1.8.5
|
166
128
|
signing_key:
|
167
129
|
specification_version: 3
|
168
|
-
summary: Contextual behaviors for objects for use with Rails models and many other
|
130
|
+
summary: Contextual behaviors for objects for use with Rails models and many other
|
131
|
+
scenarios
|
169
132
|
test_files: []
|
170
|
-
|
data/README.rdoc
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
= contextualize
|
2
|
-
|
3
|
-
Adds the ability to add and remove specific modules to an object depending on the current context
|
4
|
-
This can fx be used for Models in a MVC pattern, where the model could have different behavior
|
5
|
-
depending on the context it operates in, fx if is currently accessed in a View or a Controller, or
|
6
|
-
even depending on the scope (fx Admin) etc. This way, a lot of the typical scenarios for helper methods
|
7
|
-
can be avoided, and instead you simply create scope folders for the model, typically one for view and
|
8
|
-
possibly one for controller
|
9
|
-
|
10
|
-
+ models
|
11
|
-
project
|
12
|
-
+ contextualize
|
13
|
-
project_view.rb
|
14
|
-
project_control.rb
|
15
|
-
+ admin
|
16
|
-
project_view.rb
|
17
|
-
|
18
|
-
module Contextualize::ProjectView
|
19
|
-
def full_name
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
module Contextualize::ProjectControl
|
24
|
-
def best
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
class Project
|
30
|
-
contextualize
|
31
|
-
icontexts :view, :control # using naming conventions
|
32
|
-
icontext :admin, Contextualize::Admin::ProjectView
|
33
|
-
end
|
34
|
-
|
35
|
-
project = Project.new
|
36
|
-
|
37
|
-
# add :view context
|
38
|
-
project.add_icontext :view
|
39
|
-
|
40
|
-
# use the view context methods now available
|
41
|
-
project.own_methods.should include('view')
|
42
|
-
project.view.should == "view"
|
43
|
-
|
44
|
-
# remove the :view context
|
45
|
-
project.remove_icontext :view
|
46
|
-
|
47
|
-
# the methods of the view context are no longer available!
|
48
|
-
lambda {project.view}.should raise_error
|
49
|
-
|
50
|
-
# operate on object within one or more contexts
|
51
|
-
project.icontext_scope :view do |project|
|
52
|
-
project.view.should == "view"
|
53
|
-
end
|
54
|
-
|
55
|
-
# contexts are automatically removed from object when block terminates
|
56
|
-
lambda {project.view}.should raise_error
|
57
|
-
|
58
|
-
|
59
|
-
== Contributing to contextualize
|
60
|
-
|
61
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
62
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
63
|
-
* Fork the project
|
64
|
-
* Start a feature/bugfix branch
|
65
|
-
* Commit and push until you are happy with your contribution
|
66
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
67
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
68
|
-
|
69
|
-
== Copyright
|
70
|
-
|
71
|
-
Copyright (c) 2011 Kristian Mandrup. See LICENSE.txt for
|
72
|
-
further details.
|
73
|
-
|