Module: JSONData::Data
- Defined in:
- lib/json_data/data.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
- #data_source ⇒ Object writeonly
Class Method Summary collapse
-
.included(base) ⇒ Object
end ClassMethods.
Instance Method Summary collapse
Instance Attribute Details
#data_source=(json) ⇒ Object
42 43 44 |
# File 'lib/json_data/data.rb', line 42 def data_source=(json) @data_source = OpenStruct.new(parser.parse(json)) end |
Class Method Details
.included(base) ⇒ Object
end ClassMethods
33 34 35 |
# File 'lib/json_data/data.rb', line 33 def self.included(base) base.send :extend, ClassMethods end |
Instance Method Details
#initialize(options = {}) ⇒ Object
37 38 39 40 |
# File 'lib/json_data/data.rb', line 37 def initialize( = {}) @parser = .fetch(:parser) { Parser.new } self.data_source = .fetch(:data_source) { JSON.generate({}) } end |
#required_attrs ⇒ Object
50 51 52 |
# File 'lib/json_data/data.rb', line 50 def required_attrs self.class.instance_variable_get(:@required_attrs) || [] end |
#valid? ⇒ Boolean
46 47 48 |
# File 'lib/json_data/data.rb', line 46 def valid? required_attrs.empty? || required_attrs.all? { |f| !send(f).nil? } end |