Class: PushType::FieldType

Inherits:
Object show all
Defined in:
lib/push_type/field_type.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, model, opts = {}) ⇒ FieldType

Returns a new instance of FieldType.



29
30
31
32
33
# File 'lib/push_type/field_type.rb', line 29

def initialize(name, model, opts = {})
  @name     = name
  @model    = model
  @opts     = [defaults, self.class.options, opts].compact.inject(&:deep_merge)
end

Class Attribute Details

.def_blockObject (readonly)

Returns the value of attribute def_block.



12
13
14
# File 'lib/push_type/field_type.rb', line 12

def def_block
  @def_block
end

.init_blockObject (readonly)

Returns the value of attribute init_block.



12
13
14
# File 'lib/push_type/field_type.rb', line 12

def init_block
  @init_block
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



27
28
29
# File 'lib/push_type/field_type.rb', line 27

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/push_type/field_type.rb', line 27

def name
  @name
end

Class Method Details

.on_class(&block) ⇒ Object



18
19
20
# File 'lib/push_type/field_type.rb', line 18

def on_class(&block)
  @def_block = block
end

.on_instance(&block) ⇒ Object



22
23
24
# File 'lib/push_type/field_type.rb', line 22

def on_instance(&block)
  @init_block = block
end

.options(opts = {}) ⇒ Object



14
15
16
# File 'lib/push_type/field_type.rb', line 14

def options(opts = {})
  @options ||= opts
end

Instance Method Details

#css_classObject



59
60
61
# File 'lib/push_type/field_type.rb', line 59

def css_class
  @opts[:css_class]
end

#field_optionsObject



79
80
81
# File 'lib/push_type/field_type.rb', line 79

def field_options
  @opts[:field_options]
end

#form_helperObject



71
72
73
# File 'lib/push_type/field_type.rb', line 71

def form_helper
  @opts[:form_helper]
end

#html_optionsObject



75
76
77
# File 'lib/push_type/field_type.rb', line 75

def html_options
  @opts[:html_options]
end

#json_primitiveObject



55
56
57
# File 'lib/push_type/field_type.rb', line 55

def json_primitive
  @opts[:json_primitive]
end

#json_valueObject



47
48
49
# File 'lib/push_type/field_type.rb', line 47

def json_value
  model.field_store.try(:[], name.to_s)
end

#kindObject



35
36
37
# File 'lib/push_type/field_type.rb', line 35

def kind
  self.class.name.demodulize.underscore.gsub(/_(field|type)$/, '').to_sym
end

#labelObject



67
68
69
# File 'lib/push_type/field_type.rb', line 67

def label
  @opts[:label]
end

#multiple?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/push_type/field_type.rb', line 83

def multiple?
  @opts[:multiple]
end

#primitiveObject



39
40
41
42
43
44
45
# File 'lib/push_type/field_type.rb', line 39

def primitive
  begin
    "push_type/primitives/#{ json_primitive }_type".camelize.constantize
  rescue NameError
    "#{ json_primitive }_type".camelize.constantize
  end
end

#templateObject



63
64
65
# File 'lib/push_type/field_type.rb', line 63

def template
  @opts[:template]
end

#valueObject



51
52
53
# File 'lib/push_type/field_type.rb', line 51

def value
  json_value
end