Sha256: 5f0b555e8b10cb840bdf2aa250e57db8b666473f0e7622b1a3845ddb5e0c9e2d
Contents?: true
Size: 1.87 KB
Versions: 30
Compression:
Stored size: 1.87 KB
Contents
require 'push_type/primitives/base' require 'push_type/primitives/string_type' require 'push_type/primitives/number_type' require 'push_type/primitives/array_type' require 'push_type/primitives/object_type' require 'push_type/primitives/boolean_type' module PushType class FieldType class << self attr_reader :def_block, :init_block def options(opts = {}) @options ||= opts end def on_class(&block) @def_block = block end def on_instance(&block) @init_block = block end end attr_reader :name, :model def initialize(name, model, opts = {}) @name = name @model = model @opts = [defaults, self.class.options, opts].compact.inject(&:deep_merge) end def kind self.class.name.demodulize.underscore.gsub(/_(field|type)$/, '').to_sym end def primitive begin "push_type/primitives/#{ json_primitive }_type".camelize.constantize rescue NameError "#{ json_primitive }_type".camelize.constantize end end def json_value model.field_store.try(:[], name.to_s) end def value json_value end def json_primitive @opts[:json_primitive] end def css_class @opts[:css_class] end def template @opts[:template] end def label @opts[:label] end def form_helper @opts[:form_helper] end def html_options @opts[:html_options] end def field_options @opts[:field_options] end def multiple? @opts[:multiple] end private def defaults { json_primitive: :string, template: 'default', label: name.to_s.humanize, form_helper: :text_field, html_options: {}, field_options: {}, multiple: false } end end end
Version data entries
30 entries across 30 versions & 1 rubygems