Module: SchemaTools::Modules::Attributes::ClassMethods
- Defined in:
- lib/schema_tools/modules/attributes.rb
Instance Method Summary collapse
Instance Method Details
#has_schema_attrs(schema_name, opts = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/schema_tools/modules/attributes.rb', line 33 def has_schema_attrs(schema_name, opts={}) reader = opts[:reader] || SchemaTools::Reader schema_location = opts[:path] || opts[:schema] # remember schema + name on class level self.schema( reader.read(schema_name, schema_location) ) self.schema_name(schema_name) # make getter / setter self.schema[:properties].each do |key, prop| define_method(key) { schema_attrs[key] } define_method("#{key}=") { |value| schema_attrs[key] = value } unless prop[:readonly] end #TODO parse links ?? or do it in resource module end |
#schema(schema_hash = nil) ⇒ Object
48 49 50 51 |
# File 'lib/schema_tools/modules/attributes.rb', line 48 def schema(schema_hash=nil) @schema = schema_hash if schema_hash @schema end |