infopark_rails_connector_meta 1.6.3 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/rails_connector/abstract_obj.rb +20 -0
- data/{lib/meta → app/models/rails_connector}/attribute.rb +0 -0
- data/{lib/meta → app/models/rails_connector}/blob_mapping.rb +0 -0
- data/{lib/meta → app/models/rails_connector}/channel.rb +0 -0
- data/{lib/meta → app/models/rails_connector}/content.rb +0 -0
- data/{lib → app/models/rails_connector}/meta/eager_loader.rb +0 -0
- data/{lib/meta → app/models/rails_connector}/obj_class.rb +4 -4
- data/{lib/meta → app/models/rails_connector}/object_with_meta_data.rb +0 -0
- data/infopark_rails_connector_meta.gemspec +2 -2
- data/lib/engine.rb +4 -0
- data/lib/infopark_rails_connector_meta.rb +2 -0
- data/lib/meta.rb +143 -9
- data/lib/meta/version.rb +1 -1
- data/spec/infopark_rails_connector_meta_spec.rb +3 -4
- metadata +21 -21
- data/lib/meta/base.rb +0 -146
@@ -0,0 +1,20 @@
|
|
1
|
+
module RailsConnector
|
2
|
+
# This trick is a workaround to provide compatiblity with both
|
3
|
+
# ObjExtensions-enabled versions (older versions) and ObjExtensions-deprecated
|
4
|
+
# versions (newest versions) of RailsConnector
|
5
|
+
#
|
6
|
+
# It first tries to use user-defined Obj class in the newest RailsConnector,
|
7
|
+
# which is also an alias for RailsConnector::Obj in the older RailsConnector.
|
8
|
+
# If that fails it falls back to ::RailsConnector::BasicObj (new)
|
9
|
+
# or ::RailsConnector::Obj (old).
|
10
|
+
# The last case shouldn't really ever happen.
|
11
|
+
AbstractObj = begin
|
12
|
+
::Obj
|
13
|
+
rescue NameError
|
14
|
+
begin
|
15
|
+
::RailsConnector::BasicObj
|
16
|
+
rescue NameError
|
17
|
+
::RailsConnector::Obj
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -25,16 +25,16 @@ module RailsConnector
|
|
25
25
|
@blob_data['titles'] || {}
|
26
26
|
end
|
27
27
|
|
28
|
-
# Returns the custom Ruby class or RailsConnector::
|
28
|
+
# Returns the custom Ruby class or RailsConnector::AbstractObj.
|
29
29
|
def ruby_class
|
30
30
|
# this must be the same algorithm that the rest of the RailsConnector uses!
|
31
|
-
RailsConnector::
|
31
|
+
RailsConnector::AbstractObj.compute_type(self.name)
|
32
32
|
end
|
33
33
|
|
34
34
|
# Returns true, if a custom Ruby class exists.
|
35
35
|
def has_custom_ruby_class?
|
36
|
-
self.ruby_class.present? && self.ruby_class != RailsConnector::
|
37
|
-
self.ruby_class.ancestors.include?(RailsConnector::
|
36
|
+
self.ruby_class.present? && self.ruby_class != RailsConnector::AbstractObj &&
|
37
|
+
self.ruby_class.ancestors.include?(RailsConnector::AbstractObj)
|
38
38
|
end
|
39
39
|
|
40
40
|
# Returns the custom attributes in the form of a Hash.
|
File without changes
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
s.add_development_dependency "rspec"
|
23
23
|
|
24
|
-
s.add_runtime_dependency "activerecord", '>= 3.0.10', '<= 3.
|
25
|
-
s.add_runtime_dependency "activesupport", '>= 3.0.10', '<= 3.
|
24
|
+
s.add_runtime_dependency "activerecord", '>= 3.0.10', '<= 3.3'
|
25
|
+
s.add_runtime_dependency "activesupport", '>= 3.0.10', '<= 3.3'
|
26
26
|
s.add_runtime_dependency "infopark_rails_connector"
|
27
27
|
end
|
data/lib/engine.rb
ADDED
data/lib/meta.rb
CHANGED
@@ -1,10 +1,144 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
module RailsConnector
|
3
|
+
|
4
|
+
module Meta
|
5
|
+
|
6
|
+
# This method is an equivalent of Rails.logger.silence, which has been deprecated
|
7
|
+
def self.hello_im_rails_and_im_retarted_so_please_be_patient(&block)
|
8
|
+
begin
|
9
|
+
old_logger_level, Rails.logger.level = Rails.logger.level, Logger::ERROR
|
10
|
+
yield self
|
11
|
+
ensure
|
12
|
+
Rails.logger.level = old_logger_level
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.included(base) #:nodoc:
|
17
|
+
# Class enhancements
|
18
|
+
base.extend(ClassMethods)
|
19
|
+
end
|
20
|
+
|
21
|
+
# The RailsConnector::ObjClass object for this file format.
|
22
|
+
# This will always return a proper object, even if no custom
|
23
|
+
# Ruby class exists.
|
24
|
+
def obj_class_definition
|
25
|
+
@obj_class_definition ||= RailsConnector::Meta::EagerLoader.instance.obj_class(self.obj_class)
|
26
|
+
end
|
27
|
+
alias_method :obj_class_def, :obj_class_definition
|
28
|
+
|
29
|
+
# Returns true, if there is a custom Ruby class defined for the object
|
30
|
+
# or false, if it is represented by RailsConnector::Obj
|
31
|
+
def has_custom_ruby_class?
|
32
|
+
self.class.is_custom_ruby_class?
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns the custom attributes in the form of a Hash.
|
36
|
+
def custom_attributes
|
37
|
+
self.obj_class_definition.custom_attributes
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns true, if the file format has an attribute of the given name.
|
41
|
+
def custom_attribute?(attr)
|
42
|
+
self.obj_class_definition.custom_attribute?(attr)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns an Array of String of all mandatory attributes, no mather if it's
|
46
|
+
# custom or built-in. Built-in attributes are underscored (valid_from,
|
47
|
+
# not validFrom).
|
48
|
+
# Possible +options+ are:
|
49
|
+
# <tt>:only_custom_attributes</tt>:: Return only custom attributes, omit
|
50
|
+
# built-in attributes like content_type or valid_from.
|
51
|
+
def mandatory_attribute_names(options = {})
|
52
|
+
self.obj_class_definition.mandatory_attribute_names(options)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns true, if the file format has an mandatory attribute of the given name.
|
56
|
+
def mandatory_attribute?(attr)
|
57
|
+
self.obj_class_definition.mandatory_attribute?(attr)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Returns the version of this object. This number is increased every time
|
61
|
+
# this object is released.
|
62
|
+
def version
|
63
|
+
load_meta_details
|
64
|
+
@object_with_meta_data.version.presence.to_i || 0
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns the time of the reminder, if it is set.
|
68
|
+
def reminder_from
|
69
|
+
load_meta_details
|
70
|
+
@object_with_meta_data.reminder_from.presence &&
|
71
|
+
::RailsConnector::DateAttribute.parse(@object_with_meta_data.reminder_from)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Returns the reminder comment, if a reminder is set.
|
75
|
+
def reminder_comment
|
76
|
+
load_meta_details
|
77
|
+
@object_with_meta_data.reminder_comment
|
78
|
+
end
|
79
|
+
|
80
|
+
# Return the name of the workflow, that is assigned to this object.
|
81
|
+
def workflow_name
|
82
|
+
load_meta_details
|
83
|
+
@object_with_meta_data.workflow_name
|
84
|
+
end
|
85
|
+
|
86
|
+
# Return the current editor as a String. If there is no edited content,
|
87
|
+
# which is always the case in live mode, an empty String is returned.
|
88
|
+
# The 'contents' table is queried for this information.
|
89
|
+
def editor
|
90
|
+
return @editor if @editor
|
91
|
+
|
92
|
+
load_meta_details
|
93
|
+
|
94
|
+
content_id = if self.edited?
|
95
|
+
@object_with_meta_data.edited_content_id
|
96
|
+
else
|
97
|
+
@object_with_meta_data.released_cont_id
|
98
|
+
end
|
99
|
+
|
100
|
+
if content_id
|
101
|
+
content = RailsConnector::Content.find(content_id)
|
102
|
+
@editor = content.editor
|
103
|
+
else
|
104
|
+
@editor = ''
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
# Load the objects details from the `objects' tables.
|
111
|
+
def load_meta_details #:nodoc:
|
112
|
+
return if @object_with_meta_data
|
113
|
+
|
114
|
+
@object_with_meta_data = RailsConnector::ObjectWithMetaData.find(self.id)
|
115
|
+
|
116
|
+
# reset depending instance variables
|
117
|
+
@editor = nil
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
# the methods in this module will become class methods
|
122
|
+
module ClassMethods
|
123
|
+
|
124
|
+
# The RailsConnector::ObjClass object for this file format.
|
125
|
+
# This will only return a proper object if a custom Ruby class exists
|
126
|
+
# and will throw a RuntimeError otherwise.
|
127
|
+
def obj_class_definition
|
128
|
+
raise "Obtaining the obj_class_definition of an Obj without custom Ruby class " \
|
129
|
+
"is logically impossible." unless is_custom_ruby_class?
|
130
|
+
# @obj_class_definition ||= RailsConnector::ObjClass.find_by_name(self.name)
|
131
|
+
@obj_class_definition ||= RailsConnector::Meta::EagerLoader.instance.obj_class(self.name)
|
132
|
+
end
|
133
|
+
alias_method :obj_class_def, :obj_class_definition
|
134
|
+
|
135
|
+
# RailsConnector::AbstractObj returns false, everything else true.
|
136
|
+
def is_custom_ruby_class?
|
137
|
+
self != RailsConnector::AbstractObj
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
data/lib/meta/version.rb
CHANGED
@@ -12,7 +12,7 @@ describe Obj do
|
|
12
12
|
nil.should be_false # we're off a good start
|
13
13
|
|
14
14
|
# everything should be false here
|
15
|
-
obj = RailsConnector::
|
15
|
+
obj = RailsConnector::AbstractObj.where(:obj_class => 'ObjClassWithoutRubyClass').first
|
16
16
|
obj.obj_class_def.has_custom_ruby_class?.should be_false
|
17
17
|
obj.has_custom_ruby_class?.should be_false
|
18
18
|
obj.class.is_custom_ruby_class?.should be_false
|
@@ -25,7 +25,7 @@ describe Obj do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should respond to obj_class_def/obj_class_definition correctly" do
|
28
|
-
obj = RailsConnector::
|
28
|
+
obj = RailsConnector::AbstractObj.where(:obj_class => 'ObjClassWithoutRubyClass').first
|
29
29
|
obj.obj_class_def.name.should == 'ObjClassWithoutRubyClass'
|
30
30
|
obj.obj_class_definition.name.should == 'ObjClassWithoutRubyClass'
|
31
31
|
|
@@ -47,8 +47,7 @@ describe RailsConnector::ObjClass do
|
|
47
47
|
|
48
48
|
it "should serve the proper Ruby class" do
|
49
49
|
obj_class_def = RailsConnector::ObjClass.where(:obj_class_name => 'ObjClassWithoutRubyClass').first
|
50
|
-
obj_class_def.ruby_class.should == RailsConnector::Obj
|
51
|
-
obj_class_def.ruby_class.should == ::Obj
|
50
|
+
obj_class_def.ruby_class.should == RailsConnector::AbstractObj.obj_class_def.ruby_class.should == ::Obj
|
52
51
|
obj_class_def.has_custom_ruby_class?.should be_false
|
53
52
|
|
54
53
|
obj2_class_def = RailsConnector::ObjClass.where(:obj_class_name => 'StandardPage').first
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infopark_rails_connector_meta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 7
|
9
|
+
- 0
|
10
|
+
version: 1.7.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tomasz Przedmojski
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-02-
|
18
|
+
date: 2013-02-21 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -48,12 +48,11 @@ dependencies:
|
|
48
48
|
version: 3.0.10
|
49
49
|
- - <=
|
50
50
|
- !ruby/object:Gem::Version
|
51
|
-
hash:
|
51
|
+
hash: 1
|
52
52
|
segments:
|
53
53
|
- 3
|
54
|
-
-
|
55
|
-
|
56
|
-
version: 3.2.12
|
54
|
+
- 3
|
55
|
+
version: "3.3"
|
57
56
|
type: :runtime
|
58
57
|
version_requirements: *id002
|
59
58
|
- !ruby/object:Gem::Dependency
|
@@ -72,12 +71,11 @@ dependencies:
|
|
72
71
|
version: 3.0.10
|
73
72
|
- - <=
|
74
73
|
- !ruby/object:Gem::Version
|
75
|
-
hash:
|
74
|
+
hash: 1
|
76
75
|
segments:
|
77
76
|
- 3
|
78
|
-
-
|
79
|
-
|
80
|
-
version: 3.2.12
|
77
|
+
- 3
|
78
|
+
version: "3.3"
|
81
79
|
type: :runtime
|
82
80
|
version_requirements: *id003
|
83
81
|
- !ruby/object:Gem::Dependency
|
@@ -108,16 +106,18 @@ files:
|
|
108
106
|
- Gemfile
|
109
107
|
- LICENSE
|
110
108
|
- Rakefile
|
109
|
+
- app/models/rails_connector/abstract_obj.rb
|
110
|
+
- app/models/rails_connector/attribute.rb
|
111
|
+
- app/models/rails_connector/blob_mapping.rb
|
112
|
+
- app/models/rails_connector/channel.rb
|
113
|
+
- app/models/rails_connector/content.rb
|
114
|
+
- app/models/rails_connector/meta/eager_loader.rb
|
115
|
+
- app/models/rails_connector/obj_class.rb
|
116
|
+
- app/models/rails_connector/object_with_meta_data.rb
|
111
117
|
- infopark_rails_connector_meta.gemspec
|
118
|
+
- lib/engine.rb
|
119
|
+
- lib/infopark_rails_connector_meta.rb
|
112
120
|
- lib/meta.rb
|
113
|
-
- lib/meta/attribute.rb
|
114
|
-
- lib/meta/base.rb
|
115
|
-
- lib/meta/blob_mapping.rb
|
116
|
-
- lib/meta/channel.rb
|
117
|
-
- lib/meta/content.rb
|
118
|
-
- lib/meta/eager_loader.rb
|
119
|
-
- lib/meta/obj_class.rb
|
120
|
-
- lib/meta/object_with_meta_data.rb
|
121
121
|
- lib/meta/version.rb
|
122
122
|
- spec/infopark_rails_connector_meta_spec.rb
|
123
123
|
- spec/spec_helper.rb
|
data/lib/meta/base.rb
DELETED
@@ -1,146 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require 'meta/eager_loader'
|
3
|
-
|
4
|
-
module RailsConnector
|
5
|
-
|
6
|
-
module Meta
|
7
|
-
|
8
|
-
# This method is an equivalent of Rails.logger.silence, which has been deprecated
|
9
|
-
def self.hello_im_rails_and_im_retarted_so_please_be_patient(&block)
|
10
|
-
begin
|
11
|
-
old_logger_level, Rails.logger.level = Rails.logger.level, Logger::ERROR
|
12
|
-
yield self
|
13
|
-
ensure
|
14
|
-
Rails.logger.level = old_logger_level
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.included(base) #:nodoc:
|
19
|
-
# Class enhancements
|
20
|
-
base.extend(ClassMethods)
|
21
|
-
end
|
22
|
-
|
23
|
-
# The RailsConnector::ObjClass object for this file format.
|
24
|
-
# This will always return a proper object, even if no custom
|
25
|
-
# Ruby class exists.
|
26
|
-
def obj_class_definition
|
27
|
-
@obj_class_definition ||= RailsConnector::Meta::EagerLoader.instance.obj_class(self.obj_class)
|
28
|
-
end
|
29
|
-
alias_method :obj_class_def, :obj_class_definition
|
30
|
-
|
31
|
-
# Returns true, if there is a custom Ruby class defined for the object
|
32
|
-
# or false, if it is represented by RailsConnector::Obj
|
33
|
-
def has_custom_ruby_class?
|
34
|
-
self.class.is_custom_ruby_class?
|
35
|
-
end
|
36
|
-
|
37
|
-
# Returns the custom attributes in the form of a Hash.
|
38
|
-
def custom_attributes
|
39
|
-
self.obj_class_definition.custom_attributes
|
40
|
-
end
|
41
|
-
|
42
|
-
# Returns true, if the file format has an attribute of the given name.
|
43
|
-
def custom_attribute?(attr)
|
44
|
-
self.obj_class_definition.custom_attribute?(attr)
|
45
|
-
end
|
46
|
-
|
47
|
-
# Returns an Array of String of all mandatory attributes, no mather if it's
|
48
|
-
# custom or built-in. Built-in attributes are underscored (valid_from,
|
49
|
-
# not validFrom).
|
50
|
-
# Possible +options+ are:
|
51
|
-
# <tt>:only_custom_attributes</tt>:: Return only custom attributes, omit
|
52
|
-
# built-in attributes like content_type or valid_from.
|
53
|
-
def mandatory_attribute_names(options = {})
|
54
|
-
self.obj_class_definition.mandatory_attribute_names(options)
|
55
|
-
end
|
56
|
-
|
57
|
-
# Returns true, if the file format has an mandatory attribute of the given name.
|
58
|
-
def mandatory_attribute?(attr)
|
59
|
-
self.obj_class_definition.mandatory_attribute?(attr)
|
60
|
-
end
|
61
|
-
|
62
|
-
# Returns the version of this object. This number is increased every time
|
63
|
-
# this object is released.
|
64
|
-
def version
|
65
|
-
load_meta_details
|
66
|
-
@object_with_meta_data.version.presence.to_i || 0
|
67
|
-
end
|
68
|
-
|
69
|
-
# Returns the time of the reminder, if it is set.
|
70
|
-
def reminder_from
|
71
|
-
load_meta_details
|
72
|
-
@object_with_meta_data.reminder_from.presence &&
|
73
|
-
::RailsConnector::DateAttribute.parse(@object_with_meta_data.reminder_from)
|
74
|
-
end
|
75
|
-
|
76
|
-
# Returns the reminder comment, if a reminder is set.
|
77
|
-
def reminder_comment
|
78
|
-
load_meta_details
|
79
|
-
@object_with_meta_data.reminder_comment
|
80
|
-
end
|
81
|
-
|
82
|
-
# Return the name of the workflow, that is assigned to this object.
|
83
|
-
def workflow_name
|
84
|
-
load_meta_details
|
85
|
-
@object_with_meta_data.workflow_name
|
86
|
-
end
|
87
|
-
|
88
|
-
# Return the current editor as a String. If there is no edited content,
|
89
|
-
# which is always the case in live mode, an empty String is returned.
|
90
|
-
# The 'contents' table is queried for this information.
|
91
|
-
def editor
|
92
|
-
return @editor if @editor
|
93
|
-
|
94
|
-
load_meta_details
|
95
|
-
|
96
|
-
content_id = if self.edited?
|
97
|
-
@object_with_meta_data.edited_content_id
|
98
|
-
else
|
99
|
-
@object_with_meta_data.released_cont_id
|
100
|
-
end
|
101
|
-
|
102
|
-
if content_id
|
103
|
-
content = RailsConnector::Content.find(content_id)
|
104
|
-
@editor = content.editor
|
105
|
-
else
|
106
|
-
@editor = ''
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
private
|
111
|
-
|
112
|
-
# Load the objects details from the `objects' tables.
|
113
|
-
def load_meta_details #:nodoc:
|
114
|
-
return if @object_with_meta_data
|
115
|
-
|
116
|
-
@object_with_meta_data = RailsConnector::ObjectWithMetaData.find(self.id)
|
117
|
-
|
118
|
-
# reset depending instance variables
|
119
|
-
@editor = nil
|
120
|
-
end
|
121
|
-
|
122
|
-
|
123
|
-
# the methods in this module will become class methods
|
124
|
-
module ClassMethods
|
125
|
-
|
126
|
-
# The RailsConnector::ObjClass object for this file format.
|
127
|
-
# This will only return a proper object if a custom Ruby class exists
|
128
|
-
# and will throw a RuntimeError otherwise.
|
129
|
-
def obj_class_definition
|
130
|
-
raise "Obtaining the obj_class_definition of an Obj without custom Ruby class " \
|
131
|
-
"is logically impossible." unless is_custom_ruby_class?
|
132
|
-
# @obj_class_definition ||= RailsConnector::ObjClass.find_by_name(self.name)
|
133
|
-
@obj_class_definition ||= RailsConnector::Meta::EagerLoader.instance.obj_class(self.name)
|
134
|
-
end
|
135
|
-
alias_method :obj_class_def, :obj_class_definition
|
136
|
-
|
137
|
-
# RailsConnector::Obj returns false, everything else true.
|
138
|
-
def is_custom_ruby_class?
|
139
|
-
self != RailsConnector::Obj
|
140
|
-
end
|
141
|
-
|
142
|
-
end
|
143
|
-
|
144
|
-
end
|
145
|
-
|
146
|
-
end
|