Module: GraphQL::Define::InstanceDefinable::ClassMethods
- Defined in:
- lib/graphql/define/instance_definable.rb
Instance Method Summary collapse
-
#accepts_definitions(*accepts) ⇒ Object
Attach definitions to this class.
- #define(**kwargs, &block) ⇒ Object
- #deprecated_accepts_definitions(*accepts) ⇒ Object
-
#deprecated_define(**kwargs, &block) ⇒ Object
Create a new instance and prepare a definition using its definitions.
-
#dictionary ⇒ Hash
Combined definitions for self and ancestors.
- #ensure_defined(*method_names) ⇒ Object
- #ensure_defined_method_names ⇒ Object
-
#own_dictionary ⇒ Hash
Definitions for this class only.
Instance Method Details
#accepts_definitions(*accepts) ⇒ Object
Attach definitions to this class.
Each symbol in accepts will be assigned with {key}=.
The last entry in accepts may be a hash of name-proc pairs for custom definitions.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/graphql/define/instance_definable.rb', line 169 def accepts_definitions(*accepts) deprecated_caller = caller(0, 1).first if deprecated_caller.include?("lib/graphql") deprecated_caller = caller(2, 10).find { |c| !c.include?("lib/graphql") } end if deprecated_caller GraphQL::Deprecation.warn <<-ERR #{self}.accepts_definitions will be removed in GraphQL-Ruby 2.0; use a class-based definition instead. See https://graphql-ruby.org/schema/class_based_api.html. -> called from #{deprecated_caller} ERR end deprecated_accepts_definitions(*accepts) end |
#define(**kwargs, &block) ⇒ Object
160 161 162 163 164 |
# File 'lib/graphql/define/instance_definable.rb', line 160 def define(**kwargs, &block) instance = self.new instance.define(**kwargs, &block) instance end |
#deprecated_accepts_definitions(*accepts) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/graphql/define/instance_definable.rb', line 184 def deprecated_accepts_definitions(*accepts) new_assignments = if accepts.last.is_a?(Hash) accepts.pop.dup else {} end accepts.each do |key| new_assignments[key] = AssignAttribute.new(key) end @own_dictionary = own_dictionary.merge(new_assignments) end |
#deprecated_define(**kwargs, &block) ⇒ Object
Create a new instance and prepare a definition using its definitions.
153 154 155 156 157 |
# File 'lib/graphql/define/instance_definable.rb', line 153 def deprecated_define(**kwargs, &block) instance = self.new instance.deprecated_define(**kwargs, &block) instance end |
#dictionary ⇒ Hash
Returns combined definitions for self and ancestors.
214 215 216 217 218 219 220 |
# File 'lib/graphql/define/instance_definable.rb', line 214 def dictionary if superclass.respond_to?(:dictionary) own_dictionary.merge(superclass.dictionary) else own_dictionary end end |
#ensure_defined(*method_names) ⇒ Object
198 199 200 201 202 |
# File 'lib/graphql/define/instance_definable.rb', line 198 def ensure_defined(*method_names) @ensure_defined_method_names ||= [] @ensure_defined_method_names.concat(method_names) nil end |
#ensure_defined_method_names ⇒ Object
204 205 206 207 208 209 210 211 |
# File 'lib/graphql/define/instance_definable.rb', line 204 def ensure_defined_method_names own_method_names = @ensure_defined_method_names || [] if superclass.respond_to?(:ensure_defined_method_names) superclass.ensure_defined_method_names + own_method_names else own_method_names end end |
#own_dictionary ⇒ Hash
Returns definitions for this class only.
223 224 225 |
# File 'lib/graphql/define/instance_definable.rb', line 223 def own_dictionary @own_dictionary ||= {} end |