Sha256: 304d4c9cabf888e0df7a86f3ab05771a36467202f3abaa8957a819948aaddf27

Contents?: true

Size: 623 Bytes

Versions: 4

Compression:

Stored size: 623 Bytes

Contents

require 'date'

module ProntoForms
  class Resource
    attr_reader :data, :client, :parent

    def self.property(name, key: nil, &block)
      define_method(name) {
        if block_given?
          instance_eval(&block)
        elsif !key.nil?
          data.fetch(key)
        else
          nil
        end
      }
    end

    def initialize(data, client, parent = nil)
      @data = data
      @client = client
      @parent = parent
    end

    def self.resource_name
      name = self.to_s.split("::").last
      "#{name.downcase}s"
    end

    def resource_name
      self.class.resource_name
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
prontoforms-0.3.1 lib/prontoforms/resource.rb
prontoforms-0.3.0 lib/prontoforms/resource.rb
prontoforms-0.2.0 lib/prontoforms/resource.rb
prontoforms-0.1.0 lib/prontoforms/resource.rb