Class: LcpRuby::Dsl::TypeBuilder
- Inherits:
-
Object
- Object
- LcpRuby::Dsl::TypeBuilder
- Defined in:
- lib/lcp_ruby/dsl/type_builder.rb
Instance Method Summary collapse
- #base_type(value) ⇒ Object
- #column_option(key, value) ⇒ Object
- #default_index_visible(value) ⇒ Object
- #html_attr(key, value) ⇒ Object
-
#initialize(name) ⇒ TypeBuilder
constructor
A new instance of TypeBuilder.
- #input_type(value) ⇒ Object
- #null_false_validation(*entries) ⇒ Object
- #renderer(value) ⇒ Object
- #reserved_clash(*names) ⇒ Object
- #to_hash ⇒ Object
- #transform(key) ⇒ Object
- #validate(type, **options) ⇒ Object
Constructor Details
#initialize(name) ⇒ TypeBuilder
Returns a new instance of TypeBuilder.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/lcp_ruby/dsl/type_builder.rb', line 4 def initialize(name) @name = name.to_s @base_type_value = nil @transforms = [] @validations = [] @input_type_value = nil @renderer_value = nil @column_options = {} @html_input_attrs = {} @default_index_visible_value = nil @null_false_validations = nil @reserved_clashes = [] end |
Instance Method Details
#base_type(value) ⇒ Object
18 19 20 |
# File 'lib/lcp_ruby/dsl/type_builder.rb', line 18 def base_type(value) @base_type_value = value.to_s end |
#column_option(key, value) ⇒ Object
40 41 42 |
# File 'lib/lcp_ruby/dsl/type_builder.rb', line 40 def column_option(key, value) @column_options[key.to_sym] = value end |
#default_index_visible(value) ⇒ Object
48 49 50 |
# File 'lib/lcp_ruby/dsl/type_builder.rb', line 48 def default_index_visible(value) @default_index_visible_value = value end |
#html_attr(key, value) ⇒ Object
44 45 46 |
# File 'lib/lcp_ruby/dsl/type_builder.rb', line 44 def html_attr(key, value) @html_input_attrs[key.to_sym] = value end |
#input_type(value) ⇒ Object
32 33 34 |
# File 'lib/lcp_ruby/dsl/type_builder.rb', line 32 def input_type(value) @input_type_value = value.to_s end |
#null_false_validation(*entries) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/lcp_ruby/dsl/type_builder.rb', line 52 def null_false_validation(*entries) @null_false_validations ||= [] entries.each do |entry| raise ArgumentError, "null_false_validation entry must be a Hash" unless entry.is_a?(Hash) @null_false_validations << stringify_keys(entry) end end |
#renderer(value) ⇒ Object
36 37 38 |
# File 'lib/lcp_ruby/dsl/type_builder.rb', line 36 def renderer(value) @renderer_value = value.to_s end |
#reserved_clash(*names) ⇒ Object
60 61 62 |
# File 'lib/lcp_ruby/dsl/type_builder.rb', line 60 def reserved_clash(*names) @reserved_clashes.concat(names.map(&:to_s)) end |
#to_hash ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/lcp_ruby/dsl/type_builder.rb', line 64 def to_hash hash = { "name" => @name, "base_type" => @base_type_value } hash["transforms"] = @transforms unless @transforms.empty? hash["validations"] = @validations unless @validations.empty? hash["input_type"] = @input_type_value if @input_type_value hash["renderer"] = @renderer_value if @renderer_value hash["column_options"] = stringify_keys(@column_options) unless @column_options.empty? hash["html_input_attrs"] = stringify_keys(@html_input_attrs) unless @html_input_attrs.empty? hash["default_index_visible"] = @default_index_visible_value unless @default_index_visible_value.nil? hash["null_false_validation"] = @null_false_validations unless @null_false_validations.nil? hash["reserved_clashes"] = @reserved_clashes unless @reserved_clashes.empty? hash end |
#transform(key) ⇒ Object
22 23 24 |
# File 'lib/lcp_ruby/dsl/type_builder.rb', line 22 def transform(key) @transforms << key.to_s end |
#validate(type, **options) ⇒ Object
26 27 28 29 30 |
# File 'lib/lcp_ruby/dsl/type_builder.rb', line 26 def validate(type, **) validation = { "type" => type.to_s } validation["options"] = stringify_keys() unless .empty? @validations << validation end |