Class: Typekit::Element::Base
- Inherits:
-
Object
- Object
- Typekit::Element::Base
show all
- Extended by:
- Forwardable
- Includes:
- Client::Proxy
- Defined in:
- lib/typekit/element/base.rb
Instance Attribute Summary collapse
#client, #token
Class Method Summary
collapse
Instance Method Summary
collapse
#connect
Constructor Details
#initialize(*arguments) ⇒ Base
Returns a new instance of Base.
11
12
13
14
15
|
# File 'lib/typekit/element/base.rb', line 11
def initialize(*arguments)
@attributes = prepare_attributes(Helper.(arguments))
@attributes[:id] = nil unless @attributes.key?(:id)
connect(arguments.first)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *arguments) ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'lib/typekit/element/base.rb', line 50
def method_missing(name, *arguments)
if name.to_s =~ /^(?<name>.*)=$/
name = Regexp.last_match(:name).to_sym
attributes.send(:[]=, name, *arguments)
else
return super unless attributes.key?(name)
attributes[name]
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
8
9
10
|
# File 'lib/typekit/element/base.rb', line 8
def attributes
@attributes
end
|
Class Method Details
.feature?(name) ⇒ Boolean
23
24
25
26
27
28
|
# File 'lib/typekit/element/base.rb', line 23
def self.feature?(name)
name = Helper.constantize(name)
@features ||= {}
return @features[name] if @features.key?(name)
@features[name] = include?(Element.const_get(name))
end
|
Instance Method Details
#assign_attributes(*arguments) ⇒ Object
38
39
40
41
42
|
# File 'lib/typekit/element/base.rb', line 38
def assign_attributes(*arguments)
prepare_attributes(*arguments).each do |name, value|
attributes[name] = value
end
end
|
#attribute?(name) ⇒ Boolean
34
35
36
|
# File 'lib/typekit/element/base.rb', line 34
def attribute?(name)
attributes.key?(name)
end
|
#become(another) ⇒ Object
17
18
19
20
21
|
# File 'lib/typekit/element/base.rb', line 17
def become(another)
raise ArgumentError, 'Invalid class' unless self.class == another.class
@attributes = another.attributes
true
end
|
#feature?(name) ⇒ Boolean
30
31
32
|
# File 'lib/typekit/element/base.rb', line 30
def feature?(name)
self.class.feature?(name)
end
|