Sha256: a6ef6edc6e9860091689546d1af446fc5959b519d0f719531387cbe266be00cc
Contents?: true
Size: 1.26 KB
Versions: 2
Compression:
Stored size: 1.26 KB
Contents
require 'active_support' module Rsbe module Client class Provider < Base def self.base_path super + '/providers' end # implementation objectives: # - expose attributes via standard setter/getter methods # - create getters for all Read-Only (RO) attributes # - create setters only for Read/Write (RW) attributes # - use hash for internal representation to simplify passing # data back and forth to back end app def self.rw_attrs [:id, :name] end def self.ro_attrs [:created_at, :updated_at, :lock_version] end def self.all_attrs self.rw_attrs + self.ro_attrs end # define setter methods for RW attributes self.rw_attrs.each {|m| define_method("#{m}=") {|v| @hash[m] = v}} # define getter methods for ALL attributes self.all_attrs.each {|m| define_method("#{m}") { @hash[m]}} def initialize(vals = {}) raise ArgumentError.new("Constructor requires a Hash") unless vals.is_a?(Hash) super() @hash = {} @response = nil # initialize local hash with incoming values, restrict to RW attrs self.class.rw_attrs.each { |x| @hash[x] = (vals[x] || vals[x.to_s]) } end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rsbe-client-0.5.1 | lib/rsbe/client/provider.rb |
rsbe-client-0.5.0 | lib/rsbe/client/provider.rb |