Class: Kitsune::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/kitsune/builder.rb

Constant Summary collapse

TYPES =
[:check_box, :datetime_select, :password_field, :text_area, :text_field, :wysiwyg]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, &block) ⇒ Builder

Returns a new instance of Builder.



6
7
8
9
# File 'lib/kitsune/builder.rb', line 6

def initialize(resource, &block)
  @resource = resource
  self.instance_eval &block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



104
105
106
107
108
# File 'lib/kitsune/builder.rb', line 104

def method_missing(method, *args, &block)
  if TYPES.include?(method)
    add method, *args
  end
end

Class Method Details

.generate(resource, &block) ⇒ Object



31
32
33
# File 'lib/kitsune/builder.rb', line 31

def self.generate(resource, &block)
  Builder.new(resource, &block)
end

Instance Method Details

#category(category) ⇒ Object



11
12
13
# File 'lib/kitsune/builder.rb', line 11

def category category
  @resource.kitsune_admin[:category] = category
end

#columns(type = nil) ⇒ Object



39
40
41
# File 'lib/kitsune/builder.rb', line 39

def columns(type = nil)
  @resource.columns
end

#definitionsObject



35
36
37
# File 'lib/kitsune/builder.rb', line 35

def definitions
  yield # should be it's own builder
end

#disable(*types) ⇒ Object



43
44
45
46
47
# File 'lib/kitsune/builder.rb', line 43

def disable(*types)
	types.each do |type|
		@resource.kitsune_admin[:disabled] << type.to_sym
	end
end

#display(*fields) ⇒ Object



89
90
91
# File 'lib/kitsune/builder.rb', line 89

def display(*fields)
  set :display, fields
end

#display_and_edit(*args) ⇒ Object



84
85
86
87
# File 'lib/kitsune/builder.rb', line 84

def display_and_edit(*args)
  display *args
  edit *args
end

#edit(*fields) ⇒ Object



93
94
95
96
97
98
# File 'lib/kitsune/builder.rb', line 93

def edit(*fields)
  fields.each do |field|
    type = @resource.reflections[field.to_sym] ? :reflections : :edit
    set type, field
  end
end

#file(field) ⇒ Object



56
57
58
59
# File 'lib/kitsune/builder.rb', line 56

def file(field)
  add :file_field, field
  multipart
end

#image(field) ⇒ Object



61
62
63
64
# File 'lib/kitsune/builder.rb', line 61

def image(field)
  add :image_field, field
  multipart
end

#is_sti(field) ⇒ Object



79
80
81
82
# File 'lib/kitsune/builder.rb', line 79

def is_sti(field)
  @resource.kitsune_admin[:is_sti] = true
  @resource.kitsune_admin[:sti_column] = field
end

#multipart(value = true) ⇒ Object



66
67
68
# File 'lib/kitsune/builder.rb', line 66

def multipart(value = true)
  @resource.kitsune_admin[:multipart] = value
end

#name(name) ⇒ Object



15
16
17
# File 'lib/kitsune/builder.rb', line 15

def name name
  @resource.kitsune_admin[:name] = name
end

#no_adminObject



23
24
25
# File 'lib/kitsune/builder.rb', line 23

def no_admin
  @resource.kitsune_admin[:no_admin] = true
end

#no_edit(*fields) ⇒ Object



100
101
102
# File 'lib/kitsune/builder.rb', line 100

def no_edit(*fields)
  set :no_edit, fields
end

#no_menuObject



19
20
21
# File 'lib/kitsune/builder.rb', line 19

def no_menu
	no_admin
end

#select(field, options) ⇒ Object



70
71
72
# File 'lib/kitsune/builder.rb', line 70

def select(field, options)
  add :select, field, {:options => options}
end

#sortable(*fields) ⇒ Object



49
50
51
52
53
54
# File 'lib/kitsune/builder.rb', line 49

def sortable(*fields)
  @resource.kitsune_admin[:sortable] ||= []
  fields.each do |field|
    @resource.kitsune_admin[:sortable] << field.to_sym
  end
end

#sti(field, options = {}) ⇒ Object



74
75
76
77
# File 'lib/kitsune/builder.rb', line 74

def sti(field, options = {})
  add :sti, field, {:options => options}
  is_sti field
end

#tabs(tabs) ⇒ Object



27
28
29
# File 'lib/kitsune/builder.rb', line 27

def tabs(tabs)
  @resource.kitsune_admin[:tabs] = tabs
end