Module: HashControl::Model
- Included in:
- WritableModel
- Defined in:
- lib/hash_control/model.rb,
lib/hash_control/model.rb
Overview
Add extra I/O Placed in a separate block for sake of clarity
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#ai(options) ⇒ Object
AwesomePrint support.
- #as_json(_opts = {}) ⇒ Object
- #initialize(hash = {}) ⇒ Object
- #slice(*keys) ⇒ Object
- #symbolized_hash ⇒ Object
- #to_json ⇒ Object
Instance Method Details
#[](name) ⇒ Object
23 24 25 |
# File 'lib/hash_control/model.rb', line 23 def [](name) @hash[name] end |
#ai(options) ⇒ Object
AwesomePrint support
121 122 123 124 |
# File 'lib/hash_control/model.rb', line 121 def ai() require 'awesome_print' AwesomePrint::Inspector.new().awesome(symbolized_hash) end |
#as_json(_opts = {}) ⇒ Object
116 117 118 |
# File 'lib/hash_control/model.rb', line 116 def as_json(_opts = {}) symbolized_hash end |
#initialize(hash = {}) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/hash_control/model.rb', line 8 def initialize(hash = {}) @hash = ::ActiveSupport::HashWithIndifferentAccess.new(hash) initialize_model if self.class.method_defined? :initialize_model hash_validator = validate_default validate(hash_validator) if self.class.method_defined? :validate end |
#slice(*keys) ⇒ Object
19 20 21 |
# File 'lib/hash_control/model.rb', line 19 def slice(*keys) @symbolized_hash.select { |key, _| keys.include? key.to_sym } end |
#symbolized_hash ⇒ Object
15 16 17 |
# File 'lib/hash_control/model.rb', line 15 def symbolized_hash @hash.symbolize_keys end |
#to_json ⇒ Object
111 112 113 114 |
# File 'lib/hash_control/model.rb', line 111 def to_json require 'json' @hash.to_json end |