Module: FlightConfig::Accessor::ClassMethods

Defined in:
lib/flight_config/accessor.rb

Instance Method Summary collapse

Instance Method Details

#data_accessor(key) ⇒ Object



61
62
63
64
# File 'lib/flight_config/accessor.rb', line 61

def data_accessor(key)
  data_reader(key)
  data_writer(key)
end

#data_reader(key, &b) ⇒ Object



66
67
68
69
70
71
# File 'lib/flight_config/accessor.rb', line 66

def data_reader(key, &b)
  self.define_method(key) do
    raw = __data__[key]
    b ? instance_exec(raw, &b) : raw
  end
end

#data_writer(key, &b) ⇒ Object



73
74
75
76
77
# File 'lib/flight_config/accessor.rb', line 73

def data_writer(key, &b)
  self.define_method("#{key}=") do |raw|
    __data__[key] = b ? instance_exec(raw, &b) : raw
  end
end

#define_input_methods_from_path_parametersObject



79
80
81
82
83
84
85
86
# File 'lib/flight_config/accessor.rb', line 79

def define_input_methods_from_path_parameters
  self.method(:path)
      .parameters
      .select { |type, _| type == :req }
      .each_with_index do |(_, arg), idx|
    define_method(arg) { __inputs__[idx] }
  end
end