lucid_works 0.6.9 → 0.6.10
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/lib/lucid_works.rb +1 -0
- data/lib/lucid_works/base.rb +1 -10
- data/lib/lucid_works/collection.rb +1 -1
- data/lib/lucid_works/collection/synonym.rb +4 -1
- data/lib/lucid_works/simple_naming.rb +13 -0
- data/lib/lucid_works/version.rb +1 -1
- data/spec/lib/lucid_works/collection/synonym_spec.rb +22 -1
- metadata +2 -1
data/lib/lucid_works.rb
CHANGED
data/lib/lucid_works/base.rb
CHANGED
@@ -33,6 +33,7 @@ module LucidWorks
|
|
33
33
|
extend ActiveModel::Callbacks
|
34
34
|
include Associations
|
35
35
|
include Utils::BoolConverter
|
36
|
+
extend SimpleNaming
|
36
37
|
|
37
38
|
attr_accessor :parent # :nodoc:
|
38
39
|
attr_writer :id # :nodoc:
|
@@ -48,16 +49,6 @@ module LucidWorks
|
|
48
49
|
|
49
50
|
attr_accessor :collection_name # :nodoc:
|
50
51
|
attr_accessor_with_default :singleton, false
|
51
|
-
|
52
|
-
def model_name
|
53
|
-
super.tap do |name|
|
54
|
-
name.instance_eval do
|
55
|
-
def singular; ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)).tr('/', '_').freeze; end
|
56
|
-
def plural; singular.pluralize.freeze; end
|
57
|
-
def collection; ActiveSupport::Inflector.tableize(ActiveSupport::Inflector.demodulize(self)).freeze; end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
52
|
|
62
53
|
# The attributes for a model are ascertained in on of two ways.
|
63
54
|
# Without a schema, the attributes list is automatically generated when the the object is retrieved from the server.
|
@@ -47,7 +47,7 @@ module LucidWorks
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def synonyms
|
50
|
-
|
50
|
+
settings.synonym_list.each_with_index.map do |mapping, index|
|
51
51
|
Synonym.new(:id => index, :collection => self, :mapping => mapping, :persisted => true)
|
52
52
|
end
|
53
53
|
end
|
@@ -4,7 +4,9 @@ module LucidWorks
|
|
4
4
|
|
5
5
|
class Synonym
|
6
6
|
include ActiveModel::Validations
|
7
|
-
|
7
|
+
include ActiveModel::Conversion
|
8
|
+
extend ActiveModel::Naming
|
9
|
+
extend SimpleNaming
|
8
10
|
|
9
11
|
attr_reader :id, :collection, :persisted
|
10
12
|
attr_accessor :mapping
|
@@ -31,6 +33,7 @@ module LucidWorks
|
|
31
33
|
settings.synonym_list[id] = mapping
|
32
34
|
else
|
33
35
|
settings.synonym_list << mapping
|
36
|
+
@id = settings.synonym_list.length - 1
|
34
37
|
end
|
35
38
|
settings.save
|
36
39
|
@persisted = true
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module LucidWorks
|
2
|
+
module SimpleNaming
|
3
|
+
def model_name
|
4
|
+
super.tap do |name|
|
5
|
+
name.instance_eval do
|
6
|
+
def singular; ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)).tr('/', '_').freeze; end
|
7
|
+
def plural; singular.pluralize.freeze; end
|
8
|
+
def collection; ActiveSupport::Inflector.tableize(ActiveSupport::Inflector.demodulize(self)).freeze; end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/lucid_works/version.rb
CHANGED
@@ -12,6 +12,22 @@ describe LucidWorks::Collection::Synonym do
|
|
12
12
|
end
|
13
13
|
alias :reload_collection :load_collection
|
14
14
|
|
15
|
+
describe "naming support" do
|
16
|
+
it "demodulizes names" do
|
17
|
+
LucidWorks::Collection::Synonym.model_name.singular.should == "synonym"
|
18
|
+
LucidWorks::Collection::Synonym.model_name.plural.should == "synonyms"
|
19
|
+
LucidWorks::Collection::Synonym.model_name.collection.should == "synonyms"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "conversion support" do
|
24
|
+
it "can be converted to a key" do
|
25
|
+
synonym = LucidWorks::Collection::Synonym.new(:collection => @collection, :mapping => "car, auto")
|
26
|
+
synonym.save
|
27
|
+
synonym.to_key.should == [8]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
15
31
|
describe "validations" do
|
16
32
|
it "requires a mapping" do
|
17
33
|
synonym = LucidWorks::Collection::Synonym.new(:mapping => "")
|
@@ -31,7 +47,7 @@ describe LucidWorks::Collection::Synonym do
|
|
31
47
|
synonym.errors[:mapping].should == ["must be a comma-separated list"]
|
32
48
|
end
|
33
49
|
end
|
34
|
-
|
50
|
+
|
35
51
|
describe :save do
|
36
52
|
context "when valid" do
|
37
53
|
subject { LucidWorks::Collection::Synonym.new(:collection => @collection, :mapping => "car, auto") }
|
@@ -49,6 +65,11 @@ describe LucidWorks::Collection::Synonym do
|
|
49
65
|
subject.save
|
50
66
|
subject.should be_persisted
|
51
67
|
end
|
68
|
+
|
69
|
+
it "gets an id" do
|
70
|
+
subject.save
|
71
|
+
subject.id.should == 8
|
72
|
+
end
|
52
73
|
end
|
53
74
|
|
54
75
|
context "when invalid" do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: lucid_works
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.6.
|
5
|
+
version: 0.6.10
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sam Pierson
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- lib/lucid_works/patch_time.rb
|
133
133
|
- lib/lucid_works/schema.rb
|
134
134
|
- lib/lucid_works/server.rb
|
135
|
+
- lib/lucid_works/simple_naming.rb
|
135
136
|
- lib/lucid_works/utils.rb
|
136
137
|
- lib/lucid_works/version.rb
|
137
138
|
- lucid_works.gemspec
|