Class: Stargate::Metadata
- Inherits:
-
Object
- Object
- Stargate::Metadata
show all
- Includes:
- Serialization
- Defined in:
- lib/stargate/metadata.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#bencode, #to_json, #to_msgpack
Constructor Details
#initialize(klass, name, &block) ⇒ Metadata
Returns a new instance of Metadata.
19
20
21
22
23
24
25
26
|
# File 'lib/stargate/metadata.rb', line 19
def initialize(klass, name, &block)
@klass, @name = klass, name
@class_methods = []
@attributes = []
@readers = []
instance_eval(&block) if block_given?
end
|
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
15
16
17
|
# File 'lib/stargate/metadata.rb', line 15
def klass
@klass
end
|
#name ⇒ Object
Returns the value of attribute name.
17
18
19
|
# File 'lib/stargate/metadata.rb', line 17
def name
@name
end
|
Class Method Details
.from_hash(hash) ⇒ Object
5
6
7
8
9
10
11
12
13
|
# File 'lib/stargate/metadata.rb', line 5
def self.from_hash(hash)
hash.symbolize_keys!
new(hash[:klass], hash[:name]).tap do |metadata|
metadata.class_methods(*hash.fetch(:class_methods, []))
metadata.attributes(*hash.fetch(:attributes, []))
metadata.readers(*hash.fetch(:readers, []))
end
end
|
Instance Method Details
#active_record? ⇒ Boolean
28
29
30
|
# File 'lib/stargate/metadata.rb', line 28
def active_record?
@active_record
end
|
#attributes(*names) ⇒ Object
36
37
38
|
# File 'lib/stargate/metadata.rb', line 36
def attributes(*names)
load_or_add(:attributes, *names)
end
|
#class_methods(*names) ⇒ Object
32
33
34
|
# File 'lib/stargate/metadata.rb', line 32
def class_methods(*names)
load_or_add(:class_methods, *names)
end
|
#inspect ⇒ Object
53
54
55
|
# File 'lib/stargate/metadata.rb', line 53
def inspect
"#<#{self.class.name} name=#{name.inspect} class_methods=#{class_methods.inspect} attributes=#{attributes.inspect} readers=#{readers.inspect}"
end
|
#readers(*names) ⇒ Object
40
41
42
|
# File 'lib/stargate/metadata.rb', line 40
def readers(*names)
load_or_add(:readers, *names)
end
|
#serialize ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/stargate/metadata.rb', line 44
def serialize
{
name: name,
class_methods: class_methods,
attributes: attributes,
readers: readers
}
end
|