noodall-core 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -0
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/noodall/node.rb +1 -5
- data/lib/noodall-core.rb +1 -1
- data/noodall-core.gemspec +5 -3
- data/spec/node_spec.rb +9 -0
- metadata +25 -10
- data/lib/noodall/multi_parameter_attributes.rb +0 -83
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -19,6 +19,8 @@ GEM
|
|
19
19
|
jnunemaker-validatable (1.8.4)
|
20
20
|
activesupport (>= 2.3.4)
|
21
21
|
json_pure (1.4.6)
|
22
|
+
mm-multi-parameter-attributes (0.1.1)
|
23
|
+
mongo_mapper
|
22
24
|
mongo (1.1.1)
|
23
25
|
bson (>= 1.1.1)
|
24
26
|
mongo_mapper (0.8.6)
|
@@ -55,6 +57,7 @@ DEPENDENCIES
|
|
55
57
|
faker (~> 0.3.1)
|
56
58
|
i18n
|
57
59
|
jeweler (~> 1.4.0)
|
60
|
+
mm-multi-parameter-attributes (~> 0.1.1)
|
58
61
|
mongo_mapper (~> 0.8.6)
|
59
62
|
rake
|
60
63
|
ramdiv-mongo_mapper_acts_as_tree (~> 0.1.1)
|
data/Rakefile
CHANGED
@@ -13,6 +13,7 @@ begin
|
|
13
13
|
gem.authors = ["Steve England"]
|
14
14
|
gem.add_dependency('mongo_mapper', '~> 0.8.6')
|
15
15
|
gem.add_dependency('ramdiv-mongo_mapper_acts_as_tree', '~> 0.1.1')
|
16
|
+
gem.add_dependency('mm-multi-parameter-attributes', '~> 0.1.1')
|
16
17
|
gem.add_dependency('canable', '0.1.1')
|
17
18
|
gem.add_dependency('ruby-stemmer')
|
18
19
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/noodall/node.rb
CHANGED
@@ -4,7 +4,7 @@ module Noodall
|
|
4
4
|
include MongoMapper::Acts::Tree
|
5
5
|
include Canable::Ables
|
6
6
|
|
7
|
-
plugin MultiParameterAttributes
|
7
|
+
plugin MongoMapper::Plugins::MultiParameterAttributes
|
8
8
|
plugin Indexer
|
9
9
|
plugin Search
|
10
10
|
plugin Tagging
|
@@ -332,10 +332,6 @@ module Noodall
|
|
332
332
|
@root_template
|
333
333
|
end
|
334
334
|
|
335
|
-
def single_collection_inherited?
|
336
|
-
false
|
337
|
-
end
|
338
|
-
|
339
335
|
# Returns a list of classes that can have this model as a child
|
340
336
|
def parent_classes
|
341
337
|
classes = []
|
data/lib/noodall-core.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'mongo_mapper'
|
2
2
|
require 'mongo_mapper_acts_as_tree'
|
3
3
|
require 'canable'
|
4
|
+
require 'mm-multi-parameter-attributes'
|
4
5
|
require 'noodall/global_update_time'
|
5
|
-
require 'noodall/multi_parameter_attributes'
|
6
6
|
require 'noodall/search'
|
7
7
|
require 'noodall/tagging'
|
8
8
|
require 'noodall/permalink'
|
data/noodall-core.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{noodall-core}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Steve England"]
|
12
|
-
s.date = %q{2010-11-
|
12
|
+
s.date = %q{2010-11-03}
|
13
13
|
s.description = %q{Core data objects for Noodall}
|
14
14
|
s.email = %q{steve@wearebeef.co.uk}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -29,7 +29,6 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/noodall/component.rb",
|
30
30
|
"lib/noodall/global_update_time.rb",
|
31
31
|
"lib/noodall/indexer.rb",
|
32
|
-
"lib/noodall/multi_parameter_attributes.rb",
|
33
32
|
"lib/noodall/node.rb",
|
34
33
|
"lib/noodall/permalink.rb",
|
35
34
|
"lib/noodall/search.rb",
|
@@ -61,17 +60,20 @@ Gem::Specification.new do |s|
|
|
61
60
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
62
61
|
s.add_runtime_dependency(%q<mongo_mapper>, ["~> 0.8.6"])
|
63
62
|
s.add_runtime_dependency(%q<ramdiv-mongo_mapper_acts_as_tree>, ["~> 0.1.1"])
|
63
|
+
s.add_runtime_dependency(%q<mm-multi-parameter-attributes>, ["~> 0.1.1"])
|
64
64
|
s.add_runtime_dependency(%q<canable>, ["= 0.1.1"])
|
65
65
|
s.add_runtime_dependency(%q<ruby-stemmer>, [">= 0"])
|
66
66
|
else
|
67
67
|
s.add_dependency(%q<mongo_mapper>, ["~> 0.8.6"])
|
68
68
|
s.add_dependency(%q<ramdiv-mongo_mapper_acts_as_tree>, ["~> 0.1.1"])
|
69
|
+
s.add_dependency(%q<mm-multi-parameter-attributes>, ["~> 0.1.1"])
|
69
70
|
s.add_dependency(%q<canable>, ["= 0.1.1"])
|
70
71
|
s.add_dependency(%q<ruby-stemmer>, [">= 0"])
|
71
72
|
end
|
72
73
|
else
|
73
74
|
s.add_dependency(%q<mongo_mapper>, ["~> 0.8.6"])
|
74
75
|
s.add_dependency(%q<ramdiv-mongo_mapper_acts_as_tree>, ["~> 0.1.1"])
|
76
|
+
s.add_dependency(%q<mm-multi-parameter-attributes>, ["~> 0.1.1"])
|
75
77
|
s.add_dependency(%q<canable>, ["= 0.1.1"])
|
76
78
|
s.add_dependency(%q<ruby-stemmer>, [">= 0"])
|
77
79
|
end
|
data/spec/node_spec.rb
CHANGED
@@ -33,6 +33,15 @@ describe Noodall::Node do
|
|
33
33
|
node = Noodall::Node.find(page.id)
|
34
34
|
|
35
35
|
node.class.should == Page
|
36
|
+
|
37
|
+
class LandingPage < Noodall::Node
|
38
|
+
root_template!
|
39
|
+
end
|
40
|
+
|
41
|
+
LandingPage.create!(@valid_attributes)
|
42
|
+
|
43
|
+
Page.last.class.should == Page
|
44
|
+
LandingPage.last.class.should == LandingPage
|
36
45
|
end
|
37
46
|
|
38
47
|
it "should be found by permalink" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noodall-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Steve England
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-03 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -53,11 +53,11 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
|
-
name:
|
56
|
+
name: mm-multi-parameter-attributes
|
57
57
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
58
58
|
none: false
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ~>
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
hash: 25
|
63
63
|
segments:
|
@@ -69,8 +69,24 @@ dependencies:
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
|
-
name:
|
72
|
+
name: canable
|
73
73
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - "="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 25
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
- 1
|
82
|
+
- 1
|
83
|
+
version: 0.1.1
|
84
|
+
requirement: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
name: ruby-stemmer
|
89
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
74
90
|
none: false
|
75
91
|
requirements:
|
76
92
|
- - ">="
|
@@ -79,7 +95,7 @@ dependencies:
|
|
79
95
|
segments:
|
80
96
|
- 0
|
81
97
|
version: "0"
|
82
|
-
requirement: *
|
98
|
+
requirement: *id005
|
83
99
|
description: Core data objects for Noodall
|
84
100
|
email: steve@wearebeef.co.uk
|
85
101
|
executables: []
|
@@ -102,7 +118,6 @@ files:
|
|
102
118
|
- lib/noodall/component.rb
|
103
119
|
- lib/noodall/global_update_time.rb
|
104
120
|
- lib/noodall/indexer.rb
|
105
|
-
- lib/noodall/multi_parameter_attributes.rb
|
106
121
|
- lib/noodall/node.rb
|
107
122
|
- lib/noodall/permalink.rb
|
108
123
|
- lib/noodall/search.rb
|
@@ -1,83 +0,0 @@
|
|
1
|
-
module Noodall
|
2
|
-
module MultiParameterAttributes
|
3
|
-
module InstanceMethods
|
4
|
-
def attributes=(attrs)
|
5
|
-
multi_parameter_attributes = []
|
6
|
-
attrs.each do |name, value|
|
7
|
-
return if attrs.blank?
|
8
|
-
if name.to_s.include?("(")
|
9
|
-
multi_parameter_attributes << [ name, value ]
|
10
|
-
else
|
11
|
-
writer_method = "#{name}="
|
12
|
-
if respond_to?(writer_method)
|
13
|
-
self.send(writer_method, value)
|
14
|
-
else
|
15
|
-
self[name.to_s] = value
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
assign_multiparameter_attributes(multi_parameter_attributes)
|
21
|
-
end
|
22
|
-
|
23
|
-
def assign_multiparameter_attributes(pairs)
|
24
|
-
execute_callstack_for_multiparameter_attributes(
|
25
|
-
extract_callstack_for_multiparameter_attributes(pairs)
|
26
|
-
)
|
27
|
-
end
|
28
|
-
|
29
|
-
def execute_callstack_for_multiparameter_attributes(callstack)
|
30
|
-
callstack.each do |name, values_with_empty_parameters|
|
31
|
-
# in order to allow a date to be set without a year, we must keep the empty values.
|
32
|
-
# Otherwise, we wouldn't be able to distinguish it from a date with an empty day.
|
33
|
-
values = values_with_empty_parameters.reject(&:blank?)
|
34
|
-
|
35
|
-
if values.any?
|
36
|
-
key = self.class.keys[name]
|
37
|
-
raise ArgumentError, "Unknown key #{name}" if key.nil?
|
38
|
-
klass = key.type
|
39
|
-
|
40
|
-
value = if Time == klass
|
41
|
-
Time.zone.local(*values.map(&:to_i))
|
42
|
-
elsif Date == klass
|
43
|
-
begin
|
44
|
-
values = values_with_empty_parameters.collect do |v| v.nil? ? 1 : v end
|
45
|
-
Date.new(*values)
|
46
|
-
rescue ArgumentError => ex # if Date.new raises an exception on an invalid date
|
47
|
-
Time.zone.local(*values).to_date # we instantiate Time object and convert it back to a date thus using Time's logic in handling invalid dates
|
48
|
-
end
|
49
|
-
else
|
50
|
-
klass.new(*values)
|
51
|
-
end
|
52
|
-
else
|
53
|
-
value = nil
|
54
|
-
end
|
55
|
-
writer_method = "#{name}="
|
56
|
-
if respond_to?(writer_method)
|
57
|
-
self.send(writer_method, value)
|
58
|
-
else
|
59
|
-
self[name.to_s] = value
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def extract_callstack_for_multiparameter_attributes(pairs)
|
65
|
-
attributes = { }
|
66
|
-
|
67
|
-
for pair in pairs
|
68
|
-
multiparameter_name, value = pair
|
69
|
-
attribute_name = multiparameter_name.split("(").first
|
70
|
-
attributes[attribute_name] = [] unless attributes.include?(attribute_name)
|
71
|
-
|
72
|
-
attributes[attribute_name] << [ find_parameter_position(multiparameter_name), value ]
|
73
|
-
end
|
74
|
-
|
75
|
-
attributes.each { |name, values| attributes[name] = values.sort_by{ |v| v.first }.collect { |v| v.last } }
|
76
|
-
end
|
77
|
-
|
78
|
-
def find_parameter_position(multiparameter_name)
|
79
|
-
multiparameter_name.scan(/\(([0-9]*).*\)/).first.first
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|