Module: Recline

Defined in:
lib/recline.rb,
lib/recline/model.rb,
lib/recline/railtie.rb,
lib/recline/version.rb,
lib/recline/appearance.rb

Defined Under Namespace

Modules: Types Classes: Appearance, AttributeReflection, Model, ModelReflection, Railtie

Constant Summary collapse

VERSION =
'0.1.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.default_appearance_typesObject

Returns the value of attribute default_appearance_types.



34
35
36
# File 'lib/recline.rb', line 34

def default_appearance_types
  @default_appearance_types
end

.fallback_appearanceObject

Returns the value of attribute fallback_appearance.



33
34
35
# File 'lib/recline.rb', line 33

def fallback_appearance
  @fallback_appearance
end

.schema_name_prefixObject

Returns the value of attribute schema_name_prefix.



32
33
34
# File 'lib/recline.rb', line 32

def schema_name_prefix
  @schema_name_prefix
end

Class Method Details

.appearance_for(field, klass, name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/recline.rb', line 6

def self.appearance_for(field, klass, name)
  if field..key? :recline_appearance
    return field.[:recline_appearance]
  else
    field_type = field.type
    while field_type.kind.wraps?
      field_type = field_type.of_type
    end

    if default_appearance_types.key? field_type
      default_appearance_types[field_type]
    else
      db_type = klass.type_for_attribute(name.to_s).type
      if default_appearance_types.key? db_type
        default_appearance_types[db_type]
      else
        fallback_appearance
      end
    end
  end
end