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
Create a new instance and prepare a definition using its definitions.
-
#dictionary ⇒ Hash
Combined definitions for self and ancestors.
- #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.
163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/graphql/define/instance_definable.rb', line 163 def 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 |
#define(**kwargs, &block) ⇒ Object
Create a new instance and prepare a definition using its definitions.
154 155 156 157 158 |
# File 'lib/graphql/define/instance_definable.rb', line 154 def define(**kwargs, &block) instance = self.new instance.define(**kwargs, &block) instance end |
#dictionary ⇒ Hash
Returns combined definitions for self and ancestors.
192 193 194 195 196 197 198 |
# File 'lib/graphql/define/instance_definable.rb', line 192 def dictionary if superclass.respond_to?(:dictionary) own_dictionary.merge(superclass.dictionary) else own_dictionary end end |
#ensure_defined(*method_names) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/graphql/define/instance_definable.rb', line 177 def ensure_defined(*method_names) ensure_defined_module = Module.new ensure_defined_module.module_eval { method_names.each do |method_name| define_method(method_name) { |*args, &block| ensure_defined super(*args, &block) } end } self.prepend(ensure_defined_module) nil end |
#own_dictionary ⇒ Hash
Returns definitions for this class only.
201 202 203 |
# File 'lib/graphql/define/instance_definable.rb', line 201 def own_dictionary @own_dictionary ||= {} end |