Class: Locomotive::Steam::ContentTypeFieldRepository

Inherits:
Object
  • Object
show all
Includes:
Models::Repository
Defined in:
lib/locomotive/steam/repositories/content_type_field_repository.rb

Instance Attribute Summary collapse

Attributes included from Models::Repository

#adapter, #local_conditions, #scope

Instance Method Summary collapse

Methods included from Models::Repository

#base_url, #build, #count, #create, #delete, #find, #first, #i18n_value_of, #inc, #initialize, #initialize_copy, #k, #last, #mapper, #prepare_conditions, #query, #update

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



8
9
10
# File 'lib/locomotive/steam/repositories/content_type_field_repository.rb', line 8

def content_type
  @content_type
end

Instance Method Details

#associationsObject



45
46
47
# File 'lib/locomotive/steam/repositories/content_type_field_repository.rb', line 45

def associations
  query { where(k(:type, :in) => %i(belongs_to has_many many_to_many)) }.all
end

#belongs_toObject



37
38
39
# File 'lib/locomotive/steam/repositories/content_type_field_repository.rb', line 37

def belongs_to
  query { where(type: :belongs_to) }.all
end

#by_name(name) ⇒ Object



17
18
19
# File 'lib/locomotive/steam/repositories/content_type_field_repository.rb', line 17

def by_name(name)
  first { where(name: name) }
end

#dates_and_date_timesObject



33
34
35
# File 'lib/locomotive/steam/repositories/content_type_field_repository.rb', line 33

def dates_and_date_times
  query { where(k(:type, :in) => %i(date date_time)) }.all
end

#defaultObject



70
71
72
# File 'lib/locomotive/steam/repositories/content_type_field_repository.rb', line 70

def default
  query { where(k(:default, :neq) => nil, k(:type, :in) => [:string, :text, :color, :select, :boolean, :email, :integer, :float]) }.all
end

#filesObject



25
26
27
# File 'lib/locomotive/steam/repositories/content_type_field_repository.rb', line 25

def files
  query { where(type: :file) }.all
end

#localized_namesObject



64
65
66
67
68
# File 'lib/locomotive/steam/repositories/content_type_field_repository.rb', line 64

def localized_names
  query { where(localized: true) }.all.map do |field|
    field.type == :select ? [field.name, "#{field.name}_id"] : field.name
  end.flatten
end

#many_to_manyObject



41
42
43
# File 'lib/locomotive/steam/repositories/content_type_field_repository.rb', line 41

def many_to_many
  query { where(type: :many_to_many) }.all
end

#no_associationsObject



49
50
51
# File 'lib/locomotive/steam/repositories/content_type_field_repository.rb', line 49

def no_associations
  query { where(k(:type, :nin) => %i(belongs_to has_many many_to_many)) }.all
end

#passwordsObject



29
30
31
# File 'lib/locomotive/steam/repositories/content_type_field_repository.rb', line 29

def passwords
  query { where(type: :password) }.all
end

#requiredObject



60
61
62
# File 'lib/locomotive/steam/repositories/content_type_field_repository.rb', line 60

def required
  query { where(required: true) }.all
end

#select_options(name) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/locomotive/steam/repositories/content_type_field_repository.rb', line 74

def select_options(name)
  if field = first { where(name: name, type: :select) }
    field.select_options.all
  else
    nil
  end
end

#selectsObject



21
22
23
# File 'lib/locomotive/steam/repositories/content_type_field_repository.rb', line 21

def selects
  query { where(type: :select) }.all
end

#uniqueObject



53
54
55
56
57
58
# File 'lib/locomotive/steam/repositories/content_type_field_repository.rb', line 53

def unique
  query { where(unique: true) }.all.inject({}) do |memo, field|
    memo[field.name] = field
    memo
  end
end