Class: Jsapi::Meta::Base::Model

Inherits:
Object
  • Object
show all
Extended by:
Attributes
Defined in:
lib/jsapi/meta/base/model.rb

Overview

The base meta model class.

Constant Summary

Constants included from Attributes

Attributes::DEFAULT_ARRAY, Attributes::DEFAULT_HASH

Instance Method Summary collapse

Methods included from Attributes

attribute, attribute_names

Constructor Details

#initialize(keywords = {}) ⇒ Model

Creates a new meta model.

Raises an ArgumentError if at least one keyword is not supported.



13
14
15
# File 'lib/jsapi/meta/base/model.rb', line 13

def initialize(keywords = {})
  merge!(keywords)
end

Instance Method Details

#inspect(*attributes) ⇒ Object

:nodoc:



17
18
19
20
21
22
23
24
25
# File 'lib/jsapi/meta/base/model.rb', line 17

def inspect(*attributes) # :nodoc:
  klass = self.class
  attribute_names = klass.attribute_names
  attribute_names = attributes & attribute_names if attributes.any?

  "#<#{klass.name} #{
    attribute_names.map { |name| "#{name}: #{send(name).inspect}" }.join(', ')
  }>"
end

#merge!(keywords = {}) ⇒ Object

Merges keywords into the model.

Raises an ArgumentError if at least one keyword is not supported.



30
31
32
33
34
35
36
37
38
39
# File 'lib/jsapi/meta/base/model.rb', line 30

def merge!(keywords = {})
  keywords.each do |key, value|
    if respond_to?(method = "#{key}=")
      public_send(method, value)
    else
      raise ArgumentError, "unsupported keyword: #{key}"
    end
  end
  self
end

#reference?Boolean

Returns false.

Returns:

  • (Boolean)


42
43
44
# File 'lib/jsapi/meta/base/model.rb', line 42

def reference?
  false
end

#resolveObject

Returns itself.



47
48
49
# File 'lib/jsapi/meta/base/model.rb', line 47

def resolve(*)
  self
end