active_content 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1514763e6708c791c73b89c1b7b845d4f635bcd
4
- data.tar.gz: 2689c2be2f014ca5e74a08aaa3c7442d44ca572a
3
+ metadata.gz: 95694815bebd13b3b30d8b1d065d6b04dce20877
4
+ data.tar.gz: 6cc2f2055d69201c469dafd1c8cac6e989b57930
5
5
  SHA512:
6
- metadata.gz: 07177b8ccad87382c536b6d1a9457b989c9f7d2ce3021ae7552e18f734491f690332e0a13aa74cc83ad2e88a7a5b5b22f286b7e5aa85b7d2ef18984678ccaf18
7
- data.tar.gz: 197defa087e36083bf4df0142297221906dfdaf95ccea07e9f08607a0ab4b3d7b842f780857e4c69633855fbffc533cf49b966e88763995d7f4572616878fb2f
6
+ metadata.gz: eb88e592627b511a9a56641cb1ff48e7a88fbb22ba3446fc7fe588c92850ee3d8379163b92aada99a2afb5e905d05934befb04b209679ec550f33537cfba09f8
7
+ data.tar.gz: 57618528440456b8cfaf98a388115dc1d425b247185fb318670f4c97a7bbc7f91152bec1fb72abf169c0e123f7c74fcdde4cd709ef020e616ffc70e2c9ddf516
@@ -1,4 +1,5 @@
1
1
  class ActiveContent::Attachment < ApplicationRecord
2
+ # Set table name
2
3
  self.table_name = 'attachments'
3
4
 
4
5
  # Belongs associations
@@ -1,3 +1,7 @@
1
1
  class ActiveContent::Content < ApplicationRecord
2
+ # Set table name
2
3
  self.table_name = 'contents'
4
+
5
+ # Define validations
6
+ validates :title, presence: true
3
7
  end
@@ -1,4 +1,5 @@
1
1
  class ActiveContent::Metum < ApplicationRecord
2
+ # Set table name
2
3
  self.table_name = 'meta'
3
4
 
4
5
  # Belongs associations
@@ -1,4 +1,5 @@
1
1
  class ActiveContent::Profile < ApplicationRecord
2
+ # Set table name
2
3
  self.table_name = 'profiles'
3
4
 
4
5
  # Belongs associations
@@ -1,4 +1,5 @@
1
1
  class ActiveContent::Relation < ApplicationRecord
2
+ # Set table name
2
3
  self.table_name = 'relations'
3
4
 
4
5
  # Belongs associations
@@ -1,4 +1,5 @@
1
1
  class ActiveContent::Taxonomization < ApplicationRecord
2
+ # Set table name
2
3
  self.table_name = 'taxonomizations'
3
4
 
4
5
  # Belongs associations
@@ -1,3 +1,7 @@
1
1
  class ActiveContent::Taxonomy < ApplicationRecord
2
+ # Set table name
2
3
  self.table_name = 'taxonomies'
4
+
5
+ # Define validations
6
+ validates :name, presence: true
3
7
  end
@@ -1,4 +1,5 @@
1
1
  class ActiveContent::Template < ApplicationRecord
2
+ # Set table name
2
3
  self.table_name = 'templates'
3
4
 
4
5
  # Belongs associations
@@ -1,6 +1,10 @@
1
1
  class ActiveContent::Upload < ApplicationRecord
2
+ # Set table name
2
3
  self.table_name = 'uploads'
3
4
 
4
5
  # Mount carrierwave uploader
5
6
  has_uploader
7
+
8
+ # Define validations
9
+ validates :file, presence: true
6
10
  end
@@ -3,18 +3,33 @@ module ActiveContent
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  class_methods do
6
- def has_profile
6
+ def has_profile(options={})
7
7
  include ActiveDelegate
8
8
 
9
9
  has_one :profile, as: :profileable, class_name: 'ActiveContent::Profile', autosave: true, dependent: :destroy
10
- delegate_attributes to: :profile, allow_nil: true
10
+ delegate_attributes options.except(:to).merge(to: :profile, allow_nil: true)
11
+
12
+ before_save do
13
+ prof_foreign = self.class.profiles_attribute_names.map(&:to_s)
14
+ prof_current = prof_foreign.map { |n| send(n) }
15
+ prof_default = self.class.column_defaults.select { |n, _d| prof_foreign.include?(n) }.values
16
+ prof_changes = (prof_current - prof_default).reject(&:blank?)
17
+
18
+ if prof_changes.empty?
19
+ self.profile = nil
20
+ end
21
+ end
11
22
 
12
23
  define_method :name do
13
- "#{first_name} #{last_name}".strip
24
+ if first_name or last_name
25
+ "#{first_name} #{last_name}".strip
26
+ end
14
27
  end
15
28
 
16
29
  define_method :gravatar do |size=48, default='mm'|
17
- hash = Digest::MD5::hexdigest(try(:email))
30
+ mail = try(:email)
31
+ hash = Digest::MD5::hexdigest(mail) unless mail.nil?
32
+
18
33
  "https://www.gravatar.com/avatar/#{hash}?rating=PG&size=#{size}&default=#{default}"
19
34
  end
20
35
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveContent
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  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.0
4
+ version: 0.1.1
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 00:00:00.000000000 Z
12
+ date: 2017-11-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord