Class: Toast::ConfigDSL::Base
- Inherits:
-
Object
- Object
- Toast::ConfigDSL::Base
- Includes:
- Blockenspiel::DSL
- Defined in:
- lib/toast/config_dsl.rb
Instance Method Summary collapse
- #apidoc(arg = nil) ⇒ Object
- #collections(*arg) ⇒ Object
- #collections=(collections = []) ⇒ Object
- #deletable ⇒ Object
- #deletable? ⇒ Boolean
- #exposed_associations ⇒ Object
- #exposed_attributes ⇒ Object
- #field_comments ⇒ Object
- #in_collection(&block) ⇒ Object
-
#initialize(model) ⇒ Base
constructor
A new instance of Base.
- #paginate(collection_name, options = {}) ⇒ Object
- #paginations ⇒ Object
- #pass_params_to(*arg) ⇒ Object
- #pass_params_to=(arg) ⇒ Object
- #postable ⇒ Object
- #postable? ⇒ Boolean
-
#readables(*arg) ⇒ Object
args: Array or :all, :except => Array.
- #readables=(arg) ⇒ Object
- #singles(*arg) ⇒ Object
- #singles=(singles = []) ⇒ Object
-
#writables(*arg) ⇒ Object
args: Array or :all, :except => Array.
- #writables=(arg) ⇒ Object
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 |
#deletable ⇒ Object
58 59 60 |
# File 'lib/toast/config_dsl.rb', line 58 def deletable @deletable = true end |
#deletable? ⇒ Boolean
62 63 64 |
# File 'lib/toast/config_dsl.rb', line 62 def deletable? @deletable end |
#exposed_associations ⇒ Object
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_attributes ⇒ Object
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_comments ⇒ Object
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, ={} .reverse_merge! :page_size => 30 @paginations[collection_name.to_s] = {:page_size => [:page_size]} end |
#paginations ⇒ Object
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 |
#postable ⇒ Object
66 67 68 |
# File 'lib/toast/config_dsl.rb', line 66 def postable @postable = true end |
#postable? ⇒ 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 |