flowmor_router 0.2.1 → 0.2.2
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 +4 -4
- data/README.md +18 -5
- data/config/routes.rb +3 -3
- data/lib/flowmor_router/acts_as_routable.rb +3 -2
- data/lib/flowmor_router/version.rb +1 -1
- data/test/dummy/log/test.log +1827 -0
- metadata +1 -4
- data/app/models/routable_record.rb +0 -131
- data/lib/flowmor_router/foo.rb +0 -63
- data/lib/flowmor_router/proxy_foo.rb +0 -50
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flowmor_router
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Lang
|
@@ -52,15 +52,12 @@ files:
|
|
52
52
|
- Rakefile
|
53
53
|
- app/controllers/application_controller.rb
|
54
54
|
- app/controllers/static_controller.rb
|
55
|
-
- app/models/routable_record.rb
|
56
55
|
- bin/rails
|
57
56
|
- config/routes.rb
|
58
57
|
- lib/flowmor_router.rb
|
59
58
|
- lib/flowmor_router/acts_as_routable.rb
|
60
59
|
- lib/flowmor_router/engine.rb
|
61
60
|
- lib/flowmor_router/exceptions.rb
|
62
|
-
- lib/flowmor_router/foo.rb
|
63
|
-
- lib/flowmor_router/proxy_foo.rb
|
64
61
|
- lib/flowmor_router/router_classes.rb
|
65
62
|
- lib/flowmor_router/version.rb
|
66
63
|
- lib/tasks/flowmor_router_tasks.rake
|
@@ -1,131 +0,0 @@
|
|
1
|
-
class RoutableRecord < ActiveRecord::Base
|
2
|
-
self.abstract_class = true
|
3
|
-
|
4
|
-
scope :routable, -> {}
|
5
|
-
|
6
|
-
def self.route_model
|
7
|
-
name.underscore.downcase
|
8
|
-
end
|
9
|
-
|
10
|
-
def route_model
|
11
|
-
self.class.route_model
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.set_controller_action value
|
15
|
-
@controller_action = value
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.default_controller_action
|
19
|
-
"#{route_model.underscore}#show"
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.controller_action
|
23
|
-
@controller_action || default_controller_action
|
24
|
-
end
|
25
|
-
|
26
|
-
def controller_action
|
27
|
-
self.class.controller_action
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.set_derived_name_field value
|
31
|
-
@derived_name_field = value
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.derived_name_field
|
35
|
-
@derived_name_field || 'title'
|
36
|
-
end
|
37
|
-
|
38
|
-
def derived_name_field
|
39
|
-
self.class.derived_name_field
|
40
|
-
end
|
41
|
-
|
42
|
-
def derived_name_field_value
|
43
|
-
if respond_to? derived_name_field
|
44
|
-
send(derived_name_field)
|
45
|
-
else
|
46
|
-
raise RuntimeError
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.set_name_field value
|
51
|
-
@name_field = value
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.name_field
|
55
|
-
@name_field || 'name'
|
56
|
-
end
|
57
|
-
|
58
|
-
def name_field
|
59
|
-
self.class.name_field
|
60
|
-
end
|
61
|
-
|
62
|
-
def name_field_value
|
63
|
-
attributes[name_field]
|
64
|
-
end
|
65
|
-
|
66
|
-
include Rails.application.routes.url_helpers
|
67
|
-
|
68
|
-
after_save :reload_routes
|
69
|
-
before_save :populate_name
|
70
|
-
|
71
|
-
def route_name_prefix
|
72
|
-
"#{route_model.pluralize}"
|
73
|
-
end
|
74
|
-
|
75
|
-
def route_name
|
76
|
-
name_suffix = new_name_value
|
77
|
-
raise UnroutableRecord if name_suffix.blank?
|
78
|
-
|
79
|
-
"#{route_name_prefix}_#{name_suffix}".underscore
|
80
|
-
end
|
81
|
-
|
82
|
-
def route_prefix
|
83
|
-
"/#{route_model.pluralize.gsub('_', '-')}"
|
84
|
-
end
|
85
|
-
|
86
|
-
def route
|
87
|
-
"#{route_prefix}/#{new_name_value}"
|
88
|
-
end
|
89
|
-
|
90
|
-
def default_url_options
|
91
|
-
{ :host => Thread.current[:host], :port => Thread.current[:port] }
|
92
|
-
end
|
93
|
-
|
94
|
-
def url
|
95
|
-
begin
|
96
|
-
send("#{route_name}_url", default_url_options)
|
97
|
-
rescue NoMethodError
|
98
|
-
raise FlowmorRouter::UnroutedRecord.new("#{self.inspect} was not routed.")
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def path
|
103
|
-
begin
|
104
|
-
send("#{route_name}_path")
|
105
|
-
rescue NoMethodError
|
106
|
-
raise FlowmorRouter::UnroutedRecord.new("#{self.inspect} was not routed.")
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def new_name_value
|
111
|
-
if value = derived_name_field_value and !value.blank?
|
112
|
-
value.downcase.gsub(/[^\w\s\d\_\-]/,'').gsub(/\s\s+/,' ').gsub(/[^\w\d]/, '-')
|
113
|
-
else
|
114
|
-
raise FlowmorRouter::UnroutableRecord if value.blank?
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def name_field_changed?
|
119
|
-
new_name_value != attributes[name_field]
|
120
|
-
end
|
121
|
-
|
122
|
-
def populate_name
|
123
|
-
if attributes[name_field].blank? || name_field_changed?
|
124
|
-
send("#{name_field}=", new_name_value)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def reload_routes
|
129
|
-
Rails.application.routes_reloader.reload!
|
130
|
-
end
|
131
|
-
end
|
data/lib/flowmor_router/foo.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
class Foo
|
2
|
-
def hello
|
3
|
-
puts "gonna say hello"
|
4
|
-
"Hello #{world}"
|
5
|
-
end
|
6
|
-
|
7
|
-
def world
|
8
|
-
"World"
|
9
|
-
end
|
10
|
-
|
11
|
-
attr_reader :say_it
|
12
|
-
|
13
|
-
def initialize options = {}
|
14
|
-
@say_it = options[:another_way] || method(:hello)
|
15
|
-
define_singleton_method(:world, options[:another_world]) if options[:another_world]
|
16
|
-
end
|
17
|
-
|
18
|
-
def speak
|
19
|
-
instance_exec &say_it
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
begin
|
24
|
-
foobar = Foo.new
|
25
|
-
puts "lazy?"
|
26
|
-
puts foobar.speak
|
27
|
-
rescue Exception => e
|
28
|
-
puts "#{e.class.to_s}: #{e.message}"
|
29
|
-
end
|
30
|
-
|
31
|
-
begin
|
32
|
-
foobaz = Foo.new(another_way: lambda { "#{hello}, Sir!" })
|
33
|
-
puts "lazy?"
|
34
|
-
puts foobaz.speak
|
35
|
-
rescue Exception => e
|
36
|
-
puts "#{e.class.to_s}: #{e.message}"
|
37
|
-
end
|
38
|
-
|
39
|
-
begin
|
40
|
-
foobaz = Foo.new(another_world: lambda { "Earth" })
|
41
|
-
puts "lazy?"
|
42
|
-
puts foobaz.speak
|
43
|
-
rescue Exception => e
|
44
|
-
puts "#{e.class.to_s}: #{e.message}"
|
45
|
-
end
|
46
|
-
|
47
|
-
class Bar
|
48
|
-
def self.register(name = nil, options = {})
|
49
|
-
if name.nil?
|
50
|
-
name = "foobaz"
|
51
|
-
elsif name.is_a?(Hash) && options == {}
|
52
|
-
name, options = "foobar", name
|
53
|
-
end
|
54
|
-
puts [name, options].inspect
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
Bar.register :something, :foo => 1, :bar => 2
|
59
|
-
Bar.register \
|
60
|
-
foo: 2,
|
61
|
-
bar: -> { puts "yeah" },
|
62
|
-
baz: 3
|
63
|
-
Bar.register
|
@@ -1,50 +0,0 @@
|
|
1
|
-
class Foo
|
2
|
-
def hello
|
3
|
-
puts "gonna say hello"
|
4
|
-
"Hello #{world}"
|
5
|
-
end
|
6
|
-
|
7
|
-
def world
|
8
|
-
"World"
|
9
|
-
end
|
10
|
-
|
11
|
-
attr_reader :say_it
|
12
|
-
|
13
|
-
def initialize options = {}
|
14
|
-
@say_it = options[:another_way] || method(:hello)
|
15
|
-
define_singleton_method(:world, options[:another_world]) if options[:another_world]
|
16
|
-
end
|
17
|
-
|
18
|
-
def speak
|
19
|
-
hello
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class Proxy
|
24
|
-
def
|
25
|
-
end
|
26
|
-
|
27
|
-
begin
|
28
|
-
foobar = Foo.new
|
29
|
-
puts "lazy?"
|
30
|
-
puts foobar.speak
|
31
|
-
rescue Exception => e
|
32
|
-
puts "#{e.class.to_s}: #{e.message}"
|
33
|
-
end
|
34
|
-
|
35
|
-
begin
|
36
|
-
foobaz = Foo.new(another_way: lambda { "#{hello}, Sir!" })
|
37
|
-
puts "lazy?"
|
38
|
-
puts foobaz.speak
|
39
|
-
rescue Exception => e
|
40
|
-
puts "#{e.class.to_s}: #{e.message}"
|
41
|
-
end
|
42
|
-
|
43
|
-
begin
|
44
|
-
foobaz = Foo.new(another_world: lambda { "Earth" })
|
45
|
-
puts "lazy?"
|
46
|
-
puts foobaz.speak
|
47
|
-
rescue Exception => e
|
48
|
-
puts "#{e.class.to_s}: #{e.message}"
|
49
|
-
end
|
50
|
-
|