Class: Aliyun::Odps::Struct::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/aliyun/odps/struct.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.



5
6
7
8
9
10
11
12
# File 'lib/aliyun/odps/struct.rb', line 5

def initialize(attributes = {})
  attributes.each do |key, value|
    m = "#{Utils.underscore(key)}=".to_sym
    send(m, value) if self.respond_to?(m)
  end

  validate_required
end

Class Attribute Details

.required_attrsObject (readonly)

Returns the value of attribute required_attrs.



35
36
37
# File 'lib/aliyun/odps/struct.rb', line 35

def required_attrs
  @required_attrs
end

Class Method Details

.property(attr, type, options = {}) ⇒ Object

Examples:


property :name, String, required: true, init_with: proc {|value| value.upcase }, within: %w{value1 value2}

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :required (Boolean)

    required or optional

  • :init_with (block)

    block used to init attr



48
49
50
51
52
53
54
# File 'lib/aliyun/odps/struct.rb', line 48

def property(attr, type, options = {})
  @required_attrs ||= []
  @required_attrs << attr.to_s if options[:required]

  define_reader_method(attr)
  define_writer_method(attr, type, options)
end

Instance Method Details

#clientObject



30
31
32
# File 'lib/aliyun/odps/struct.rb', line 30

def client
  project.client
end

#update_attrs(attrs) ⇒ Object



23
24
25
26
27
28
# File 'lib/aliyun/odps/struct.rb', line 23

def update_attrs(attrs)
  attrs.each do |k, v|
    send("#{Utils.underscore(k)}=", v)
  end
  self
end