Class: ActiveRpc::ModelExtensions::AttributeDsl

Inherits:
Object
  • Object
show all
Defined in:
lib/active_rpc/model_extensions/attribute_dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ AttributeDsl

Returns a new instance of AttributeDsl.



4
5
6
# File 'lib/active_rpc/model_extensions/attribute_dsl.rb', line 4

def initialize(config)
  @config = config
end

Instance Method Details

#define_rpc_attribute(name, type, options = {}) ⇒ Object Also known as: attribute



8
9
10
11
12
# File 'lib/active_rpc/model_extensions/attribute_dsl.rb', line 8

def define_rpc_attribute(name, type, options = {})
  @config.attributes << name.to_sym
  @config.attribute_types[name.to_sym] = type
  @config.attribute_defaults[name.to_sym] = options[:default] if options.key?(:default)
end

#query_config(options = {}) ⇒ Object



16
17
18
# File 'lib/active_rpc/model_extensions/attribute_dsl.rb', line 16

def query_config(options = {})
  @config.query_config = options
end

#scope(name, description = nil) ⇒ Object



20
21
22
23
# File 'lib/active_rpc/model_extensions/attribute_dsl.rb', line 20

def scope(name, description = nil)
  @config.scopes ||= {}
  @config.scopes[name] = { description: description }
end

#where_rpc_mapping(mappings = {}) ⇒ Object



25
26
27
28
# File 'lib/active_rpc/model_extensions/attribute_dsl.rb', line 25

def where_rpc_mapping(mappings = {})
  @config.where_rpc_mappings ||= {}
  @config.where_rpc_mappings.merge!(mappings)
end