Navigation Menu

Skip to content

Commit

Permalink
mrb: add column value read support to Record
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 7, 2015
1 parent 604515f commit b8fb765
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/mrb/scripts/record.rb
Expand Up @@ -8,5 +8,31 @@ def inspect
"@id=#{@id.inspect}, @table=#{@table.inspect}>"
end
end

def [](name)
column = find_column(name)
if column.nil?
raise InvalidArgument, "unknown column: <#{absolute_column_name(name)}>"
end
column[@id]
end

def method_missing(name, *args, &block)
return super unless args.empty?

column = find_column(name)
return super if column.nil?

column[@id]
end

private
def absolute_column_name(name)
"#{@table.name}.#{name}"
end

def find_column(name)
Context.instance[absolute_column_name(name)]
end
end
end

0 comments on commit b8fb765

Please sign in to comment.