Class: Formup::Source
- Inherits:
-
Object
- Object
- Formup::Source
- Defined in:
- lib/formup/source.rb
Instance Attribute Summary collapse
-
#attribute_defs ⇒ Object
Returns the value of attribute attribute_defs.
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
- #attr(base) ⇒ Object
- #attr?(attr) ⇒ Boolean
- #base(attr) ⇒ Object
- #base?(base) ⇒ Boolean
-
#initialize(key, attribute_defs = {}, excludes = nil) ⇒ Source
constructor
A new instance of Source.
Constructor Details
#initialize(key, attribute_defs = {}, excludes = nil) ⇒ Source
Returns a new instance of Source.
10 11 12 13 14 15 16 |
# File 'lib/formup/source.rb', line 10 def initialize(key, attribute_defs = {}, excludes = nil) raise "Formup::Source require key param." if key.nil? @key = key.to_s @attribute_defs = attribute_defs.map { |k, v| Formup::AttrDef.new(k, v) } if attribute_defs @attribute_defs ||= [] end |
Instance Attribute Details
#attribute_defs ⇒ Object
Returns the value of attribute attribute_defs.
8 9 10 |
# File 'lib/formup/source.rb', line 8 def attribute_defs @attribute_defs end |
#key ⇒ Object
Returns the value of attribute key.
8 9 10 |
# File 'lib/formup/source.rb', line 8 def key @key end |
Instance Method Details
#attr(base) ⇒ Object
31 32 33 34 |
# File 'lib/formup/source.rb', line 31 def attr(base) attr_def = @attribute_defs.detect { |attr_def| attr_def.base == base.to_s } attr_def ? attr_def.attr : nil end |
#attr?(attr) ⇒ Boolean
27 28 29 |
# File 'lib/formup/source.rb', line 27 def attr?(attr) @attribute_defs.any? { |attr_def| attr_def.attr == attr.to_s } end |
#base(attr) ⇒ Object
22 23 24 25 |
# File 'lib/formup/source.rb', line 22 def base(attr) attr_def = @attribute_defs.detect { |attr_def| attr_def.attr == attr.to_s } attr_def ? attr_def.base : nil end |
#base?(base) ⇒ Boolean
18 19 20 |
# File 'lib/formup/source.rb', line 18 def base?(base) @attribute_defs.any? { |attr_def| attr_def.base == base.to_s } end |