motr 0.0.7 → 0.0.8
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.
- data/Rakefile +17 -17
- data/lib/motr.rb +30 -7
- data/lib/motr/defaults.rb +1 -0
- data/lib/motr/mods.rb +4 -4
- data/lib/motr/mods/scopeable.rb +27 -0
- data/lib/motr/orm/active_record.rb +3 -0
- data/lib/motr/orm/mongoid.rb +5 -0
- data/lib/motr/rails.rb +2 -0
- data/lib/motr/version.rb +1 -1
- metadata +4 -5
- data/lib/motr/mapper.rb +0 -14
- data/lib/motr/rails/routes.rb +0 -11
data/Rakefile
CHANGED
@@ -16,23 +16,23 @@ require 'rspec/core/rake_task'
|
|
16
16
|
require 'rake/testtask'
|
17
17
|
|
18
18
|
RSpec::Core::RakeTask.new(:spec)
|
19
|
-
|
20
|
-
task :default => :spec
|
21
|
-
|
22
|
-
Rake::TestTask.new(:test) do |t|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
19
|
+
#
|
20
|
+
# #task :default => :spec
|
21
|
+
#
|
22
|
+
# Rake::TestTask.new(:test) do |t|
|
23
|
+
# t.libs << 'lib'
|
24
|
+
# t.libs << 'test'
|
25
|
+
# t.pattern = 'test/**/*_test.rb'
|
26
|
+
# t.verbose = false
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# Rake::RDocTask.new(:rdoc) do |rdoc|
|
30
|
+
# rdoc.rdoc_dir = 'rdoc'
|
31
|
+
# rdoc.title = 'motr'
|
32
|
+
# rdoc.options << '--line-numbers' << '--inline-source'
|
33
|
+
# rdoc.rdoc_files.include('README.rdoc')
|
34
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
35
|
+
# end
|
36
36
|
|
37
37
|
|
38
38
|
|
data/lib/motr.rb
CHANGED
@@ -24,6 +24,9 @@ module Motr
|
|
24
24
|
autoload :ModuleMissing, 'motr/errors/module_missing'
|
25
25
|
end
|
26
26
|
|
27
|
+
# @private
|
28
|
+
mattr_accessor :applied_mods
|
29
|
+
@@applied_mods = ActiveSupport::OrderedHash.new
|
27
30
|
|
28
31
|
##
|
29
32
|
#
|
@@ -33,23 +36,43 @@ module Motr
|
|
33
36
|
# @param [Hash] options Hash including options for the mod
|
34
37
|
#
|
35
38
|
# @option options [String, Boolean] :autoload The path to autoload the module from (optional)
|
36
|
-
# @option options [Hash, Boolean] :mapping Routing options for the mod
|
37
|
-
# if a Hash is provided, it should contain a :controller option, and an optional :route option
|
38
|
-
# Passing "true" assumes a controller matching :modnames_controller (the mod name, plural) and
|
39
|
-
# a route matching the same.
|
40
39
|
#
|
41
40
|
#
|
42
|
-
def self.add_mod(
|
41
|
+
def self.add_mod(mod_name, options = {})
|
42
|
+
|
43
|
+
const_name = ActiveSupport::Inflector.camelize(mod_name.to_s)
|
44
|
+
mod_name_pl = ActiveSupport::Inflector.pluralize(mod_name.to_s)
|
45
|
+
|
46
|
+
# Setup a tracking array
|
47
|
+
self.applied_mods[mod_name] ||= []
|
43
48
|
|
44
|
-
const_name = ActiveSupport::Inflector.camelize(module_name.to_s)
|
45
49
|
|
46
50
|
if autoload_path = options.delete(:autoload)
|
47
|
-
path = (autoload_path == true ? "motr/mods/#{
|
51
|
+
path = (autoload_path == true ? "motr/mods/#{mod_name.to_s}" : autoload_path)
|
48
52
|
Motr::Mods.send(:autoload, const_name, path)
|
49
53
|
end
|
50
54
|
|
51
55
|
end
|
52
56
|
|
57
|
+
##
|
58
|
+
# Tracks which models have been modded by any given mod, providing
|
59
|
+
# an easy way to do lookups.
|
60
|
+
#
|
61
|
+
# @since 0.0.8
|
62
|
+
def self.track_mod(mod_name, ref)
|
63
|
+
self.applied_mods[mod_name.to_sym] |= [ ActiveSupport::Inflector.camelize(ref.to_s) ]
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# Apply helpers from mods at load time.
|
68
|
+
#
|
69
|
+
# @since 0.0.8
|
70
|
+
def self.apply_helpers(helper_name)
|
71
|
+
ActiveSupport.on_load(:action_controller) do
|
72
|
+
include helper_name
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
53
76
|
# Support initializer configuration
|
54
77
|
# @private
|
55
78
|
#
|
data/lib/motr/defaults.rb
CHANGED
data/lib/motr/mods.rb
CHANGED
@@ -15,14 +15,13 @@ module Motr
|
|
15
15
|
#
|
16
16
|
#
|
17
17
|
def modded_with(*mods)
|
18
|
-
|
19
|
-
|
20
|
-
self.motr_mods ||= []
|
18
|
+
|
19
|
+
include Motr::Mods::Scopeable
|
21
20
|
|
22
21
|
options = mods.extract_options!
|
23
22
|
modules = mods.map(&:to_sym).uniq
|
24
23
|
|
25
|
-
modules.each do |mod|
|
24
|
+
modules.each do |mod|
|
26
25
|
const_name = mod.to_s.classify
|
27
26
|
next unless Motr::Mods.const_defined?(:"#{const_name}")
|
28
27
|
|
@@ -54,6 +53,7 @@ module Motr
|
|
54
53
|
end
|
55
54
|
|
56
55
|
include const_incl
|
56
|
+
Motr.track_mod(mod, self.name.to_s)
|
57
57
|
|
58
58
|
end
|
59
59
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Motr
|
2
|
+
module Mods
|
3
|
+
##
|
4
|
+
# Scopeable is simply a base mod for setting up model "scoping".
|
5
|
+
# This allows for helpers, routes, and other things to operate on particular
|
6
|
+
# model "scopes" where mods may exist on multiple different models.
|
7
|
+
#
|
8
|
+
module Scopeable
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
class_attribute :motr_mods, :instance_writer => false
|
13
|
+
self.motr_mods ||= []
|
14
|
+
end
|
15
|
+
|
16
|
+
def motr_scope_name
|
17
|
+
self.class.name.underscore
|
18
|
+
end
|
19
|
+
|
20
|
+
def motr_scope_id
|
21
|
+
self.id
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/motr/orm/mongoid.rb
CHANGED
data/lib/motr/rails.rb
CHANGED
@@ -6,6 +6,8 @@ module Motr
|
|
6
6
|
require 'active_support/i18n'
|
7
7
|
I18n.load_path << File.expand_path('../../config/locales/en.yml', __FILE__)
|
8
8
|
|
9
|
+
config.before_eager_load { |app| app.reload_routes! }
|
10
|
+
|
9
11
|
initializer 'motr.initializer' do
|
10
12
|
require 'motr/orm/mongoid' if defined?(Mongoid)
|
11
13
|
require 'motr/forms'
|
data/lib/motr/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: motr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Brent Kirby
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-24 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -137,13 +137,12 @@ files:
|
|
137
137
|
- lib/motr/helpers/elements.rb
|
138
138
|
- lib/motr/helpers/layout_helpers.rb
|
139
139
|
- lib/motr/helpers/navigation.rb
|
140
|
-
- lib/motr/mapper.rb
|
141
140
|
- lib/motr/modding.rb
|
141
|
+
- lib/motr/mods/scopeable.rb
|
142
142
|
- lib/motr/mods/sluggable.rb
|
143
143
|
- lib/motr/mods.rb
|
144
144
|
- lib/motr/orm/active_record.rb
|
145
145
|
- lib/motr/orm/mongoid.rb
|
146
|
-
- lib/motr/rails/routes.rb
|
147
146
|
- lib/motr/rails.rb
|
148
147
|
- lib/motr/version.rb
|
149
148
|
- lib/motr.rb
|
@@ -166,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
166
165
|
requirements:
|
167
166
|
- - ">="
|
168
167
|
- !ruby/object:Gem::Version
|
169
|
-
hash: -
|
168
|
+
hash: -3091450084673038537
|
170
169
|
segments:
|
171
170
|
- 0
|
172
171
|
version: "0"
|
data/lib/motr/mapper.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
module Motr
|
2
|
-
##
|
3
|
-
# Mapper handles configuring mod based routes within an application
|
4
|
-
#
|
5
|
-
class Mapper
|
6
|
-
class_attribute :map_options, :instance_writer => false
|
7
|
-
self.map_options = {}
|
8
|
-
|
9
|
-
def self.add_mapping(mod_name, options)
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|