Class: Conflagration
- Inherits:
-
Object
- Object
- Conflagration
- Includes:
- ActiveModel::Model
- Defined in:
- lib/conflagration.rb,
lib/conflagration/version.rb
Constant Summary collapse
- Unset =
Class.new(StandardError)
- VERSION =
"0.0.2"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.attribute(name, *args) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/conflagration.rb', line 17 def self.attribute name, *args super name, *args define_method "#{name}!" do val = public_send(name) raise Unset.new "'#{name}' is not sent" unless val.present? val end end |
.path(new_path = nil) ⇒ Object
13 14 15 |
# File 'lib/conflagration.rb', line 13 def self.path new_path=nil new_path ? (@path = new_path) : @path end |
.read ⇒ Object
27 28 29 |
# File 'lib/conflagration.rb', line 27 def self.read new JSON.parse File.read path end |
Instance Method Details
#update(attrs) ⇒ Object
31 32 33 34 |
# File 'lib/conflagration.rb', line 31 def update attrs attrs.each { |k,v| send "#{k}=", v } File.write self.class.path, JSON.pretty_generate(as_json) end |