Class: Knish::Model
- Inherits:
-
Object
- Object
- Knish::Model
- Extended by:
- Forwardable
- Includes:
- ActiveModel::Model
- Defined in:
- lib/knish/model.rb
Class Attribute Summary collapse
-
.config ⇒ Object
Returns the value of attribute config.
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attrs = nil) ⇒ Model
constructor
A new instance of Model.
- #load ⇒ Object
- #save ⇒ Object
- #set(attrs) ⇒ Object
- #template(key) ⇒ Object
Constructor Details
#initialize(attrs = nil) ⇒ Model
Returns a new instance of Model.
13 14 15 16 |
# File 'lib/knish/model.rb', line 13 def initialize(attrs=nil) attrs ||= {} set(attrs) end |
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
51 52 53 |
# File 'lib/knish/model.rb', line 51 def config @config end |
Instance Attribute Details
#config ⇒ Object
46 47 48 |
# File 'lib/knish/model.rb', line 46 def config @config ||= self.class.config.clone end |
Class Method Details
.model_name ⇒ Object
6 7 8 |
# File 'lib/knish/model.rb', line 6 def self.model_name ActiveModel::Name.new(self, omitted_namespace) end |
.omitted_namespace ⇒ Object
54 55 56 |
# File 'lib/knish/model.rb', line 54 def self.omitted_namespace config && config.omitted_namespace end |
Instance Method Details
#load ⇒ Object
29 30 31 32 33 |
# File 'lib/knish/model.rb', line 29 def load set(reader.get_json) set(reader.get_markdown) true end |
#save ⇒ Object
23 24 25 26 27 |
# File 'lib/knish/model.rb', line 23 def save writer.save_json(data_attributes) writer.save_markdown(markdown_attributes) true end |
#set(attrs) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/knish/model.rb', line 35 def set(attrs) attrs.each do |key, value| next if key.to_sym == config.type_key.to_sym public_send("#{key}=", value) end end |
#template(key) ⇒ Object
42 43 44 |
# File 'lib/knish/model.rb', line 42 def template(key) reader.template(key) end |