Module: MetaManager::Taggable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/meta_manager/taggable.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/meta_manager/taggable.rb', line 38
def method_missing(method, *args, &block)
key = method.to_s
if key =~ meta_match_case
attr_name = key.gsub(meta_match_case, '')
if key =~ /=$/ && !args.first.blank?
record = meta_tag(attr_name, :build => true)
record.content = args.first
else
meta_tag(attr_name).try(:content)
end
else
super
end
end
|
Instance Method Details
20
21
22
|
# File 'lib/meta_manager/taggable.rb', line 20
def cached_meta_tags
@cached_meta_tags ||= {}
end
|
Save meta tags records into one hash
12
13
14
15
16
17
18
|
# File 'lib/meta_manager/taggable.rb', line 12
def meta_tag(attr_name, options={})
key = normalize_meta_tag_name(attr_name)
cached_meta_tags[key] ||= self.meta_tags.detect {|t| t.name == key}
cached_meta_tags[key] ||= self.meta_tags.build(:name => key) if options[:build]
cached_meta_tags[key]
end
|
#respond_to?(method_sym, include_private = false) ⇒ Boolean
24
25
26
27
28
29
30
|
# File 'lib/meta_manager/taggable.rb', line 24
def respond_to?(method_sym, include_private = false)
if method_sym.to_s =~ meta_match_case
true
else
super
end
end
|