meta_manager 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  class MetaTag < ::ActiveRecord::Base
2
2
  belongs_to :taggable, :polymorphic => true
3
3
 
4
- validates_presence_of :name, :taggable_type
4
+ validates_presence_of :name, :taggable_type, :content
5
5
  validates_uniqueness_of :name, :scope => [:taggable_type, :taggable_id, :is_dynamic]
6
6
 
7
7
  attr_accessible :name, :content, :is_dynamic
@@ -5,20 +5,14 @@ module MetaManager
5
5
  included do
6
6
  has_many :meta_tags, :as => :taggable, :dependent => :destroy, :autosave => true
7
7
 
8
- accepts_nested_attributes_for :meta_tags, :reject_if => :all_blank, :allow_destroy => true
8
+ accepts_nested_attributes_for :meta_tags, :reject_if => proc { |tag| tag['content'].blank? }, :allow_destroy => true
9
9
  end
10
-
11
- # Find meta tag by name or build new record
12
- def find_or_build_meta_tag(attr_name)
13
- key = normalize_meta_tag_name(attr_name)
14
- self.meta_tags.where(:name => key).first || self.meta_tags.build(:name => key)
15
- end
16
-
10
+
17
11
  # Save meta tags records into one hash
18
- def meta_tag(attr_name)
12
+ def meta_tag(attr_name, options={})
19
13
  key = normalize_meta_tag_name(attr_name)
20
14
  @meta_tag ||= {}
21
- @meta_tag[key] ||= find_or_build_meta_tag(key)
15
+ @meta_tag[key] ||= self.meta_tags.where(:name => key).first || (options[:build] ? self.meta_tags.build(:name => key) : nil)
22
16
  end
23
17
 
24
18
  def respond_to?(method_sym, include_private = false)
@@ -41,8 +35,8 @@ module MetaManager
41
35
  if key =~ meta_match_case
42
36
  attr_name = key.gsub(meta_match_case, '')
43
37
 
44
- if key =~ /=$/
45
- record = meta_tag(attr_name.chop)
38
+ if key =~ /=$/ && !args.first.blank?
39
+ record = meta_tag(attr_name.chop, :build => true)
46
40
  record.content = args.first
47
41
  else
48
42
  meta_tag(attr_name).try(:content)
@@ -1,3 +1,3 @@
1
1
  module MetaManager
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end