Class: Toast::ConfigDSL::Base

Inherits:
Object
  • Object
show all
Includes:
Blockenspiel::DSL
Defined in:
lib/toast/config_dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/toast/config_dsl.rb', line 8

def initialize model
  @model = model
  @readables = []
  @writables = []
  @field_comments = {}
  @collections = []
  @singles = []
  @deletable = false
  @postable = false
  @pass_params_to = []
  @in_collection = ConfigDSL::InCollection.new model, self
  @media_type = "application/json"
  @apidoc = {}
  @paginations = {}
  @model.attr_accessible []
end

Instance Method Details

#apidoc(arg = nil) ⇒ Object



109
110
111
112
113
# File 'lib/toast/config_dsl.rb', line 109

def apidoc arg=nil
  return(@apidoc) if arg.nil?
  raise "Toast Config Error (#{model.class}): apidoc argument must be a Hash." unless arg.is_a?(Hash)
  @apidoc = arg
end

#collections(*arg) ⇒ Object



87
88
89
90
# File 'lib/toast/config_dsl.rb', line 87

def collections *arg
  return(@collections) if arg.empty?
  self.collections = arg
end

#collections=(collections = []) ⇒ Object



83
84
85
# File 'lib/toast/config_dsl.rb', line 83

def collections= collections=[]
  @collections = ConfigDSL.normalize(collections, "collections")
end

#deletableObject



58
59
60
# File 'lib/toast/config_dsl.rb', line 58

def deletable
  @deletable = true
end

#deletable?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/toast/config_dsl.rb', line 62

def deletable?
  @deletable
end

#exposed_associationsObject



30
31
32
33
# File 'lib/toast/config_dsl.rb', line 30

def exposed_associations
  assocs = @model.reflect_on_all_associations.map{|a| a.name.to_s}
  (@writables + @readables).uniq.select{|f| assocs.include?(f)}
end

#exposed_attributesObject



25
26
27
28
# File 'lib/toast/config_dsl.rb', line 25

def exposed_attributes
  assocs = @model.reflect_on_all_associations.map{|a| a.name.to_s}
  (@writables + @readables).uniq.select{|f| !assocs.include?(f)}
end

#field_commentsObject



124
125
126
# File 'lib/toast/config_dsl.rb', line 124

def field_comments
  @field_comments
end

#in_collection(&block) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/toast/config_dsl.rb', line 101

def in_collection &block
  if block_given?
    Blockenspiel.invoke( block, @in_collection)
  else
    @in_collection
  end
end

#paginate(collection_name, options = {}) ⇒ Object



115
116
117
118
119
# File 'lib/toast/config_dsl.rb', line 115

def paginate collection_name, options={}
  options.reverse_merge! :page_size => 30

  @paginations[collection_name.to_s] = {:page_size => options[:page_size]}
end

#paginationsObject



128
129
130
# File 'lib/toast/config_dsl.rb', line 128

def paginations
  @paginations
end

#pass_params_to(*arg) ⇒ Object



78
79
80
81
# File 'lib/toast/config_dsl.rb', line 78

def pass_params_to *arg
  return(@pass_params_to) if arg.empty?
  self.pass_params_to = arg
end

#pass_params_to=(arg) ⇒ Object



74
75
76
# File 'lib/toast/config_dsl.rb', line 74

def pass_params_to= arg
  @pass_params_to.push *ConfigDSL.normalize(arg,"pass_params_to")
end

#postableObject



66
67
68
# File 'lib/toast/config_dsl.rb', line 66

def postable
  @postable = true
end

#postable?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/toast/config_dsl.rb', line 70

def postable?
  @postable
end

#readables(*arg) ⇒ Object

args: Array or :all, :except => Array



41
42
43
44
# File 'lib/toast/config_dsl.rb', line 41

def readables *arg
  return(@readables) if arg.empty?
  self.readables = arg
end

#readables=(arg) ⇒ Object



35
36
37
38
# File 'lib/toast/config_dsl.rb', line 35

def readables= arg
  @field_comments.merge! ConfigDSL.get_comments(arg, 'ro')
  @readables.push *ConfigDSL.normalize(arg,"readables")
end

#singles(*arg) ⇒ Object



96
97
98
99
# File 'lib/toast/config_dsl.rb', line 96

def singles *arg
  return(@singles) if arg.empty?
  self.singles = arg
end

#singles=(singles = []) ⇒ Object



92
93
94
# File 'lib/toast/config_dsl.rb', line 92

def singles= singles=[]
  @singles = ConfigDSL.normalize(singles, "singles")
end

#writables(*arg) ⇒ Object

args: Array or :all, :except => Array



53
54
55
56
# File 'lib/toast/config_dsl.rb', line 53

def writables *arg
  return(@writables) if arg.empty?
  self.writables = arg
end

#writables=(arg) ⇒ Object



46
47
48
49
50
# File 'lib/toast/config_dsl.rb', line 46

def writables= arg
  @field_comments.merge! ConfigDSL.get_comments(arg, 'rw')
  @writables.push *ConfigDSL.normalize(arg,"writables")
  @model.attr_accessible *@writables
end