Class: Cmsimple::Snippet
- Inherits:
-
Object
show all
- Extended by:
- ActiveModel::Naming
- Defined in:
- app/models/cmsimple/snippet.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(id, snippet_hash) ⇒ Snippet
Returns a new instance of Snippet.
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'app/models/cmsimple/snippet.rb', line 6
def initialize(id, snippet_hash)
@id = id
@snippet_hash = snippet_hash.dup
@name = @snippet_hash[:name]
@options = flatten_options(@snippet_hash[:options].presence || @snippet_hash)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
29
30
31
|
# File 'app/models/cmsimple/snippet.rb', line 29
def method_missing method, *args, &block
@options[method]
end
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
4
5
6
|
# File 'app/models/cmsimple/snippet.rb', line 4
def id
@id
end
|
#name ⇒ Object
Returns the value of attribute name.
4
5
6
|
# File 'app/models/cmsimple/snippet.rb', line 4
def name
@name
end
|
#options ⇒ Object
Returns the value of attribute options.
4
5
6
|
# File 'app/models/cmsimple/snippet.rb', line 4
def options
@options
end
|
Instance Method Details
#errors ⇒ Object
56
57
58
|
# File 'app/models/cmsimple/snippet.rb', line 56
def errors
ActiveModel::Errors.new(self)
end
|
#flatten_options(options) ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'app/models/cmsimple/snippet.rb', line 19
def flatten_options(options)
return {} unless options.present?
options = options.dup
if options.key?(:snippet)
options.merge(options[:snippet])
else
options
end
end
|
#matcher ⇒ Object
33
34
35
|
# File 'app/models/cmsimple/snippet.rb', line 33
def matcher
/\[#{self.id}(\/\d)?\]/
end
|
#persisted? ⇒ Boolean
40
41
42
|
# File 'app/models/cmsimple/snippet.rb', line 40
def persisted?
false
end
|
#to_key ⇒ Object
48
49
50
|
# File 'app/models/cmsimple/snippet.rb', line 48
def to_key
nil
end
|
#to_param ⇒ Object
44
45
46
|
# File 'app/models/cmsimple/snippet.rb', line 44
def to_param
nil
end
|
#to_partial_path ⇒ Object
52
53
54
|
# File 'app/models/cmsimple/snippet.rb', line 52
def to_partial_path
"cmsimple/snippets/#{name}/display"
end
|
#valid? ⇒ Boolean
60
61
62
|
# File 'app/models/cmsimple/snippet.rb', line 60
def valid?
true
end
|