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

Parameters:

  • schema (Symbol|String)

    name

  • opts (Hash<Symbol|String>) (defaults to: {})


33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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

#schemaObject



52
53
54
# File 'lib/schema_tools/modules/attributes.rb', line 52

def schema
  @schema
end

#schema=(schema_hash) ⇒ Object

Parameters:

  • schema_hash (Hash)


49
50
51
# File 'lib/schema_tools/modules/attributes.rb', line 49

def schema= schema_hash
  @schema = schema_hash
end