Class: ClassKit::AttributeHelper
- Inherits:
-
Object
- Object
- ClassKit::AttributeHelper
- Defined in:
- lib/class_kit/attribute_helper.rb
Instance Method Summary collapse
-
#get_attribute(klass:, name:) ⇒ Hash
Get attribute for a given class and name.
-
#get_attribute_type(klass:, name:) ⇒ Class
Get the type of a given attribute on a given class.
-
#get_attributes(klass) ⇒ Hash
Get attributes for a given class.
Instance Method Details
#get_attribute(klass:, name:) ⇒ Hash
Get attribute for a given class and name
29 30 31 32 |
# File 'lib/class_kit/attribute_helper.rb', line 29 def get_attribute(klass:, name:) get_attributes(klass).detect { |a| a[:name] == name } || raise(ClassKit::Exceptions::AttributeNotFoundError, "Attribute: #{name}, could not be found.") end |
#get_attribute_type(klass:, name:) ⇒ Class
Get the type of a given attribute on a given class
40 41 42 |
# File 'lib/class_kit/attribute_helper.rb', line 40 def get_attribute_type(klass:, name:) get_attribute(klass: klass, name: name)[:type] end |
#get_attributes(klass) ⇒ Hash
Get attributes for a given class
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/class_kit/attribute_helper.rb', line 8 def get_attributes(klass) attributes = [] klass.ancestors.map do |k| hash = k.instance_variable_get(:@class_kit_attributes) if hash != nil hash.values.each do |a| attributes.push(a) end end end attributes.compact end |