Class: FastAttributes::Builder
- Inherits:
-
Object
- Object
- FastAttributes::Builder
- Defined in:
- lib/fast_attributes/builder.rb
Instance Method Summary collapse
- #attribute(*attributes, type, options) ⇒ Object
- #compile! ⇒ Object
-
#initialize(klass, options = {}) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(klass, options = {}) ⇒ Builder
Returns a new instance of Builder.
6 7 8 9 10 11 |
# File 'lib/fast_attributes/builder.rb', line 6 def initialize(klass, = {}) @klass = klass @options = @attributes = [] @methods = Module.new end |
Instance Method Details
#attribute(*attributes, type, options) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fast_attributes/builder.rb', line 13 def attribute(*attributes, type, ) unless .is_a?(Hash) (attributes ||= []) << type type = = {} end unless FastAttributes.type_exists?(type) raise UnsupportedTypeError, %(Unsupported attribute type "#{type.inspect}") end @attributes << [attributes, type, || {}] end |
#compile! ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fast_attributes/builder.rb', line 27 def compile! compile_getter compile_setter set_defaults if @options[:initialize] compile_initialize end if @options[:attributes] compile_attributes(@options[:attributes]) end include_methods end |