active_content 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_content/metable.rb +2 -2
- data/lib/active_content/models/profile.rb +7 -0
- data/lib/active_content/models/taxonomy.rb +3 -0
- data/lib/active_content/profileable.rb +0 -6
- data/lib/active_content/relatable.rb +19 -3
- data/lib/active_content/taxonomizable.rb +8 -1
- data/lib/active_content/templatable.rb +1 -14
- data/lib/active_content/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d60c817352bd84ece447640c005b19fa387d2949
|
4
|
+
data.tar.gz: cd81840e8c606e71f216a3aef698635f78f55bc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7f591a16993b72bb4c9a1f404bd08363f61c7c482db47861b7c663535bcb8aa5e64d8ac5d967f1d2b4e0bc154ace717788a1856e5079ff3459e380edf3f2a00
|
7
|
+
data.tar.gz: 23d890828c76d054afa886cba0d61bb0c505b38e076e31533957d28590413f8136cf4d1ad7a9c98f0557dbbb4fccea63ca84a199426f9b259dddb09631eb28ac
|
@@ -8,14 +8,14 @@ module ActiveContent
|
|
8
8
|
|
9
9
|
assoc_opts = { as: :metable, class_name: 'ActiveContent::Metum', autosave: true, dependent: :destroy }
|
10
10
|
assoc_proc = -> { where field: field }
|
11
|
-
value_opts =
|
11
|
+
value_opts = options.merge(to: :"#{field}_metum", prefix: field, alias: field)
|
12
12
|
|
13
13
|
has_one :"#{field}_metum", assoc_proc, assoc_opts
|
14
14
|
delegate_attribute :value, cast_type, value_opts
|
15
15
|
|
16
16
|
before_save do
|
17
17
|
current = send(field)
|
18
|
-
default = self.class.
|
18
|
+
default = self.class.try(:"_attribute_#{field}_value_default")
|
19
19
|
|
20
20
|
if current.blank? or current == default
|
21
21
|
send :"#{field}_metum=", nil
|
@@ -20,12 +20,6 @@ module ActiveContent
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
define_method :name do
|
24
|
-
if first_name or last_name
|
25
|
-
"#{first_name} #{last_name}".strip
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
23
|
define_method :gravatar do |size=48, default='mm'|
|
30
24
|
mail = try(:email)
|
31
25
|
hash = Digest::MD5::hexdigest(mail) unless mail.nil?
|
@@ -8,16 +8,17 @@ module ActiveContent
|
|
8
8
|
assoc_opts = { as: :relatable, class_name: 'ActiveContent::Relation', autosave: true, dependent: :destroy }
|
9
9
|
assoc_proc = -> { where field: field }
|
10
10
|
|
11
|
+
default = options.delete(:default)
|
11
12
|
multiple = options.delete(:multiple)
|
12
|
-
|
13
|
+
options = options.reverse_merge(class_name: "#{name}".classify, source: :item, source_type: assoc_type)
|
13
14
|
|
14
15
|
if multiple
|
15
|
-
options =
|
16
|
+
options = options.merge(through: :"#{field}_relations")
|
16
17
|
|
17
18
|
has_many options[:through], assoc_proc, assoc_opts
|
18
19
|
has_many :"#{field}", options
|
19
20
|
else
|
20
|
-
options =
|
21
|
+
options = options.merge(through: :"#{field}_relation")
|
21
22
|
|
22
23
|
has_one options[:through], assoc_proc, assoc_opts
|
23
24
|
has_one :"#{field}", options
|
@@ -30,6 +31,21 @@ module ActiveContent
|
|
30
31
|
send :"#{field}=", "#{name}".classify.constantize.find_by_id(value)
|
31
32
|
end
|
32
33
|
end
|
34
|
+
|
35
|
+
if default
|
36
|
+
relation_method = :"_relation_#{field}_default"
|
37
|
+
relation_default = default
|
38
|
+
|
39
|
+
define_singleton_method relation_method do
|
40
|
+
relation_default
|
41
|
+
end
|
42
|
+
|
43
|
+
after_initialize do |record|
|
44
|
+
if record.try(:"#{field}").blank?
|
45
|
+
record.send(:"#{field}=", self.class.try(relation_method))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
33
49
|
end
|
34
50
|
end
|
35
51
|
end
|
@@ -4,7 +4,7 @@ module ActiveContent
|
|
4
4
|
|
5
5
|
class_methods do
|
6
6
|
def has_taxonomy(name, options={})
|
7
|
-
options = options.reverse_merge(class_name: name.
|
7
|
+
options = options.reverse_merge(class_name: "#{name}".classify, source: :taxonomy)
|
8
8
|
options = options.merge(through: :"#{name}_taxonomizations")
|
9
9
|
setting = { as: :taxonomizable, class_name: 'ActiveContent::Taxonomization', autosave: true, dependent: :destroy }
|
10
10
|
|
@@ -37,6 +37,13 @@ module ActiveContent
|
|
37
37
|
ids.empty? ? query.where(blank) : query.where(blank).or(query.where.not(id))
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
def has_taxonomized(name, options={})
|
42
|
+
assoc_name = "#{name}".pluralize
|
43
|
+
assoc_type = (options[:class_name] || "#{name}".classify).constantize.base_class.name
|
44
|
+
|
45
|
+
has_many :"#{assoc_name}", through: :taxonomizations, source: :taxonomizable, source_type: "#{assoc_type}"
|
46
|
+
end
|
40
47
|
end
|
41
48
|
end
|
42
49
|
end
|
@@ -10,24 +10,11 @@ module ActiveContent
|
|
10
10
|
enumerize :template, in: templates, predicates: { prefix: true }
|
11
11
|
|
12
12
|
has_one :view_template, as: :templatable, class_name: 'ActiveContent::Template', autosave: true, dependent: :destroy
|
13
|
-
delegate_attribute :name, :string, to: :view_template, prefix: 'template', alias: :template
|
13
|
+
delegate_attribute :name, :string, to: :view_template, prefix: 'template', alias: :template, finder: true, scope: true
|
14
14
|
|
15
15
|
before_save do
|
16
16
|
self.view_template = nil if template.blank?
|
17
17
|
end
|
18
|
-
|
19
|
-
query = self.includes(:view_template)
|
20
|
-
blank = { templates: { name: nil } }
|
21
|
-
|
22
|
-
scope :with_template, -> (*names) do
|
23
|
-
named = { templates: { name: names } }
|
24
|
-
names.empty? ? query.where.not(blank) : query.where(named)
|
25
|
-
end
|
26
|
-
|
27
|
-
scope :without_template, -> (*names) do
|
28
|
-
named = { templates: { name: names } }
|
29
|
-
names.empty? ? query.where(blank) : query.where(blank).or(query.where.not(named))
|
30
|
-
end
|
31
18
|
end
|
32
19
|
end
|
33
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_content
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olibia Tsati
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-11-
|
12
|
+
date: 2017-11-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|