Class: TinyZap::OpenGraph::Base
- Inherits:
-
Object
- Object
- TinyZap::OpenGraph::Base
- Defined in:
- app/models/tinyzap/open_graph/base.rb
Overview
Provides a way to specify OpenGraph keys for an OpenGraphModel, which can later be iterated upon to generate OpenGraph meta tags.
Defined Under Namespace
Classes: Property
Class Method Summary collapse
-
.properties ⇒ Object
Array where properties are registered.
-
.property(*args, **kwargs) ⇒ Object
DSL for creating properties when defining a model.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ Base
constructor
Allows for the object to be initialized with args like ‘Image.new(url: “”, alt: “Logo image”)`.
-
#properties ⇒ Object
Iterates through the properties and also gets their value.
Constructor Details
#initialize(**kwargs) ⇒ Base
Allows for the object to be initialized with args like ‘Image.new(url: “”, alt: “Logo image”)`.
21 22 23 24 25 26 27 |
# File 'app/models/tinyzap/open_graph/base.rb', line 21 def initialize(**kwargs) kwargs.each do |kwarg, value| self.send("#{kwarg}=", value) rescue NoMethodError raise NoMethodError, "#{kwarg.inspect} is not a property of #{self.inspect}" end end |
Class Method Details
.properties ⇒ Object
Array where properties are registered.
37 38 39 |
# File 'app/models/tinyzap/open_graph/base.rb', line 37 def self.properties @properties ||= [] end |
Instance Method Details
#properties ⇒ Object
Iterates through the properties and also gets their value.
42 43 44 45 46 47 48 |
# File 'app/models/tinyzap/open_graph/base.rb', line 42 def properties Enumerator.new do |y| self.class.properties.each do |property| y << [ property, (self.send(property.name) || property.default) ] end end end |